Skip to content
This repository has been archived by the owner on Jun 13, 2022. It is now read-only.

Latest commit

 

History

History
57 lines (46 loc) · 1.53 KB

File metadata and controls

57 lines (46 loc) · 1.53 KB

@slack/bolt-aws-lambda prototype

This repository was created in the aim of demonstrating the possibilities of proper FaaS (AWS Lambda, Google Cloud Functions etc) environment support by Bolt. As of December 2019, there is no plan to merge this implementation into Bolt framework.

How it works

import { AwsLambdaReceiver } from './src/added/AwsLambdaReceiver';
import { TwoPhaseApp } from './src/added/TwoPhaseApp';
import { sleep } from './src/added/helpers';

const app = new TwoPhaseApp({
  token: process.env.SLACK_BOT_TOKEN,
  receiver: new AwsLambdaReceiver({
    signingSecret: process.env.SLACK_SIGNING_SECRET
  })
});

app.command('/lambda')
  .ack(({ ack }) => {
    ack('ack response');
  })
  .then(async ({ body, say }) => {
    app.logger.info("You are here after the acknowledgement...");
    let totalMillis = 0;
    while (totalMillis < 5000) { // sleep for 5 seconds
      totalMillis += 1000;
      await sleep(1000);
      app.logger.info('Sleeping...');
    }
    app.logger.info("Let's go!");
    return say('How are you?').then(() => say("I'm good!"));
  });

export const main = app.receiver().toHandler();

demo

Run the app on your local machine

cp _env .env
# edit .env
npm i
npm i serverless -g
sls offline --printOutput

Deploy the app onto AWS

export SLACK_BOT_TOKEN=xoxb-xxxxxxxxx
export SLACK_SIGNING_SECRET=xxxxxxxxx
export SERVERLESS_STAGE=dev
sls deploy --stage ${SERVERLESS_STAGE} -v