How to use the @slack/interactive-messages.createMessageAdapter function in @slack/interactive-messages

To help you get started, we’ve selected a few @slack/interactive-messages examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github slackapi / template-announcement-approvals / index.js View on Github external
// --- Slack Events ---
const slackEvents = slackEventsAPI.createSlackEventAdapter(process.env.SLACK_VERIFICATION_TOKEN);

bot.getAuthorizedUser();

slackEvents.on('message', (event) => {
  // Filter out messages from this bot itself or updates to messages
  if (event.subtype === 'bot_message' || event.subtype === 'message_changed' || event.subtype === 'message_deleted') {
    return;
  }
  bot.handleDirectMessage(event.user, event.channel, event.text);
});

// --- Slack Interactive Messages ---
const slackMessages =
  slackInteractiveMessages.createMessageAdapter(process.env.SLACK_VERIFICATION_TOKEN);

// Action handling

slackMessages.action('startAnnouncement', payload =>
  bot.startAnnouncement(payload.user.id, payload.channel.id, payload.trigger_id)
);

slackMessages.action(/previewAnnouncement:(\w+)/, (payload) => {
  const reg = /previewAnnouncement:(\w+)/;
  const channelId = (payload.callback_id).match(reg)[1];
  bot.previewAnnouncement(payload.user.id, channelId, payload.submission)
  .catch(console.error);
});

slackMessages.action(/confirmAnnouncement:(\w+)/, payload =>
  bot.confirmAnnouncement(payload.user.id,
github slackapi / node-slack-sdk / examples / express-all-interactions / server.js View on Github external
const express = require('express');
const { createMessageAdapter } = require('@slack/interactive-messages');
const { WebClient } = require('@slack/web-api');
const { users, neighborhoods } = require('./models');
const axios = require('axios');
const bodyParser = require('body-parser');

// Read the signing secret and access token from the environment variables
const slackSigningSecret = process.env.SLACK_SIGNING_SECRET;
const slackAccessToken = process.env.SLACK_ACCESS_TOKEN;
if (!slackSigningSecret || !slackAccessToken) {
  throw new Error('A Slack signing secret and access token are required to run this app.');
}

// Create the adapter using the app's signing secret
const slackInteractions = createMessageAdapter(slackSigningSecret);

// Create a Slack Web API client using the access token
const web = new WebClient(slackAccessToken);

// Initialize an Express application
const app = express();

// Attach the adapter to the Express application as a middleware
app.use('/slack/actions', slackInteractions.expressMiddleware());

// Attach the slash command handler
app.post('/slack/commands', bodyParser.urlencoded({ extended: false }), slackSlashCommand);

// Start the express application server
const port = process.env.PORT || 0;
http.createServer(app).listen(port, () => {
github slackapi / node-slack-interactive-messages / examples / express-all-interactions / server.js View on Github external
const express = require('express');
const bodyParser = require('body-parser');
const { createMessageAdapter } = require('@slack/interactive-messages');
const { WebClient } = require('@slack/client');
const { users, neighborhoods } = require('./models');
const axios = require('axios');

// Read the verification token from the environment variables
const slackVerificationToken = process.env.SLACK_VERIFICATION_TOKEN;
const slackAccessToken = process.env.SLACK_ACCESS_TOKEN;
if (!slackVerificationToken || !slackAccessToken) {
  throw new Error('Slack verification token and access token are required to run this app.');
}

// Create the adapter using the app's verification token
const slackInteractions = createMessageAdapter(process.env.SLACK_VERIFICATION_TOKEN);

// Create a Slack Web API client
const web = new WebClient(slackAccessToken);

// Initialize an Express application
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));

// Attach the adapter to the Express application as a middleware
app.use('/slack/actions', slackInteractions.expressMiddleware());

// Attach the slash command handler
app.post('/slack/commands', slackSlashCommand);

// Start the express application server
const port = process.env.PORT || 0;
github cloudcomponents / cdk-components / packages / cdk-codepipeline-slack-lambda / src / approval-handler.ts View on Github external
import * as express from 'express';
import { createServer, proxy } from 'aws-serverless-express';
import { APIGatewayEvent, Context } from 'aws-lambda';
import { createMessageAdapter } from '@slack/interactive-messages';

import { Server } from 'http';
import { handleButtonClicked, handleDialog } from './interactions';

const SLACK_SIGNING_SECRET = process.env.SLACK_SIGNING_SECRET as string;

const app = express();

const slackInteractions = createMessageAdapter(SLACK_SIGNING_SECRET);

app.use('/slack/actions', slackInteractions.expressMiddleware());

slackInteractions.action('slack_approval', handleButtonClicked);

slackInteractions.action(/(\w+)_dialog/, handleDialog);

const server = createServer(app);

export const handler = (event: APIGatewayEvent, context: Context): Server =>
    proxy(server, event, context);

@slack/interactive-messages

Official library for using the Slack Platform's Interactive Buttons, Menus, Dialogs, Actions, and Block Actions

MIT
Latest version published 4 years ago

Package Health Score

61 / 100
Full package analysis

Popular @slack/interactive-messages functions