-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
38 lines (35 loc) · 1.28 KB
/
app.py
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
from chalice import Chalice, Response
from twilio.base.exceptions import TwilioRestException
from chalicelib import sms
app = Chalice(app_name="sms-serverless")
@app.route("/service/sms/send", methods=["POST"])
def send_sms():
request_body = app.current_request.json_body
if request_body:
try:
resp = sms.send(request_body)
if resp:
return Response(
status_code=201,
headers={"Content-Type": "application/json"},
body={
"status": "successo",
"data": resp.sid,
"message": "SMS enviado com sucesso",
},
)
else:
return Response(
status_code=200,
headers={"Content-Type": "application/json"},
body={
"status": "falha",
"message": "Por favor, tente novamente!!!",
},
)
except TwilioRestException as exc:
return Response(
status_code=400,
headers={"Content-Type": "application/json"},
body={"status": "failure", "message": exc.msg},
)