您好我使用Python Asterisk来处理我的星号服务器。我已经能够使用以下代码收听当前的呼叫。
def handle_event(event, manager):
with ctx:
if event.name == 'CoreShowChannel':
user_id = event.message['AccountCode']
user_id = int(user_id)
data = {
"channel":event.message['Channel'],
"channel_state":event.message['ChannelStateDesc'],
"duration":event.message['Duration'],
'extension': event.message['Exten'],
'line': event.message['ConnectedLineNum'],
'user_id': user_id,
'context': event.message['Context'],
'caller_id': event.message['CallerIDNum']
}
system = System()
user = system.getUserById(user_id)
if user:
profile = {"first_name":user.first_name, "last_name":user.last_name}
data.update(profile)
g.channels.append(data)
if event.name == 'CoreShowChannelsComplete':
g.complete = True
@app.route('/live-calls')
def live_calls():
g.complete = False
g.channels = []
manager = asterisk.manager.Manager()
manager.connect(hostname)
manager.login(username, secret)
manager.register_event('*', handle_event)
res = manager.send_action({'Action':'CoreShowChannels'})
while not g.complete:
time.sleep(0.1)
manager.close()
if len(g.channels) < 1:
return json.dumps({"response":g.complete})
return json.dumps(g.channels)
此代码用于其目的并按预期工作,现在如何实现挂起方法,当我单击挂断按钮时,当前调用挂起。问题是我知道有一个Hangup事件,但我甚至不知道要检查的对象或变量或者在哪里听。
答案 0 :(得分:0)
我刚刚调用了将通道名称作为参数的hangup方法。
我不知道有什么方法
manager.hangup(信道)
答案 1 :(得分:-2)
您必须向AMI发送命令。您可以在Asterisk CLI中列出命令及其参数
pbx*CLI> manager show commands
Action Synopsis
------ --------
AbsoluteTimeout Set absolute timeout.
AGI Add an AGI command to execute by Async AGI.
AOCMessage Generate an Advice of Charge message on a chan
Atxfer Attended transfer.
BlindTransfer Blind transfer channel(s) to the given destina
Bridge Bridge two channels already in the PBX.
BridgeDestroy Destroy a bridge.
BridgeInfo Get information about a bridge.
BridgeKick Kick a channel from a bridge.
BridgeList Get a list of bridges in the system.
BridgeTechnologyList List available bridging technologies and their
BridgeTechnologySuspend Suspend a bridging technology.
BridgeTechnologyUnsuspend Unsuspend a bridging technology.
(...)
pbx*CLI> manager show command Hangup
[Syntax]
Action: Hangup
[ActionID:] <value>
Channel: <value>
[Cause:] <value>
[Synopsis]
Hangup channel.
[Description]
Hangup a channel.
[Arguments]
ActionID
ActionID for this transaction. Will be returned.
Channel
The exact channel name to be hungup, or to use a regular expression,
set this parameter to: /regex/
Example exact channel: SIP/provider-0000012a
Example regular expression: /^SIP/provider-.*$/
Cause
Numeric hangup cause.
[See Also]
Not available
[Privilege]
system,call,all
[List Responses]
None
[Final Response]
None