Skip to content

Instantly share code, notes, and snippets.

@manse
Created February 6, 2018 04:45
Show Gist options
  • Save manse/5c98ac8f20061a4c1b9447a6e772082d to your computer and use it in GitHub Desktop.
Save manse/5c98ac8f20061a4c1b9447a6e772082d to your computer and use it in GitHub Desktop.
post to slack channel
const fetch = require('node-fetch');
function post_message(channel, text) {
const obj = {
token: 'xoxb-aaaaaaaaaaa',
channel,
as_user: true,
text
};
fetch('https://slack.com/api/chat.postMessage', {
method: 'POST',
body: Object.keys(obj).map((key) => key + '=' + encodeURIComponent(obj[key])).join('&'),
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment