How to hangup the recent originated call through AMI.? I used the code below to originate the calls but I don't know how am I supposed to hangup the same originated call.
import socket
HOST = 'localhost'
PORT = 5038
p = '''Action: login
Events: off
Username: %(username)s
Secret: %(password)s
Action: originate
Channel: Mobile/g1/%(phone_to_dial)s
WaitTime: 30
Timeout: 5
Exten: %(phone_to_dial)s
Context: home
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()
s.connect((HOST,PORT))
data = s.recv(1024)
for l in pattern.split('\n'):
print 'sending>>',1
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('918800726989',username='600',password='yourpass',local_user='11111')
I tried adding Action: hangup
but it didn't seem to work. Any help please.?
UPDATE: Codes & Error I got after adding the actions, status and hangup:
import socket
HOST = '192.168.1.3'
PORT = 5038
p = '''Action: Login
Events: off
Username: %(username)s
Secret: %(password)s
ActionID: 1
Action: Originate
ActionID: 2
Channel: SIP/11111
Exten: %(phone_to_dial)s
Context: home
priority: 1
Action: Status
ActionID: 3
Channel: SIP/11111
Action: Hangup
ActionID: 4
Channel: SIP/11111
Action: Logoff
ActionID: 5
'''
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()
s.connect((HOST,PORT))
data = s.recv(1024)
for l in pattern.split('\n'):
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('55555',username='600',password='yourpass',local_user='11111')
Message I got after running the above code:
>>> ================================ RESTART ================================
>>>
Response: Success
ActionID: 1
Message: Authentication accepted
Response: Success
ActionID: 2
Message: Originate successfully queued
Response: Error
ActionID: 3
Message: No such channel
Response: Error
ActionID: 4
Message: No such channel
Response: Goodbye
>>>