Spaces:
Running
Running
File size: 882 Bytes
ef1dd9e f37d4b8 ef1dd9e f37d4b8 ef1dd9e f37d4b8 ef1dd9e |
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 |
import requests
from fastapi import FastAPI, Request
from fastapi.responses import PlainTextResponse
from pydantic import BaseModel
import json
from logs import logger, log_execution_time
app = FastAPI()
@log_execution_time
@app.post("/message")
async def twilio_message_endpoint(request: Request):
data = await request.form()
user_input = data.get("Body", "")
reqUrl = "https://mattoofahad-whatsapp-endpoint.hf.space/message"
headersList = {
"User-Agent": "Thunder Client (https://www.thunderclient.com)",
"accept": "application/json",
"Content-Type": "application/json",
}
payload = json.dumps({"user_input": str(user_input)})
response = requests.request("POST", reqUrl, data=payload, headers=headersList)
logger.info(response.text)
return PlainTextResponse(response.text)
if __name__ == "__main__":
app.run()
|