2016-09-27 55 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(通道)方法