gpt4 book ai didi

python - Python 上的 Asterisk 调用管理器挂断事件

转载 作者:太空宇宙 更新时间:2023-11-03 18:24:28 25 4
gpt4 key购买 nike

如何挂断最近通过 AMI 发起的调用。?我使用下面的代码来发起调用,但我不知道如何挂断同一发起的调用。

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')

我尝试添加 Action: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')

运行上述代码后收到的消息:

>>> ================================ 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


>>>

最佳答案

你需要

1) 监听事件并查看新创建 channel 的 channel ID

http://www.voip-info.org/wiki/view/asterisk+manager+events

2) 将挂断操作(不是事件)与 channel 名称一起放置

http://www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Hangup

关于python - Python 上的 Asterisk 调用管理器挂断事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23489338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com