@@ -3,7 +3,7 @@ import { Logger } from '@gitbook/runtime';
3
3
import type { SlashEvent } from './commands' ;
4
4
import { notifyOnlySupportedThreads , queryLens , saveThread } from '../actions' ;
5
5
import { SlackRuntimeContext } from '../configuration' ;
6
- import { isSaveThreadMessage , stripBotName } from '../utils' ;
6
+ import { isAllowedToRespond , isSaveThreadMessage , stripBotName } from '../utils' ;
7
7
8
8
const logger = Logger ( 'slack:api' ) ;
9
9
@@ -39,11 +39,10 @@ export async function queryLensSlashHandler(slashEvent: SlashEvent, context: Sla
39
39
*/
40
40
export async function messageEventHandler ( eventPayload : any , context : SlackRuntimeContext ) {
41
41
// pull out required params from the event for queryLens
42
- const { type, text, bot_id, thread_ts, channel, user, team } = eventPayload . event ;
43
- const isExternalChannel = eventPayload . is_ext_shared_channel ;
42
+ const { type, text, thread_ts, channel, user, team } = eventPayload . event ;
44
43
45
44
// check for bot_id so that the bot doesn't trigger itself
46
- if ( [ 'message' , 'app_mention' ] . includes ( type ) && ! bot_id && ! isExternalChannel ) {
45
+ if ( [ 'message' , 'app_mention' ] . includes ( type ) && isAllowedToRespond ( eventPayload ) ) {
47
46
// strip out the bot-name in the mention and account for user mentions within the query
48
47
// @ts -ignore
49
48
const parsedQuery = stripBotName ( text , eventPayload . authorizations [ 0 ] ?. user_id ) ;
@@ -73,11 +72,10 @@ export async function messageEventHandler(eventPayload: any, context: SlackRunti
73
72
*/
74
73
export async function appMentionEventHandler ( eventPayload : any , context : SlackRuntimeContext ) {
75
74
// pull out required params from the slashEvent for queryLens
76
- const { type, text, bot_id, thread_ts, channel, user, team } = eventPayload . event ;
77
- const isExternalChannel = eventPayload . is_ext_shared_channel ;
75
+ const { type, text, thread_ts, channel, user, team } = eventPayload . event ;
78
76
79
77
// check for bot_id so that the bot doesn't trigger itself
80
- if ( [ 'message' , 'app_mention' ] . includes ( type ) && ! bot_id && ! isExternalChannel ) {
78
+ if ( [ 'message' , 'app_mention' ] . includes ( type ) && isAllowedToRespond ( eventPayload ) ) {
81
79
// strip out the bot-name in the mention and account for user mentions within the query
82
80
// @ts -ignore
83
81
const parsedMessage = stripBotName ( text , eventPayload . authorizations [ 0 ] ?. user_id ) ;
0 commit comments