Last active
August 13, 2017 02:47
-
-
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
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'); | |
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