Skip to content

Instantly share code, notes, and snippets.

@joawan
Last active September 14, 2021 17:51
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 joawan/a4f47bc828272fcac72b92c885fc6bed to your computer and use it in GitHub Desktop.
Save joawan/a4f47bc828272fcac72b92c885fc6bed to your computer and use it in GitHub Desktop.
Handler with callback to Slack
const { WebClient } = require('@slack/web-api');
const wc = new WebClient(process.env.SLACK_TOKEN);
const handler = async (event) => {
console.log('Received request', event);
const { body } = event;
if (body.challenge) {
return {
statusCode: 200,
headers: { 'Content-Type': 'text/plain' },
body: body.challenge,
};
}
// Ignore messages from bot in IM
const { channel_type: channelType, bot_id: botId } = body.event;
if (channelType === 'im' && botId) {
return { statusCode: 200 };
}
if (body.event) {
const { channel } = body.event;
const text = 'Hej Världen';
return wc.chat.postMessage({ channel, text });
}
return { statusCode: 200 };
};
module.exports = { handler };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment