narendrasinghd commited on
Commit
6978a3d
·
verified ·
1 Parent(s): 91addc1

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -5
app.py CHANGED
@@ -1,6 +1,8 @@
1
  from fastapi import FastAPI, Request, Depends, HTTPException, status
2
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
3
  import random
 
 
4
 
5
  app = FastAPI()
6
  security = HTTPBearer()
@@ -66,10 +68,37 @@ async def book_ticket(request: Request):
66
  "message": f"Ticket booked for '{movie_name}'. Username: {username}, Time: {time}, Price: {price}"
67
  }
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  @app.get('/generate_otp')
70
- async def generate_otp(token: str = Depends(verify_token)):
71
  otp = random.randint(10000, 99999)
72
- return {
73
- "status": "success",
74
- "otp": otp
75
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from fastapi import FastAPI, Request, Depends, HTTPException, status
2
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
3
  import random
4
+ from pydantic import BaseModel
5
+
6
 
7
  app = FastAPI()
8
  security = HTTPBearer()
 
68
  "message": f"Ticket booked for '{movie_name}'. Username: {username}, Time: {time}, Price: {price}"
69
  }
70
 
71
+ class AgentActionContent(BaseModel):
72
+ email: str = None
73
+ from_number: str = None
74
+ to_number: str
75
+
76
+
77
+ class AgentAction(BaseModel):
78
+ name: str
79
+ content: AgentActionContent
80
+
81
+ class Payload(BaseModel):
82
+ agent_action_id: str
83
+ agent_action: AgentAction
84
+
85
  @app.get('/generate_otp')
86
+ async def generate_otp(payload: Payload, token: str = Depends(verify_token)):
87
  otp = random.randint(10000, 99999)
88
+
89
+ if payload.agent_action.content.from_number is None:
90
+ print(f"[AMSService][generate_otp] Generating OTP for email: {payload.agent_action.content.email}")
91
+ result = {
92
+ "status": "success",
93
+ "verification_code": otp,
94
+ "message": f"OTP generated for email: {payload.agent_action.content.email}"
95
+ }
96
+ else:
97
+ print(f"[AMSService][generate_otp] Generating OTP for phone number: {payload.agent_action.content.from_number}")
98
+ result = {
99
+ "status": "success",
100
+ "verification_code": otp,
101
+ "message": f"OTP generated for phone number: {payload.agent_action.content.from_number}"
102
+ }
103
+
104
+ return result