Skip to content

Instantly share code, notes, and snippets.

@tamsanh
Last active August 13, 2017 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamsanh/95eb661f8373eea16209b08ad09d38d9 to your computer and use it in GitHub Desktop.
Save tamsanh/95eb661f8373eea16209b08ad09d38d9 to your computer and use it in GitHub Desktop.
Sending an Interactive Message on Slack with NodeJS and request with a Developer Preview Token
const request = require('request');
const SLACK_TOKEN = "INSERT-TOKEN";
const TARGET_CHANNEL = "INSERT-CHANNEL"; // Ex @user, general
const data = {
"token": SLACK_TOKEN,
"channel": TARGET_CHANNEL,
"attachments": JSON.stringify([
{
     "text": "Did you get the message?\nメセージを受けたの?",
"fallback": "Unable to select",
"callback_id": "activity",
"color": "#3AA3E3",
"attachment_type": "default",
"actions": [
{
"name": "activity",
"text": "Yes",
"style": "primary",
"type": "button",
"value": "yes"
},
{
"name": "activity",
"text": "No",
"style": "danger",
"type": "button",
"value": "no"
},
{
"name": "activity",
"text": "Maybe",
"type": "button",
"value": "maybe"
}
]
}
])
};
const options = {
uri: 'https://slack.com//api/chat.postMessage',
method: 'POST',
form: data
};
request.post(options, function(err, resp, body) {
console.log(body);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment