From 4255dec381ff4224bc30f828e20fb82046d21625 Mon Sep 17 00:00:00 2001 From: ibidyouadu Date: Sat, 9 Sep 2023 22:02:12 +0000 Subject: [PATCH] Dynamically use the user's number rather than having a hard coded number to send to --- main.py | 4 ++-- utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 6bc11b6..7041bc8 100644 --- a/main.py +++ b/main.py @@ -25,7 +25,7 @@ r.rpush(conversation_key, init_payload) @app.post("/") -async def reply(Body: str=Form()): +async def reply(Body: str=Form(), From: str=Form()): # Add to payload for OpenAI API input_message = { "role": "user", @@ -59,6 +59,6 @@ async def reply(Body: str=Form()): logger.info("Stored the response in the database.") # Send response to user - send_message(TO_NUMBER, output_body) + send_message(From, output_body) return True \ No newline at end of file diff --git a/utils.py b/utils.py index bea97c9..675b9b1 100644 --- a/utils.py +++ b/utils.py @@ -15,7 +15,7 @@ def send_message(to_number, body_text): message = client.messages.create( from_=f"whatsapp:{TWILIO_NUMBER}", body=body_text, - to=f"whatsapp:{to_number}" + to=f"{to_number}" ) logger.info(f"Message sent to {to_number}: {message.body}") except Exception as e: -- 2.43.0