Last active
February 14, 2020 03:29
-
-
Save battlecow/67238cc9ae922792c93d475a28fe66e2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{ | |
"name": "slack-issue", | |
"version": "0.0.0", | |
"description": "Slack Issue Repro", | |
"main": "server.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Brian Kelley", | |
"license": "ISC", | |
"dependencies": { | |
"@slack/interactive-messages": "^1.4.1", | |
"@slack/web-api": "^5.7.0", | |
"express": "^4.17.1" | |
} | |
} |
This file contains hidden or 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 express = require('express'); | |
const app = express(); | |
/** | |
* Define these constants | |
*/ | |
const BOT_TOKEN = ''; | |
const channelName = ''; | |
const SLACK_BOT_USER = ''; | |
const slackSigningSecret = ''; | |
const { WebClient } = require('@slack/web-api'); | |
const client = new WebClient(BOT_TOKEN); | |
const { createMessageAdapter } = require('@slack/interactive-messages'); | |
const slackInteractions = createMessageAdapter(slackSigningSecret); | |
client.chat.postMessage({ | |
as_user: true, | |
username: SLACK_BOT_USER, | |
channel: `@${channelName}`, | |
blocks: [{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "Test messaging" | |
} | |
}, { | |
"type": "actions", | |
"elements": [{ | |
"type": "button", | |
"text": { | |
"type": "plain_text", | |
"emoji": true, | |
"text": "Delete" | |
}, | |
"style": "primary", | |
"value": "delete", | |
"action_id": "delete" | |
}] | |
}], | |
text: 'Test message' | |
}); | |
app.use('/slack/actions', slackInteractions.requestListener()); | |
slackInteractions.action({ type: 'button', actionId: 'delete' }, async (payload, respond) => { | |
console.log('Button payload received'); | |
try { | |
return await respond({ | |
blocks: [{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": `Successfully performed the action` | |
} | |
}], | |
text: 'Action success', | |
replace_original: false | |
}); | |
} catch (err) { | |
return await respond({ | |
blocks: [{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": `Failed to perform the action` | |
} | |
}], | |
text: 'Action error', | |
replace_original: false | |
}); | |
} | |
}); | |
const port = process.env.PORT || 3000; | |
app.listen(port); | |
console.log(`SDK reproducer listening on port ${port}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment