• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!


Using eventsrb

Page history last edited by jay@... 16 years ago

Using events.rb


If you've ever created an Adhearsion application, you've probably poked through the events.rb file that's included in the root directory by default. Though its usage case may be initially opaque, consider the following scenarios:


  • What if you want to perform an action when new Asterisk Manager Interface events occur?
  • What if you want to hook into the Asterisk bindings and perform some custom logic on each call when it comes in but before it's handed to the dialplan?
  • What if you want to need to initialize or cleanup resources when your Adhearsion initializes and shuts down?
  • What if you have an enterprise messaging bus which is constantly sends messages to your application?


The events.rb file and the DSL surrounding it was invented for this reason.


Anatomy of events.rb


The file is all pure-Ruby with a few user-friendly APIs exposed. You'll primarily need to register new event handlers with the following (example) syntax:

events.asterisk.before_call.each do |call|
ahn_log.dialplan "Handling call with " + call.variables.inspect
A few examples like this are included by default with the sample events.rb file.

Comments (0)

You don't have permission to comment on this page.