Skip to content

Instantly share code, notes, and snippets.

@selfcontained
Created January 19, 2017 23:20
Show Gist options
  • Save selfcontained/c0c69002438eb12f5375da3723e37b0a to your computer and use it in GitHub Desktop.
Save selfcontained/c0c69002438eb12f5375da3723e37b0a to your computer and use it in GitHub Desktop.
Example of using Slack threaded messages with Slapp
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