11import { Logger } from '@gitbook/runtime' ;
22
3+ import type { SlashEvent } from './commands' ;
34import { notifyOnlySupportedThreads , queryLens , saveThread } from '../actions' ;
45import { SlackRuntimeContext } from '../configuration' ;
5- import { isSaveThreadMessage , stripBotName } from '../utils' ;
6- import type { SlashEvent } from './commands' ;
6+ import { isAllowedToRespond , isSaveThreadMessage , stripBotName } from '../utils' ;
77
88const logger = Logger ( 'slack:api' ) ;
99
@@ -38,11 +38,11 @@ export async function queryLensSlashHandler(slashEvent: SlashEvent, context: Sla
3838 * Handle an Event request and route it to the GitBook Lens' query function.
3939 */
4040export async function messageEventHandler ( eventPayload : any , context : SlackRuntimeContext ) {
41- // pull out required params from the slashEvent for queryLens
42- const { type, text, bot_id , thread_ts, channel, user, team } = eventPayload . event ;
41+ // pull out required params from the event for queryLens
42+ const { type, text, thread_ts, channel, user, team } = eventPayload . event ;
4343
4444 // check for bot_id so that the bot doesn't trigger itself
45- if ( [ 'message' , 'app_mention' ] . includes ( type ) && ! bot_id ) {
45+ if ( [ 'message' , 'app_mention' ] . includes ( type ) && isAllowedToRespond ( eventPayload ) ) {
4646 // strip out the bot-name in the mention and account for user mentions within the query
4747 // @ts -ignore
4848 const parsedQuery = stripBotName ( text , eventPayload . authorizations [ 0 ] ?. user_id ) ;
@@ -72,10 +72,10 @@ export async function messageEventHandler(eventPayload: any, context: SlackRunti
7272 */
7373export async function appMentionEventHandler ( eventPayload : any , context : SlackRuntimeContext ) {
7474 // pull out required params from the slashEvent for queryLens
75- const { type, text, bot_id , thread_ts, channel, user, team } = eventPayload . event ;
75+ const { type, text, thread_ts, channel, user, team } = eventPayload . event ;
7676
7777 // check for bot_id so that the bot doesn't trigger itself
78- if ( [ 'message' , 'app_mention' ] . includes ( type ) && ! bot_id ) {
78+ if ( [ 'message' , 'app_mention' ] . includes ( type ) && isAllowedToRespond ( eventPayload ) ) {
7979 // strip out the bot-name in the mention and account for user mentions within the query
8080 // @ts -ignore
8181 const parsedMessage = stripBotName ( text , eventPayload . authorizations [ 0 ] ?. user_id ) ;
@@ -111,4 +111,4 @@ export async function appMentionEventHandler(eventPayload: any, context: SlackRu
111111 } ) ;
112112 }
113113 }
114- }
114+ }
0 commit comments