Spaces:
Sleeping
Sleeping
File size: 1,242 Bytes
1b846eb d92c861 1b846eb 1bd9947 54db18f 13ac926 005c659 d92c861 1b846eb d92c861 13ac926 66e97f3 fed63e7 13ac926 66e97f3 1b846eb 66e97f3 6c7df80 e782b03 1b846eb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
from fastapi import FastAPI, Request, HTTPException
from fastapi.responses import PlainTextResponse
from fastapi.middleware.cors import CORSMiddleware
from twilio.twiml.messaging_response import MessagingResponse
import os
import google.generativeai as genai
secret = os.environ["key"]
genai.configure(api_key=secret)
model = genai.GenerativeModel('gemini-pro')
GOOD_BOY_URL = (
"https://images.unsplash.com/photo-1518717758536-85ae29035b6d?ixlib=rb-1.2.1"
"&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80"
)
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/whatsapp")
async def reply_whatsapp(request: Request):
form_data = await request.form()
num_media = int(form_data.get("NumMedia", 0))
from_number = form_data.get("From")
message_body = form_data.get("Body")
response = MessagingResponse()
msg = response.message(f"Hi, your number is {from_number} and you said {message_body}")
msg.media(GOOD_BOY_URL)
return PlainTextResponse(str(response), media_type="application/xml")
# Run the application (Make sure you have the necessary setup to run FastAPI)
|