ethiotech4848 commited on
Commit
2fa0f23
·
verified ·
1 Parent(s): fe1a100

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -34,7 +34,7 @@ async def ask(request: Request):
34
  print("📥 Incoming payload:", json.dumps(payload, indent=2))
35
 
36
  account_id = payload.get("account", {}).get("id")
37
- conversation_id = payload.get("conversation", {}).get("id")
38
  sender = payload.get("sender") or {}
39
  sender_id = sender.get("id")
40
  sender_role = (sender.get("role") or "").lower()
@@ -43,8 +43,17 @@ async def ask(request: Request):
43
 
44
  print(f"🧾 sender_id: {sender_id}, sender_role: {sender_role}, account_id: {account_id}")
45
 
46
- # Ignore non-incoming messages
47
  if message_type != "incoming":
 
 
 
 
 
 
 
 
 
48
  print("⚠️ Ignoring non-incoming message")
49
  return {"status": "ignored"}
50
 
@@ -60,12 +69,6 @@ async def ask(request: Request):
60
  await send_chatwoot_message(conversation_id, "Bot resumed and will reply to users now.")
61
  return {"status": "bot resumed"}
62
 
63
- # If message is from other inbox (Slack), disable bot
64
- if account_id != CHATWOOT_ACCOUNT_ID:
65
- stop_reply_conversations.add(conversation_id)
66
- print(f"🚫 Message from other inbox (account ID {account_id}) → disabling AI for conversation {conversation_id}")
67
- return {"status": "AI disabled due to human intervention"}
68
-
69
  # Check if AI is blacklisted for this conversation
70
  if conversation_id in stop_reply_conversations:
71
  print(f"🚫 AI is disabled for conversation {conversation_id}")
 
34
  print("📥 Incoming payload:", json.dumps(payload, indent=2))
35
 
36
  account_id = payload.get("account", {}).get("id")
37
+ conversation_id = str(payload.get("conversation", {}).get("id"))
38
  sender = payload.get("sender") or {}
39
  sender_id = sender.get("id")
40
  sender_role = (sender.get("role") or "").lower()
 
43
 
44
  print(f"🧾 sender_id: {sender_id}, sender_role: {sender_role}, account_id: {account_id}")
45
 
46
+ # Step 1: Detect agent message via Slack and disable AI for that conversation
47
  if message_type != "incoming":
48
+ messages = payload.get("conversation", {}).get("messages", [])
49
+ if messages:
50
+ msg = messages[0]
51
+ external_ids = msg.get("external_source_ids", {})
52
+ if "slack" in external_ids:
53
+ stop_reply_conversations.add(conversation_id)
54
+ print(f"🛑 Human intervened via Slack in conversation {conversation_id}. Disabling AI.")
55
+ return {"status": "AI disabled due to Slack intervention"}
56
+
57
  print("⚠️ Ignoring non-incoming message")
58
  return {"status": "ignored"}
59
 
 
69
  await send_chatwoot_message(conversation_id, "Bot resumed and will reply to users now.")
70
  return {"status": "bot resumed"}
71
 
 
 
 
 
 
 
72
  # Check if AI is blacklisted for this conversation
73
  if conversation_id in stop_reply_conversations:
74
  print(f"🚫 AI is disabled for conversation {conversation_id}")