-
Notifications
You must be signed in to change notification settings - Fork 0
/
twilioresponder.py
60 lines (52 loc) · 1.83 KB
/
twilioresponder.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
#!/usr/bin/python
from bottle import route, run
import confighelper
import datetime
import jirahelpers
import logging
import mongohelper
import twilio
module = 'twilioresponder'
logger = logging.getLogger(module)
logfilename = module+'.log'
logging.basicConfig(filename=logfilename, level=logging.ERROR)
timedelta = datetime.timedelta(minutes=50)
@route('/', method='POST')
@route('/index.html', method='POST')
@route('/index.htm', method='POST')
def index():
return do()
@route('/voicemail')
def index():
response = ["<?xml version='1.0' encoding='utf-8' ?>\n"]
r = twilio.Response()
s = twilio.Say('Hello, Thank you for calling 10 jen. 10 jen develops and provides enterprise grade support for Mongo D B.')
r.append(s)
return r.__repr__()
def do():
try:
logger.info('In do')
config = confighelper.get_config()
logger.info('Obtained config')
response = ["<?xml version='1.0' encoding='utf-8' ?>\n"]
r = twilio.Response()
issues = mongohelper.get_issues_to_escalate(config,
timedelta)
if len(issues) > 0:
say_msg = ['The following issues have been opened for at least 50 minutes']
for issue in issues:
say_msg.append(', ')
say_msg.append(issue['_id'])
s = twilio.Say(''.join(say_msg))
mongohelper.mark_issues_as_escalated(config,
issues)
else:
s = twilio.Say('All escalations have been taken care of')
r.append(s)
response.append(r.__repr__())
return ''.join(response)
except Exception, e:
logger.warning(e)
if __name__ == "__main__":
config = confighelper.get_config()
run(host=config.webserver_host, port=config.webserver_port)