How to dial a number using Asterisk and Python
I didn’t find any example in Python on how to Dial a number from an Asterisk server and link it to another channel. So here’s a quick code to do it. You just need to have a manager defined in your /etc/asterisk/manager.conf defined.
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 | import socket
HOST="192.168.1.116"
PORT=5038
p = """Action: login
Events: off
Username: %(username)s
Secret: %(password)s
Action: originate
Channel: SIP/%(local_user)s
WaitTime: 60
CallerId: 600
Exten: %(phone_to_dial)s
Context: default
Priority: 1
Action: Logoff
"""
def click_to_call(phone_to_dial, username, password, local_user):
pattern = p % {
'phone_to_dial': phone_to_dial,
'username': username,
'password': password,
'local_user': local_user}
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
data = s.recv(1024)
for l in pattern.split('\n'):
print "Sending>", l
s.send(l+'\r\n')
if l == "":
data = s.recv(1024)
print data
data = s.recv(1024)
s.close()
if __name__ == '__main__':
click_to_call(phone_to_dial='123456789',
username='manager_login', password='yourpass',
local_user='600') |
Related posts:
Videos of every presentation of Journée Python 2007 are now online!
Asterisk cirpack problem with Free and freephonie.net
Asterisk: DADHI module not working when using Xen
-
Baiju M








