-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathcleanup_example.py
76 lines (56 loc) · 1.75 KB
/
cleanup_example.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
73
74
75
76
#!/usr/bin/env python
"""ARI resources may be closed, if an application only needs them temporarily.
"""
#
# Copyright (c) 2013, Digium, Inc.
#
from __future__ import print_function
import ari
import logging
import sys
import six.moves._thread as thread
logging.basicConfig()
client = ari.connect('http://localhost:8088/', 'hey', 'peekaboo')
# noinspection PyUnusedLocal
def on_start(channel, event):
"""Callback for StasisStart events.
On new channels, register the on_dtmf callback, answer the channel and
play "Hello, world"
:param channel: Channel DTMF was received from.
:param event: Event.
"""
on_dtmf_handle = None
def on_dtmf(channel, event):
"""Callback for DTMF events.
When DTMF is received, play the digit back to the channel. # hangs up,
* plays a special message.
:param channel: Channel DTMF was received from.
:param event: Event.
"""
digit = event['digit']
if digit == '#':
channel.play(media='sound:goodbye')
channel.continueInDialplan()
on_dtmf_handle.close()
elif digit == '*':
channel.play(media='sound:asterisk-friend')
else:
channel.play(media='sound:digits/%s' % digit)
on_dtmf_handle = channel.on_event('ChannelDtmfReceived', on_dtmf)
channel.answer()
channel.play(media='sound:hello-world')
client.on_channel_event('StasisStart', on_start)
# Run the WebSocket
sync = thread.allocate_lock()
def run():
"""Thread for running the Websocket.
"""
sync.acquire()
client.run(apps="hello")
sync.release()
thr = thread.start_new_thread(run, ())
print("Press enter to exit")
sys.stdin.readline()
client.close()
sync.acquire()
print("Application finished")