Skip to content

Instantly share code, notes, and snippets.

@battlecow
Last active February 14, 2020 03:29
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 battlecow/67238cc9ae922792c93d475a28fe66e2 to your computer and use it in GitHub Desktop.
Save battlecow/67238cc9ae922792c93d475a28fe66e2 to your computer and use it in GitHub Desktop.
{
"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"
}
}
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