embeding_api / main.py
Arafath10's picture
Update main.py
66e97f3 verified
raw
history blame
1.22 kB
from fastapi import FastAPI, File, UploadFile, HTTPException
from fastapi.responses import HTMLResponse
from fastapi.responses import StreamingResponse
from fastapi.responses import FileResponse
from fastapi.middleware.cors import CORSMiddleware
from io import StringIO
import os
import uuid,requests
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"
)
from fastapi import FastAPI, Request, HTTPException
from fastapi.responses import PlainTextResponse
from twilio.twiml.messaging_response import MessagingResponse
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 sayed {message_body}")
msg.media(GOOD_BOY_URL)
return str(response)