Created
January 19, 2017 23:20
-
-
Save selfcontained/c0c69002438eb12f5375da3723e37b0a to your computer and use it in GitHub Desktop.
Example of using Slack threaded messages with Slapp
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 Slapp = require('slapp') | |
const BeepBoopContext = require('slapp-context-beepboop') | |
const BeepBoopConvo = require('slapp-convo-beepboop') | |
const smb = require('slack-message-builder') | |
let slapp = Slapp({ | |
verify_token: process.env.SLACK_VERIFY_TOKEN, | |
context: BeepBoopContext(), | |
convo_store: BeepBoopConvo() | |
}) | |
slapp | |
.message(/^thread me$/, 'direct_mention', msg => { | |
msg.thread().say('A thread, just for you') | |
}) | |
.message(/^unthread me$/, 'direct_mention', msg => { | |
msg.unthread().say('An unthreaded message, just for you') | |
}) | |
.message(/^buttons$/, 'direct_mention', msg => { | |
let json = smb('How bout some buttons?') | |
.attachment('What color do you prefer?') | |
.callbackId('color') | |
.action('green', 'Green').style('primary').end() | |
.action('red', 'Red').style('danger').end() | |
.end() | |
.json() | |
msg.say(json) | |
}) | |
.action('color', 'green', msg => { | |
let orig = smb(msg.body.original_message) | |
let attachment = orig.attachments.get(1) || orig.attachment() | |
attachment.text(':green_apple: You chose green') | |
msg.respond(orig.json()) | |
}) | |
.action('color', 'red', msg => { | |
let orig = smb(msg.body.original_message) | |
let attachment = orig.attachments.get(1) || orig.attachment() | |
attachment.text(':red_circle: You chose red') | |
msg.respond(orig.json()) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment