Events

  • Events

    Adhearsion includes a flexible event handling system, and events may be handled either globally or per-call:

    Global events

    In order to handle events global to the whole system, one must declare a (potentially-guarded) handler. There are two methods by which this may be achieved:

    config/adhearsion.rb:

    Adhearsion::Events.draw do
    
      # eg. Handling Punchblock events
      # punchblock do |event|
      #   ...
      # end
      #
      # eg Handling PeerStatus AMI events
      # ami name: 'PeerStatus' do |event|
      #   ...
      # end
    
    end

    or, elsewhere in your code:

    # eg. Handling Punchblock events
    # Adhearsion::Events.punchblock do |event|
    #   ...
    # end

    The available categories of events are currently:

    • punchblock
    • ami
    • after_initialized
    • exception
    • stop_requested
    • shutdown

    Per-call events

    class MyController < Adhearsion::CallController
      before_call do
        call.register_event_handler do |event|
          ...
        end
      end
    end

    Guards

    The available guards are the same as those which apply in the Routing DSL, and are documented on the has-guarded-handlers wesbite.

    Back to Config Continue to Logging
blog comments powered by Disqus