@@ -180,9 +180,26 @@ def handle_webhook():
180
180
if is_conversation_human_replied (conversation_id , r ):
181
181
logger .info (f"Conversation { conversation_id } already marked as human admin-replied; no action taken." )
182
182
return 'OK'
183
+
184
+ # Check if the conversation is of type email
185
+ conversation_type = data .get ('data' , {}).get ('item' , {}).get ('source' , {}).get ('type' )
186
+ if conversation_type == 'email' :
187
+ logger .info (f"Conversation { conversation_id } is of type email; no action taken." )
188
+ return 'OK'
189
+
183
190
# Fetch the conversation and generate an LLM answer for the user
184
191
logger .info (f"Detected a user reply in conversation { conversation_id } ; fetching an answer from LLM..." )
185
192
answer_intercom_conversation (app .rag_system , conversation_id )
193
+
194
+ elif topic == 'conversation.user.created' :
195
+ # In this case, the webhook event is a new user conversation
196
+ # Check if the conversation is of type email
197
+ conversation_type = data .get ('data' , {}).get ('item' , {}).get ('source' , {}).get ('type' )
198
+ if conversation_type == 'email' :
199
+ logger .info (f"New conversation { conversation_id } is of type email; no action taken." )
200
+ else :
201
+ logger .info (f"New conversation { conversation_id } is not of type email; generating an answer from LLM..." )
202
+ answer_intercom_conversation (app .rag_system , conversation_id )
186
203
else :
187
204
logger .info (f"Received webhook for unsupported topic: { topic } ; no action taken." )
188
205
return 'OK'
0 commit comments