2016-09-27 140 views
0

你好我正在使用Python Asterisk来处理我的星号服务器。我已经能够使用以下代码来侦听当前的呼叫。如何挂断星号中的呼叫AMI

 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事件,但我甚至不知道要检查的对象或变量或在哪里听。

回答

-1

你必须发送命令给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 
+0

如何实现它的代码 – Oladapo

+0

现在Asterisk的AMI一直和它突然停止工作昨天。我不知道什么地方出了问题,但我注意到它需要花费很多时间才能连接并最终产生一个502坏的网关 – Oladapo

0

我刚打电话挂断方法,采取通道名作为参数。

我不知道有该

manager.hangup(通道)方法