Skip to content

Commit 0958583

Browse files
authored
Create tessa_whatsapp_bot.py
1 parent 1f43fce commit 0958583

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tessa_whatsapp_bot.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from flask import Flask, request
2+
from twilio.twiml.messaging_response import MessagingResponse
3+
import openai
4+
import os
5+
from dotenv import load_dotenv
6+
7+
# Load environment variables from .env
8+
load_dotenv()
9+
openai.api_key = os.getenv("OPENAI_API_KEY")
10+
11+
app = Flask(__name__) # ✅ Corrected: Use __name__ instead of name
12+
13+
@app.route("/whatsapp", methods=["POST"])
14+
def whatsapp():
15+
incoming_msg = request.values.get("Body", "").strip()
16+
17+
# Romantic AI girlfriend-like personality prompt
18+
prompt = f"""
19+
You are Tessa, an AI girlfriend. You are romantic, sweet, caring, and emotionally supportive.
20+
You talk to the user like they're your partner, using soft language, nicknames like 'love', 'darling', 'sweetheart', and romantic emojis like ❤️😘😊.
21+
Keep it loving but respectful. Never break character.
22+
23+
User: {incoming_msg}
24+
Tessa:"""
25+
26+
# OpenAI API call
27+
response = openai.Completion.create(
28+
engine="text-davinci-003",
29+
prompt=prompt,
30+
max_tokens=150,
31+
temperature=0.9,
32+
stop=["User:"]
33+
)
34+
35+
bot_reply = response.choices[0].text.strip()
36+
37+
# Twilio WhatsApp response
38+
twilio_response = MessagingResponse()
39+
twilio_response.message(bot_reply)
40+
41+
return str(twilio_response)
42+
43+
if __name__ == "__main__": # ✅ Corrected: __name__ and "__main__"
44+
app.run(debug=True)

0 commit comments

Comments
 (0)