Skip to content

Instantly share code, notes, and snippets.

@julianeon
Created June 16, 2020 00:00
Show Gist options
  • Save julianeon/d450bee2e63c84dd392db8f6d75d84c1 to your computer and use it in GitHub Desktop.
Save julianeon/d450bee2e63c84dd392db8f6d75d84c1 to your computer and use it in GitHub Desktop.
chat.postMessage method working script using JavaScript
const request = require('request');
let token="xoxo-xoxo";
let channelid="C00LR00M";
var url = "https://slack.com/api/chat.postMessage";
var auth_token = token; //Your Bot's auth token
var headers = {
"Authorization": "Bearer " + auth_token,
"Content-Type" : "application/json"
}
var body = {
channel: channelid, // Slack user or channel, where you want to send the message
text: "It's a nice day to chat!"
}
request.post({
"url": url,
"headers": headers,
"body": JSON.stringify(body)
}, (err, response, body) => {
if (err) {
reject(err);
}
console.log("response: ", JSON.stringify(response));
console.log("body: ",body);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment