File size: 1,218 Bytes
d92c861
 
 
 
 
 
 
54db18f
 
13ac926
 
 
 
005c659
d92c861
13ac926
 
 
d92c861
 
 
 
 
 
 
 
 
 
 
07fe890
 
13ac926
 
 
66e97f3
 
 
fed63e7
13ac926
66e97f3
 
 
 
 
e782b03
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
44
45
46
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)