Skip to content

Commit

Permalink
allow the socket mode receiver to be used with socket mode
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeg committed Oct 16, 2023
1 parent 2b259a9 commit 1b59b70
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
20 changes: 19 additions & 1 deletion src/App-basic-features.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
5 changes: 1 addition & 4 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1177,10 +1177,7 @@ export default class App<AppCustomContext extends StringIndexed = StringIndexed>
): 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;
Expand Down

0 comments on commit 1b59b70

Please sign in to comment.