From: ibidyouadu Date: Sat, 9 Sep 2023 22:02:12 +0000 (+0000) Subject: Dynamically use the user's number rather than having a hard coded number to send to X-Git-Url: http://git.angelumana.com/?a=commitdiff_plain;h=refs%2Fheads%2Fmain;p=diane%2F.git Dynamically use the user's number rather than having a hard coded number to send to --- 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: