| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- const logger = require('@alias/logger')('growi:service:BoltService');
- class BoltReciever {
- init(app) {
- this.bolt = app;
- }
- async requestHandler(req, res) {
- let ackCalled = false;
- const event = {
- body: req.body,
- ack: (response) => {
- if (ackCalled) {
- return;
- }
- if (response instanceof Error) {
- res.status(500).send();
- }
- else if (!response) {
- res.send('');
- }
- else {
- res.send(response);
- }
- ackCalled = true;
- },
- };
- await this.bolt.processEvent(event);
- // for verification request URL on Event Subscriptions
- res.send(req.body);
- }
- }
- const { App } = require('@slack/bolt');
- class BoltService {
- constructor(crowi) {
- this.crowi = crowi;
- this.receiver = new BoltReciever();
- const token = process.env.SLACK_BOT_TOKEN;
- const signingSecret = process.env.SLACK_SIGNING_SECRET;
- if (token != null || signingSecret != null) {
- logger.debug('TwitterStrategy: setup is done');
- this.bolt = new App({
- token,
- signingSecret,
- receiver: this.receiver,
- });
- this.init();
- }
- }
- init() {
- // Example of listening for event
- // See. https://github.com/slackapi/bolt-js#listening-for-events
- // or https://slack.dev/bolt-js/concepts#basic
- this.bolt.command('/growi-bot', async({ command, ack, say }) => { // demo
- await say('Hello');
- });
- // The echo command simply echoes on command
- this.bolt.command('/echo', async({ command, ack, say }) => {
- // Acknowledge command request
- await ack();
- await say(`${command.text}`);
- });
- }
- }
- module.exports = BoltService;
|