diff --git a/src/App.ts b/src/App.ts index a116c20ff..260ebdab4 100644 --- a/src/App.ts +++ b/src/App.ts @@ -61,6 +61,7 @@ const packageJson = require('../package.json'); // tslint:disable-line:no-requir export interface AppOptions { signingSecret?: ExpressReceiverOptions['signingSecret']; endpoints?: ExpressReceiverOptions['endpoints']; + processBeforeResponse?: ExpressReceiverOptions['processBeforeResponse']; agent?: Agent; clientTls?: Pick; convoStore?: ConversationStore | false; @@ -73,7 +74,6 @@ export interface AppOptions { logLevel?: LogLevel; ignoreSelf?: boolean; clientOptions?: Pick; - processBeforeResponse?: boolean; } export { LogLevel, Logger } from '@slack/logger'; diff --git a/src/ExpressReceiver.ts b/src/ExpressReceiver.ts index 514647152..f125bfafa 100644 --- a/src/ExpressReceiver.ts +++ b/src/ExpressReceiver.ts @@ -68,32 +68,21 @@ export default class ExpressReceiver implements Receiver { // tslint:disable-next-line: align }, 3001); - let event: ReceiverEvent; let storedResponse = undefined; - if (this.processBeforeResponse) { - event = { - body: req.body, - ack: async (response): Promise => { - if (isAcknowledged) { - throw new ReceiverMultipleAckError(); - } - isAcknowledged = true; + const event: ReceiverEvent = { + body: req.body, + ack: async (response): Promise => { + if (isAcknowledged) { + throw new ReceiverMultipleAckError(); + } + isAcknowledged = true; + if (this.processBeforeResponse) { if (!response) { - res.send(''); + storedResponse = ''; } else { storedResponse = response; } - }, - }; - - } else { - event = { - body: req.body, - ack: async (response): Promise => { - if (isAcknowledged) { - throw new ReceiverMultipleAckError(); - } - isAcknowledged = true; + } else { if (!response) { res.send(''); } else if (typeof response === 'string') { @@ -101,9 +90,9 @@ export default class ExpressReceiver implements Receiver { } else { res.json(response); } - }, - }; - } + } + }, + }; try { await this.bolt?.processEvent(event);