@byu-oit/post-to-slack

0.0.1 • Public • Published

post-to-slack

A simple npm module for posting to Slack Incoming Webhooks (https://byu-oit.slack.com/apps/A0F7XDUAZ-incoming-webhooks)

Usage

Posting simple text

const slack = require('post-to-slack')
const url = '<your slack webhook>';

slack("Testing", url, function(err) {
     if(err) {
         console.log("Send failed: ", err)
     } else {
         console.log("Success")
     }
})

Posting attachments

const slack = require('post-to-slack')
const url = '<your slack webhook>';
const formatter = require('format-json')

var json = {
   "My":{
      "JSON":"object"
   }
}

var formattedJson = formatter.plain(json)

slack({
    text: 'A failed event has been removed from the queue',
    attachments: [{
        fallback: JSON.stringify(json),
        text: formattedJson
    }]
}, url, function(err) {
    if(err) {
        console.log("Send failed: ", err)
    } else {
        console.log("Success")
    }
})

See slack documentation for more information on sending attachments at https://api.slack.com/incoming-webhooks

Readme

Keywords

Package Sidebar

Install

npm i @byu-oit/post-to-slack

Weekly Downloads

1

Version

0.0.1

License

Apache-2.0

Last publish

Collaborators

  • gholl0
  • mjweather
  • yoshutch
  • lehinpm
  • oscea
  • stuft2
  • mhailstone
  • arasmus8
  • garygsc
  • martingarn
  • snelg
  • byu-oit-bot