mattoofahaddcube commited on
Commit
f37d4b8
Β·
1 Parent(s): 3ac85c9
Files changed (1) hide show
  1. main.py +4 -8
main.py CHANGED
@@ -2,29 +2,25 @@ import requests
2
  from fastapi import FastAPI, Request
3
  from fastapi.responses import PlainTextResponse
4
  from pydantic import BaseModel
 
5
 
6
  from logs import logger, log_execution_time
7
 
8
  app = FastAPI()
9
 
10
 
11
- class UserInputModel(BaseModel):
12
- user_input: str
13
-
14
-
15
  @log_execution_time
16
  @app.post("/message")
17
  async def twilio_message_endpoint(request: Request):
18
  data = await request.form()
19
  user_input = data.get("Body", "")
20
- user_input = data.user_input
21
  reqUrl = "https://mattoofahad-whatsapp-endpoint.hf.space/message"
22
  headersList = {
23
- "Accept": "*/*",
24
  "User-Agent": "Thunder Client (https://www.thunderclient.com)",
25
- "Content-Type": "application/x-www-form-urlencoded",
 
26
  }
27
- payload = f"Body={user_input}"
28
  response = requests.request("POST", reqUrl, data=payload, headers=headersList)
29
  logger.info(response.text)
30
  return PlainTextResponse(response.text)
 
2
  from fastapi import FastAPI, Request
3
  from fastapi.responses import PlainTextResponse
4
  from pydantic import BaseModel
5
+ import json
6
 
7
  from logs import logger, log_execution_time
8
 
9
  app = FastAPI()
10
 
11
 
 
 
 
 
12
  @log_execution_time
13
  @app.post("/message")
14
  async def twilio_message_endpoint(request: Request):
15
  data = await request.form()
16
  user_input = data.get("Body", "")
 
17
  reqUrl = "https://mattoofahad-whatsapp-endpoint.hf.space/message"
18
  headersList = {
 
19
  "User-Agent": "Thunder Client (https://www.thunderclient.com)",
20
+ "accept": "application/json",
21
+ "Content-Type": "application/json",
22
  }
23
+ payload = json.dumps({"user_input": str(user_input)})
24
  response = requests.request("POST", reqUrl, data=payload, headers=headersList)
25
  logger.info(response.text)
26
  return PlainTextResponse(response.text)