Skip to content

Commit

Permalink
Fix Chat Id Param issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh Patel authored and Harsh Patel committed Apr 15, 2023
1 parent 862882c commit 35b0179
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/twilio_handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter, Form, Response
from fastapi import APIRouter, Form, Response, Request
from twilio.twiml.messaging_response import MessagingResponse
from chat_handler import process_chat_message
from voice_handler import process_voice_message
Expand All @@ -7,7 +7,7 @@


@twilio_api_reply.post("/api")
async def handle_twilio_api_reply(Body: str = Form(""), MediaUrl0: str = Form("")):
async def handle_twilio_api_reply(request:Request,Body: str = Form(""), MediaUrl0: str = Form("")):
"""
Handle incoming text or voice messages from Twilio and generate appropriate responses.
Expand All @@ -18,12 +18,15 @@ async def handle_twilio_api_reply(Body: str = Form(""), MediaUrl0: str = Form(""
Returns:
Response: The generated response as a text message or a photo with a caption, depending on the type of output.
"""

form_data= await request.form()
chat_id=form_data.get("From")
if MediaUrl0:
# Process voice messages
output = await process_voice_message(MediaUrl0, 0)
output = await process_voice_message(MediaUrl0, chat_id)
else:
# Process text messages
output = await process_chat_message(Body, 0)
output = await process_chat_message(Body, chat_id)

print(output)
resp = MessagingResponse()
Expand Down

0 comments on commit 35b0179

Please sign in to comment.