From f104c0bc6805bad1006a6cdbfbb0efe0749d0d9d Mon Sep 17 00:00:00 2001 From: Ethan Zimbelman Date: Wed, 18 Oct 2023 09:40:13 -0700 Subject: [PATCH] Allow a custom `SocketModeReceiver` to be used with Socket Mode (#1972) --- src/App-basic-features.spec.ts | 20 +++++++++++++++++++- src/App.ts | 5 +---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/App-basic-features.spec.ts b/src/App-basic-features.spec.ts index 7559d3157..78a815380 100644 --- a/src/App-basic-features.spec.ts +++ b/src/App-basic-features.spec.ts @@ -14,6 +14,7 @@ import { } from './types'; import { ConversationStore } from './conversation-store'; import App from './App'; +import SocketModeReceiver from './receivers/SocketModeReceiver'; // Utility functions const noop = () => Promise.resolve(undefined); @@ -264,7 +265,7 @@ describe('App basic features', () => { assert.propertyVal(error, 'code', ErrorCode.AppInitializationError); } }); - it('should fail when both socketMode and receiver are specified', async () => { + it('should fail when both socketMode and a custom receiver are specified', async () => { // Arrange const fakeReceiver = new FakeReceiver(); const MockApp = await importApp(); @@ -278,6 +279,23 @@ describe('App basic features', () => { assert.propertyVal(error, 'code', ErrorCode.AppInitializationError); } }); + it('should succeed when both socketMode and SocketModeReceiver are specified', async () => { + // Arrange + const fakeBotId = 'B_FAKE_BOT_ID'; + const fakeBotUserId = 'U_FAKE_BOT_USER_ID'; + const overrides = mergeOverrides( + withNoopAppMetadata(), + withSuccessfulBotUserFetchingWebClient(fakeBotId, fakeBotUserId), + ); + const MockApp = await importApp(overrides); + const socketModeReceiver = new SocketModeReceiver({ appToken: '' }); + + // Act + const app = new MockApp({ token: '', signingSecret: '', socketMode: true, receiver: socketModeReceiver }); + + // Assert + assert.instanceOf(app, MockApp); + }); it('should initialize MemoryStore conversation store by default', async () => { // Arrange const fakeMemoryStore = sinon.fake(); diff --git a/src/App.ts b/src/App.ts index 055c82494..5fea2290c 100644 --- a/src/App.ts +++ b/src/App.ts @@ -1177,10 +1177,7 @@ export default class App ): Receiver { if (receiver !== undefined) { // Custom receiver supplied - if (this.socketMode === true) { - // socketMode = true should result in SocketModeReceiver being used as receiver - // TODO: Add case for when socketMode = true and receiver = SocketModeReceiver - // as this should not result in an error + if (this.socketMode === true && !(receiver instanceof SocketModeReceiver)) { throw new AppInitializationError('You cannot supply a custom receiver when socketMode is set to true.'); } return receiver;