-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
72 lines (58 loc) · 1.61 KB
/
bot.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import json
from flask import Flask, request
from twilio.twiml.voice_response import VoiceResponse, Gather, Dial
from twilio import twiml
from twilio.rest import Client
# Importing json data
try:
with open("creds.json", "r") as f:
json_data = json.load(f)
data = json_data[0]
from_ = data["From"]
to_ = data["To"]
ngrok_url = data["ngrok_url"]
auth_token = data["auth_token"]
sid = data["Account SID"]
except Exception as e:
print(e)
print("A problem occured in exporting json data")
import sys
sys.exit()
app = Flask(__name__)
@app.route("/dial", methods=['GET', 'POST'])
def dial():
"""Return TwiML for a moderated conference call."""
# Start our TwiML response
resp = VoiceResponse()
resp.say("I am going to transfer you call now.")
resp.dial("+919833171351")
resp.say("Sorry, we will try to reach you later")
# resp.append(dial)
return str(resp)
@app.route("/hello", methods=['GET', 'POST'])
def hello():
# Start a TwiML response
try:
resp = VoiceResponse()
except Exception as e:
print(e)
try:
gather = Gather(input='speech', timeout=2 , action='/voice')
gather.say("Hi This is Sajzad, How are you today?")
resp.append(gather)
except Exception as e:
print(e)
resp.redirect("/voice")
return str(resp)
client = Client(sid, auth_token)
print(ngrok_url+"/voice")
try:
call = client.calls.create(
url = ngrok_url+"/dial",
to = to_,
from_ = from_
)
except Exception as e:
print(e)
if __name__ == '__main__':
app.run(debug=True)