Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a custom SocketModeReceiver to be used with Socket Mode #1972

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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