diff --git a/src/App.spec.ts b/src/App.spec.ts index 0632b0e58..3e4d66da0 100644 --- a/src/App.spec.ts +++ b/src/App.spec.ts @@ -560,6 +560,13 @@ describe('App', () => { assert(error.code === ErrorCode.MultipleListenerError); assert.sameMembers(error.originals, errorsToThrow); }); + + it('should detect invalid event names', async () => { + app.event('app_mention', async () => {}); + app.event('message', async () => {}); + assert.throws(() => app.event('message.channels', async () => {}), 'Although the document mentions'); + assert.throws(() => app.event(/message\..+/, async () => {}), 'Although the document mentions'); + }); }); describe('WorkflowStep middleware', () => { diff --git a/src/App.ts b/src/App.ts index a6902896f..1229ebd14 100644 --- a/src/App.ts +++ b/src/App.ts @@ -422,6 +422,21 @@ export default class App { eventNameOrPattern: EventType, ...listeners: Middleware>[] ): void { + let invalidEventName = false; + if (typeof eventNameOrPattern === 'string') { + const name = eventNameOrPattern as string; + invalidEventName = name.startsWith('message.'); + } else if (eventNameOrPattern instanceof RegExp) { + const name = (eventNameOrPattern as RegExp).source; + invalidEventName = name.startsWith('message\\.'); + } + if (invalidEventName) { + throw new AppInitializationError( + `Although the document mentions "${eventNameOrPattern}",` + + 'it is not a valid event type. Use "message" instead. ' + + 'If you want to filter message events, you can use event.channel_type for it.', + ); + } this.listeners.push([ onlyEvents, matchEventType(eventNameOrPattern),