1
1
import { Logger } from '@gitbook/runtime' ;
2
2
3
+ import type { SlashEvent } from './commands' ;
3
4
import { notifyOnlySupportedThreads , queryLens , saveThread } from '../actions' ;
4
5
import { SlackRuntimeContext } from '../configuration' ;
5
- import { isSaveThreadMessage , stripBotName } from '../utils' ;
6
- import type { SlashEvent } from './commands' ;
6
+ import { isAllowedToRespond , isSaveThreadMessage , stripBotName } from '../utils' ;
7
7
8
8
const logger = Logger ( 'slack:api' ) ;
9
9
@@ -38,11 +38,11 @@ export async function queryLensSlashHandler(slashEvent: SlashEvent, context: Sla
38
38
* Handle an Event request and route it to the GitBook Lens' query function.
39
39
*/
40
40
export 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 ;
43
43
44
44
// 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 ) ) {
46
46
// strip out the bot-name in the mention and account for user mentions within the query
47
47
// @ts -ignore
48
48
const parsedQuery = stripBotName ( text , eventPayload . authorizations [ 0 ] ?. user_id ) ;
@@ -72,10 +72,10 @@ export async function messageEventHandler(eventPayload: any, context: SlackRunti
72
72
*/
73
73
export async function appMentionEventHandler ( eventPayload : any , context : SlackRuntimeContext ) {
74
74
// 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 ;
76
76
77
77
// 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 ) ) {
79
79
// strip out the bot-name in the mention and account for user mentions within the query
80
80
// @ts -ignore
81
81
const parsedMessage = stripBotName ( text , eventPayload . authorizations [ 0 ] ?. user_id ) ;
@@ -111,4 +111,4 @@ export async function appMentionEventHandler(eventPayload: any, context: SlackRu
111
111
} ) ;
112
112
}
113
113
}
114
- }
114
+ }
0 commit comments