Created
June 16, 2020 00:00
-
-
Save julianeon/d450bee2e63c84dd392db8f6d75d84c1 to your computer and use it in GitHub Desktop.
chat.postMessage method working script using JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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