0.1.5 • Published 8 years ago

slack-fieldify v0.1.5

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Slack Fieldify

http://brett.neese.rocks

A simple Node module that flattens a JavaScript object into a set of "fields" compatible with Slack's API; making it easier to make Slack notifications from aribtary JSON data.

Automagically turning this:

{ type: 'Ready',
  status: 'False',
  lastProbeTime: null,
  lastTransitionTime: '2016-04-25T16:49:53Z',
  reason: 'ContainersNotReady',
  message: 'containers with unready status: [sti-build]' }

Into this:

Screenshot

See the Slack docs for more info on fields. They're pretty neat.

Features:

  • Long and short "fields"
  • Custom prefixes for multidimensional arrays
  • Humanizes and properly cases value

Usage

slackFieldify(object, short, prefix)

  • @param {Object} inputObj
  • @param {boolean} False short? - Whether you want the fields to be long, for verbose data or short, for short data
  • @param {string} [] prefix? - Prepends things to the output. Mostly used inside the function.

Returns: {Object} fields - a Slack-ready set of "fields"

Example

slackFieldify = require('slack-fieldify')

/// In your Slack webhook....

attachments {     
    fields: slackFieldify(JSON.parse(jsonDataFromAPI), true);
}

N.b

Also works for arrays, or arrays of objects. If there's multiple objects in an array, it'll prepend the output with their index.

If there's only one object in an array, it won't.

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago