Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -190,32 +190,29 @@ async def send_to_slack(message: str):
|
|
190 |
except Exception as e:
|
191 |
print("❌ Slack Send Error:", e)
|
192 |
|
193 |
-
async def get_chatwoot_conversation(conversation_id:
|
194 |
-
"""Fetch conversation details from Chatwoot"""
|
195 |
try:
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
conversation = conv_resp.json()
|
205 |
-
|
206 |
-
# Get conversation messages
|
207 |
msgs_url = f"{CHATWOOT_BASE_URL}/api/v1/accounts/{CHATWOOT_ACCOUNT_ID}/conversations/{conversation_id}/messages"
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
)
|
212 |
msgs_resp.raise_for_status()
|
|
|
|
|
213 |
messages = msgs_resp.json()
|
|
|
214 |
|
215 |
-
|
216 |
-
|
217 |
-
"messages": messages
|
218 |
-
}
|
219 |
except Exception as e:
|
220 |
print(f"❌ Error fetching Chatwoot conversation: {e}")
|
221 |
return None
|
|
|
190 |
except Exception as e:
|
191 |
print("❌ Slack Send Error:", e)
|
192 |
|
193 |
+
async def get_chatwoot_conversation(conversation_id: int) -> Optional[dict]:
|
194 |
+
"""Fetch conversation details and messages from Chatwoot"""
|
195 |
try:
|
196 |
+
headers = {
|
197 |
+
"api_access_token": CHATWOOT_API_KEY,
|
198 |
+
"Content-Type": "application/json",
|
199 |
+
"Accept": "application/json"
|
200 |
+
}
|
201 |
+
|
202 |
+
async with httpx.AsyncClient(timeout=30.0) as http:
|
203 |
+
# Get conversation messages directly since that's what we need
|
|
|
|
|
|
|
204 |
msgs_url = f"{CHATWOOT_BASE_URL}/api/v1/accounts/{CHATWOOT_ACCOUNT_ID}/conversations/{conversation_id}/messages"
|
205 |
+
print(f"Fetching messages from: {msgs_url}")
|
206 |
+
|
207 |
+
msgs_resp = await http.get(msgs_url, headers=headers)
|
|
|
208 |
msgs_resp.raise_for_status()
|
209 |
+
|
210 |
+
# The API returns the payload directly as an array of messages
|
211 |
messages = msgs_resp.json()
|
212 |
+
print(f"Fetched {len(messages) if messages else 0} messages")
|
213 |
|
214 |
+
# Return the messages in the expected format
|
215 |
+
return {"payload": messages}
|
|
|
|
|
216 |
except Exception as e:
|
217 |
print(f"❌ Error fetching Chatwoot conversation: {e}")
|
218 |
return None
|