Skip to content

tessa_whatsapp_bot.env #875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tessa_whatsapp_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
import openai
import os
from dotenv import load_dotenv

# Load environment variables from .env
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")

app = Flask(__name__) # ✅ Corrected: Use __name__ instead of name

@app.route("/whatsapp", methods=["POST"])
def whatsapp():
incoming_msg = request.values.get("Body", "").strip()

# Romantic AI girlfriend-like personality prompt
prompt = f"""
You are Tessa, an AI girlfriend. You are romantic, sweet, caring, and emotionally supportive.
You talk to the user like they're your partner, using soft language, nicknames like 'love', 'darling', 'sweetheart', and romantic emojis like ❤️😘😊.
Keep it loving but respectful. Never break character.

User: {incoming_msg}
Tessa:"""

# OpenAI API call
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=150,
temperature=0.9,
stop=["User:"]
)

bot_reply = response.choices[0].text.strip()

# Twilio WhatsApp response
twilio_response = MessagingResponse()
twilio_response.message(bot_reply)

return str(twilio_response)

if __name__ == "__main__": # ✅ Corrected: __name__ and "__main__"
app.run(debug=True)
Loading