1

我有一个 Rails 应用程序,我正在尝试通过 AMI 从我的星号获取实时事件。

我成功地创建了一个脚本来从 adhearsion 源代码发起调用,而无需创建新的 adhearsion 项目。

我创建了一个扩展 adhearsion 的 ManagerInterface 类并覆盖 event_message_received 方法的类。从 Rails CLI,如果有人打电话,我按 Enter 2 或 3 次,我得到了事件,但我必须干预才能得到它。

这是我的代码:

    class Astercall < Adhearsion::VoIP::Asterisk::Manager::ManagerInterface

  def initialize
    super(:host => "host", :username => "username", :password => "password", :events => true)
    connect!
  end




  def self.click_call(number, exten, name)
    # asterisk = connect()

    originate(:channel => "SIP/#{exten}", 
                        :context => "from-internal",
                        :exten => number,
                        :priority => "1",
                        :caller_id => "Calling  #{name}")
  end

  def event_message_received(event)
    if(event.kind_of? Adhearsion::VoIP::Asterisk::Manager::ManagerInterfaceEvent )
          puts event.inspect
    end
  end



end

我是否必须运行后台进程才能做到这一点。如果我这样做,我该怎么做????

提前致谢

4

1 回答 1

3

While it is possible to use the Adhearsion AMI classes outside of an Adhearsion app, it's not really a supported use. Part of what the Adhearsion app provides is the daemonization and eventing subsystems needed to help process the events received from Asterisk, neither of which is really necessary just for the origination as you were doing before. If you really insist on using the library outside of an Adhearsion app you will need to do more than just subclass the ManagerInterface. Just be careful: what you do not want to do (mostly for performance reasons) is to cause a new AMI connection to be created/torn down with each Rails web request.

I would strongly suggest that you use an Adhearsion app to process the events from AMI and then use something like DRb to handle communication between Rails and Adhearsion. This approach has worked very well for us in several situations where we needed Asterisk events to be accessible in Rails (for example, displaying call queue statistics).

于 2012-07-09T17:04:36.443 回答