How to use @slack/bolt - 10 common examples

To help you get started, we’ve selected a few @slack/bolt 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 / bolt / integration-tests / types / action.ts View on Github external
// import App, { ActionConstraints } from '../../src/App';
import { App, MessageAction } from '@slack/bolt';

const app = new App({ token: 'TOKEN', signingSecret: 'Signing Secret' });

// calling action method with incorrect an type constraint value should not work
// $ExpectError
app.action({ type: 'Something wrong' }, ({ action }) => {
  return action;
});

/* Not working
// Should error because message_action doesn't have type action_id
// $ Expect Error
app.action({ type: 'message_action', action_id: 'dafasf' }, ({ action }) => {
    return action;
});
*/

// Action in listner should be - MessageAction
github seratch / slack-api-workshop-in-fukuoka-2019 / level-2 / 02_lunch_recommendation / first-bolt-app / app.js View on Github external
const { App } = require('@slack/bolt');

// 環境変数の SLACK_BOT_TOKEN, SLACK_SIGNING_SECRET が設定されていることが前提
const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET
});

app.use(args => {
  console.log(JSON.stringify(args));
  args.next();
});

const restaurants = [
  { name: '割烹よし田', url: 'https://tabelog.com/fukuoka/A4001/A400103/40000692/' },
  { name: '真', url: 'https://tabelog.com/fukuoka/A4001/A400103/40003911/' },
  { name: '新三浦 天神店', url: 'https://tabelog.com/fukuoka/A4001/A400103/40000066/' },
  { name: '利花苑 大名本店', url: 'https://tabelog.com/fukuoka/A4001/A400104/40000443/' },
  { name: '106 サウスインディアン 福岡天神店', url: 'https://tabelog.com/fukuoka/A4001/A400103/40041110/' },
];
github seratch / slack-app-examples / reacjilator-bolt-typescript / app.ts View on Github external
// Enable debug logging if true
const debug: boolean = true;
// lang code mapping data
import { langcode } from './langcode';

// ----------------
// Slack Bolt App
import { App, ExpressReceiver } from '@slack/bolt';

const expressReceiver = new ExpressReceiver({
  signingSecret: process.env.SLACK_SIGNING_SECRET
  // Endpoints will be attached later by calling the declared methods in Bolt's App
});
export const expressApp = expressReceiver.app;

const app: App = new App({
  token: process.env.SLACK_BOT_TOKEN,
  receiver: expressReceiver
});

app.event('reaction_added', async ({ event }) => {
  try {
    if (debug) {
      console.log(event);
    }
    if (event.item['type'] !== 'message') {
      // Skip any events apart from reactions put on messages
      return;
    }
    const reactionName = event.reaction;
    let country: string = null;
    // Check the reaction name if it is a country flag
github seratch / slack-api-workshop-in-fukuoka-2019 / level-2 / 02_lunch_recommendation / block-kit-in-modals / app.js View on Github external
const { App } = require('@slack/bolt');

// 環境変数の SLACK_BOT_TOKEN, SLACK_SIGNING_SECRET が設定されていることが前提
const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET
});

app.use(args => {
  console.log(JSON.stringify(args));
  args.next();
});

const restaurants = [
  { name: '割烹よし田', url: 'https://tabelog.com/fukuoka/A4001/A400103/40000692/' },
  { name: '真', url: 'https://tabelog.com/fukuoka/A4001/A400103/40003911/' },
  { name: '新三浦 天神店', url: 'https://tabelog.com/fukuoka/A4001/A400103/40000066/' },
  { name: '利花苑 大名本店', url: 'https://tabelog.com/fukuoka/A4001/A400104/40000443/' },
  { name: '106 サウスインディアン 福岡天神店', url: 'https://tabelog.com/fukuoka/A4001/A400103/40041110/' },
];
github seratch / slack-app-examples / reacjilator-bolt-typescript / app.ts View on Github external
projectId: process.env.GOOGLE_PROJECT_ID,
  key: process.env.GOOGLE_KEY
}
const googleApi: GoogleTranslateApi = new GoogleTranslateApi(googleApiCredentials);

// ----------------
// Enable debug logging if true
const debug: boolean = true;
// lang code mapping data
import { langcode } from './langcode';

// ----------------
// Slack Bolt App
import { App, ExpressReceiver } from '@slack/bolt';

const expressReceiver = new ExpressReceiver({
  signingSecret: process.env.SLACK_SIGNING_SECRET
  // Endpoints will be attached later by calling the declared methods in Bolt's App
});
export const expressApp = expressReceiver.app;

const app: App = new App({
  token: process.env.SLACK_BOT_TOKEN,
  receiver: expressReceiver
});

app.event('reaction_added', async ({ event }) => {
  try {
    if (debug) {
      console.log(event);
    }
    if (event.item['type'] !== 'message') {
github seratch / slack-app-examples / serverless-bolt-template / aws-js / app.js View on Github external
'use strict';

// ------------------------------------------------------
// Bot app
// https://slack.dev/bolt/
const { App, ExpressReceiver } = require('@slack/bolt');
const expressReceiver = new ExpressReceiver({
  signingSecret: process.env.SLACK_SIGNING_SECRET
});
const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  receiver: expressReceiver
});
module.exports.expressApp = expressReceiver.app;

// ------------------------------------------------------
// If you need to use API methods that are not listed on https://api.slack.com/bot-users#methods
// you need to use user api token instead like this:
const { WebClient } = require('@slack/web-api');
app.client = new WebClient(process.env.SLACK_API_TOKEN);

// ------------------------------------------------------

// React to "app_mention" events
app.event('app_mention', ({ event, say }) => {
  app.client.users.info({ user: event.user })
github seratch / slack-app-examples / bolt-serverless-aws-template / aws-js / app.js View on Github external
'use strict';

// ------------------------------------------------------
// Bot app
// https://slack.dev/bolt/
const { App, ExpressReceiver } = require('@slack/bolt');
const expressReceiver = new ExpressReceiver({
  signingSecret: process.env.SLACK_SIGNING_SECRET
});
const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  receiver: expressReceiver
});
module.exports.expressApp = expressReceiver.app;

// ------------------------------------------------------
// If you need to use API methods that are not listed on https://api.slack.com/bot-users#methods
// you need to use user api token instead like this:
const { WebClient } = require('@slack/web-api');
app.client = new WebClient(process.env.SLACK_API_TOKEN);

// ------------------------------------------------------

// React to "app_mention" events
app.event('app_mention', ({ event, say }) => {
  app.client.users.info({ user: event.user })
github seratch / slack-app-examples / serverless-bolt-template / aws-ts / app.ts View on Github external
// Type definitions in TypeScript
import * as WebApi from 'seratch-slack-types/web-api';
import { Request, Response, Application } from 'express';

// ------------------------------------------------------
// Bot app
// https://slack.dev/bolt/
import { App, ExpressReceiver } from '@slack/bolt';

const expressReceiver = new ExpressReceiver({
  signingSecret: process.env.SLACK_SIGNING_SECRET
  // Endpoints will be attached later by calling the declared methods in Bolt's App
});
export const expressApp: Application = expressReceiver.app;

const app: App = new App({
  token: process.env.SLACK_BOT_TOKEN,
  receiver: expressReceiver
});

// ------------------------------------------------------
// If you need to use API methods that are not listed on https://api.slack.com/bot-users#methods
// you need to use user api token instead like this:
import { WebClient } from '@slack/web-api';
app.client = new WebClient(process.env.SLACK_API_TOKEN);

// ------------------------------------------------------

// React to "app_mention" events
app.event('app_mention', async ({ event, say }) => {
  app.client.users.info({ user: event.user })
    .then((res: WebApi.UsersInfoResponse) => {
github seratch / slack-app-examples / bolt-gcp-js-template / app.js View on Github external
'use strict';

const config = require('./config.js');

// ------------------------------------------------------
// Bot app
// https://slack.dev/bolt/
const { App, ExpressReceiver } = require('@slack/bolt');
const expressReceiver = new ExpressReceiver({
  signingSecret: config.SLACK_SIGNING_SECRET
});
const app = new App({
  token: config.SLACK_BOT_TOKEN,
  receiver: expressReceiver
});
const expressApp = expressReceiver.app;

// ------------------------------------------------------
// If you need to use API methods that are not listed on https://api.slack.com/bot-users#methods
// you need to use user api token instead like this:
const { WebClient } = require('@slack/web-api');
app.client = new WebClient(config.SLACK_API_TOKEN);

// ------------------------------------------------------

// React to "app_mention" events
app.event('app_mention', ({ event, say }) => {
  app.client.users.info({ user: event.user })
github seratch / slack-app-examples / bolt-serverless-aws-template / aws-ts / app.ts View on Github external
// ------------------------------------------------------
// Type definitions in TypeScript
import * as WebApi from 'seratch-slack-types/web-api';
import { Request, Response, Application } from 'express';

// ------------------------------------------------------
// Bot app
// https://slack.dev/bolt/
import { App, ExpressReceiver } from '@slack/bolt';

const expressReceiver = new ExpressReceiver({
  signingSecret: process.env.SLACK_SIGNING_SECRET
});
export const expressApp: Application = expressReceiver.app;

const app: App = new App({
  token: process.env.SLACK_BOT_TOKEN,
  receiver: expressReceiver
});

// ------------------------------------------------------
// If you need to use API methods that are not listed on https://api.slack.com/bot-users#methods
// you need to use user api token instead like this:
import { WebClient } from '@slack/web-api';
app.client = new WebClient(process.env.SLACK_API_TOKEN);

// ------------------------------------------------------

// React to "app_mention" events
app.event('app_mention', async ({ event, say }) => {
  app.client.users.info({ user: event.user })
    .then((res: WebApi.UsersInfoResponse) => {

@slack/bolt

A framework for building Slack apps, fast.

MIT
Latest version published 20 days ago

Package Health Score

95 / 100
Full package analysis

Popular @slack/bolt functions