Ruby AMI Event Catching

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Ruby AMI Event Catching

Rajat Saxena
Hi,

I am developing a simple application with Asterisk. When a new call is made from a softphone, I simply need to save the incoming caller id number.

I tried this in config/adhearsion.rb

Adhearsion::Events.draw do
    ami name
: 'Newstate' do |event|
        logger
.info "+++ WE HAVE A NEW CALL +++"
       
@callvar = calleridnum
        logger
.info "++++++++++++++++++++++++++++++++++"
   
end
end

A 'Newstate' event is generated when a new call is received.

This is the snippet from Adhearsion console

[2014-09-17 11:30:46] TRACE Punchblock::Connection::Asterisk: [RECV] #<RubyAMI::Event name="Newstate", headers={"Privilege"=>"call,all", "Channel"=>"SIP/6001-0000002c", "ChannelState"=>"4", "ChannelStateDesc"=>"Ring", "CallerIDNum"=>"6001", "CallerIDName"=>"Rajat Saxena", "ConnectedLineNum"=>"", "ConnectedLineName"=>"", "Uniqueid"=>"1410933646.44"}, text_body=nil, events=[]>

[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 11:30:48] INFO  Adhearsion::Events: a873baf9-5644-4455-aa95-d22c15bd1c3b
[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++++++++++++++++++++++++++++++++

When I try
@callvar = headers[:CallerIdNum]

I get an error
<TypeError> can't convert Symbol into Integer

Is there a different or better method to store the Caller ID and pass it to the controller?

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Ben Langfeld-2
event.headers['CallerIDNum']

or

event['CallerIDNum']

for short.

A symbol was inappropriate because the hash printed clearly shows string keys. Using `calleridnum` and `headers` were inappropriate because you had not defined these anywhere. The only variable you have defined is `event`.

Furthermore, I'm absolutely certain you want a local variable here, not an instance variable of the event handler ;)

On 17 September 2014 03:06, Rajat Saxena <[hidden email]> wrote:
Hi,

I am developing a simple application with Asterisk. When a new call is made from a softphone, I simply need to save the incoming caller id number.

I tried this in config/adhearsion.rb

Adhearsion::Events.draw do
    ami name
: 'Newstate' do |event|
        logger
.info "+++ WE HAVE A NEW CALL +++"
       
@callvar = calleridnum
        logger
.info "++++++++++++++++++++++++++++++++++"
   
end
end

A 'Newstate' event is generated when a new call is received.

This is the snippet from Adhearsion console

[2014-09-17 11:30:46] TRACE Punchblock::Connection::Asterisk: [RECV] #<RubyAMI::Event name="Newstate", headers={"Privilege"=>"call,all", "Channel"=>"SIP/6001-0000002c", "ChannelState"=>"4", "ChannelStateDesc"=>"Ring", "CallerIDNum"=>"6001", "CallerIDName"=>"Rajat Saxena", "ConnectedLineNum"=>"", "ConnectedLineName"=>"", "Uniqueid"=>"1410933646.44"}, text_body=nil, events=[]>

[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 11:30:48] INFO  Adhearsion::Events: a873baf9-5644-4455-aa95-d22c15bd1c3b
[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++++++++++++++++++++++++++++++++

When I try
@callvar = headers[:CallerIdNum]

I get an error
<TypeError> can't convert Symbol into Integer

Is there a different or better method to store the Caller ID and pass it to the controller?

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Rajat Saxena
In reply to this post by Rajat Saxena
Hi,

I did

logger.info event['CallerIDNum']


This shows me a

<NilClass> nil

message in the console, no error though.

On Wednesday, September 17, 2014 11:36:12 AM UTC+5:30, Rajat Saxena wrote:
Hi,

I am developing a simple application with Asterisk. When a new call is made from a softphone, I simply need to save the incoming caller id number.

I tried this in config/adhearsion.rb

Adhearsion::Events.draw do
    ami name
: 'Newstate' do |event|
        logger
.info "+++ WE HAVE A NEW CALL +++"
       
@callvar = calleridnum
        logger
.info "++++++++++++++++++++++++++++++++++"
   
end
end

A 'Newstate' event is generated when a new call is received.

This is the snippet from Adhearsion console

[2014-09-17 11:30:46] TRACE Punchblock::Connection::Asterisk: [RECV] #<RubyAMI::Event name="Newstate", headers={"Privilege"=>"call,all", "Channel"=>"SIP/6001-0000002c", "ChannelState"=>"4", "ChannelStateDesc"=>"Ring", "CallerIDNum"=>"6001", "CallerIDName"=>"Rajat Saxena", "ConnectedLineNum"=>"", "ConnectedLineName"=>"", "Uniqueid"=>"1410933646.44"}, text_body=nil, events=[]>

[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 11:30:48] INFO  Adhearsion::Events: a873baf9-5644-4455-aa95-d22c15bd1c3b
[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++++++++++++++++++++++++++++++++

When I try
@callvar = headers[:CallerIdNum]

I get an error
<TypeError> can't convert Symbol into Integer

Is there a different or better method to store the Caller ID and pass it to the controller?

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Ben Langfeld-2
Please provide again the full code you're using and a full log.

On 17 September 2014 13:47, Rajat Saxena <[hidden email]> wrote:
Hi,

I did

logger.info event['CallerIDNum']


This shows me a

<NilClass> nil

message in the console, no error though.


On Wednesday, September 17, 2014 11:36:12 AM UTC+5:30, Rajat Saxena wrote:
Hi,

I am developing a simple application with Asterisk. When a new call is made from a softphone, I simply need to save the incoming caller id number.

I tried this in config/adhearsion.rb

Adhearsion::Events.draw do
    ami name
: 'Newstate' do |event|
        logger
.info "+++ WE HAVE A NEW CALL +++"
       
@callvar = calleridnum
        logger
.info "++++++++++++++++++++++++++++++++++"
   
end
end

A 'Newstate' event is generated when a new call is received.

This is the snippet from Adhearsion console

[2014-09-17 11:30:46] TRACE Punchblock::Connection::Asterisk: [RECV] #<RubyAMI::Event name="Newstate", headers={"Privilege"=>"call,all", "Channel"=>"SIP/6001-0000002c", "ChannelState"=>"4", "ChannelStateDesc"=>"Ring", "CallerIDNum"=>"6001", "CallerIDName"=>"Rajat Saxena", "ConnectedLineNum"=>"", "ConnectedLineName"=>"", "Uniqueid"=>"1410933646.44"}, text_body=nil, events=[]>

[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 11:30:48] INFO  Adhearsion::Events: a873baf9-5644-4455-aa95-d22c15bd1c3b
[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++++++++++++++++++++++++++++++++

When I try
@callvar = headers[:CallerIdNum]

I get an error
<TypeError> can't convert Symbol into Integer

Is there a different or better method to store the Caller ID and pass it to the controller?

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Rajat Saxena
This is config/adhearsion.rb

# encoding: utf-8

Adhearsion.config do |config|

 
# Centralized way to specify any Adhearsion platform or plugin configuration
 
# - Execute rake config:show to view the active configuration values
 
#
 
# To update a plugin configuration you can write either:
 
#
 
#    * Option 1
 
#        Adhearsion.config.<plugin-name> do |config|
 
#          config.<key> = <value>
 
#        end
 
#
 
#    * Option 2
 
#        Adhearsion.config do |config|
 
#          config.<plugin-name>.<key> = <value>
 
#        end

  config
.development do |dev|
    dev
.platform.logging.level = :debug

 
end

 
##
 
# Use with Rayo (eg Voxeo PRISM)
 
#
 
# config.punchblock.username = "" # Your XMPP JID for use with Rayo
 
# config.punchblock.password = "" # Your XMPP password

 
##
 
# Use with Asterisk
 
#
   config
.punchblock.platform = :asterisk # Use Asterisk
   config
.punchblock.username = "6001" # Your AMI username
   config
.punchblock.password = "unsecurepassword" # Your AMI password
   config
.punchblock.host = "127.0.0.1" # Your AMI host

 
##
 
# Use with FreeSWITCH
 
#
 
# config.punchblock.platform = :freeswitch # Use FreeSWITCH
 
# config.punchblock.password = "" # Your Inbound EventSocket password
 
# config.punchblock.host = "127.0.0.1" # Your IES host
end

Adhearsion::Events.draw do


    ami name
: 'Newchannel' do |event|
        callvar
= event['CALLERID(num)']
        logger
.info "+++ WE HAVE A NEW CHANNEL +++"
        logger
.info callvar
        logger
.info "++++++++++++++++++++++++++++++++++"
 
end

 
# Register global handlers for events
 
#
 
# eg. Handling Punchblock events
 
# punchblock do |event|
 
#   ...
 
# end
 
#
 
# eg Handling PeerStatus AMI events
 
# ami :name => 'PeerStatus' do |event|
 
#   ...
 
# end
 
#
end

Adhearsion.router do

 
#
 
# Specify your call routes, directing calls with particular attributes to a controller
 
#

  route
'default', SimonGame
end

This is the Adhearsion console.

rajat@RajatSaxena:~/Documents/Ruby193/bin/demoapp3$ ahn -
Starting Adhearsion server at /home/rajat/Documents/Ruby193/bin/demoapp3
[2014-09-17 23:29:13] INFO  Adhearsion::Initializer: Setting RAILS_ENV to "development"
[2014-09-17 23:29:13] INFO  Adhearsion::Rails::Plugin::Service: Rails loaded
[2014-09-17 23:29:13] INFO  Adhearsion::Drb::Service: Starting DRb on localhost:9050
[2014-09-17 23:29:13] INFO  Adhearsion::Drb::Service: DRB Started on druby://localhost:9050
[2014-09-17 23:29:13] DEBUG Punchblock::Connection::Asterisk: Starting up...
[2014-09-17 23:29:13] INFO  Adhearsion::PunchblockPlugin::Initializer: Starting connection to server
[2014-09-17 23:29:13] INFO  Adhearsion::PunchblockPlugin::Initializer: Connected to Punchblock server
[2014-09-17 23:29:13] INFO  Adhearsion::Process: Transitioning from booting to running with 0 active calls due to booted event.
[2014-09-17 23:29:13] INFO  Adhearsion::Initializer: Adhearsion v2.1.0 initialized in "development"!
[2014-09-17 23:29:13] INFO  Adhearsion::Console: Launching Adhearsion Console
AHN
> [2014-09-17 23:29:21] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 23:29:21] INFO  Adhearsion::Events: <NilClass> nil
[2014-09-17 23:29:21] INFO  Adhearsion::Events: ++++++++++++++++++++++++++++++++++




On Wednesday, September 17, 2014 10:54:28 PM UTC+5:30, Ben Langfeld wrote:
Please provide again the full code you're using and a full log.

On 17 September 2014 13:47, Rajat Saxena <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="1dqglF80fPcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">rajats...@...> wrote:
Hi,

I did

logger.info event['CallerIDNum']


This shows me a

<NilClass> nil

message in the console, no error though.


On Wednesday, September 17, 2014 11:36:12 AM UTC+5:30, Rajat Saxena wrote:
Hi,

I am developing a simple application with Asterisk. When a new call is made from a softphone, I simply need to save the incoming caller id number.

I tried this in config/adhearsion.rb

Adhearsion::Events.draw do
    ami name
: 'Newstate' do |event|
        logger
.info "+++ WE HAVE A NEW CALL +++"
       
@callvar = calleridnum
        logger
.info "++++++++++++++++++++++++++++++++++"
   
end
end

A 'Newstate' event is generated when a new call is received.

This is the snippet from Adhearsion console

[2014-09-17 11:30:46] TRACE Punchblock::Connection::Asterisk: [RECV] #<RubyAMI::Event name="Newstate", headers={"Privilege"=>"call,all", "Channel"=>"SIP/6001-0000002c", "ChannelState"=>"4", "ChannelStateDesc"=>"Ring", "CallerIDNum"=>"6001", "CallerIDName"=>"Rajat Saxena", "ConnectedLineNum"=>"", "ConnectedLineName"=>"", "Uniqueid"=>"1410933646.44"}, text_body=nil, events=[]>

[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 11:30:48] INFO  Adhearsion::Events: a873baf9-5644-4455-aa95-d22c15bd1c3b
[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++++++++++++++++++++++++++++++++

When I try
@callvar = headers[:CallerIdNum]

I get an error
<TypeError> can't convert Symbol into Integer

Is there a different or better method to store the Caller ID and pass it to the controller?

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="1dqglF80fPcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">adhearsion+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Ben Klang-2
This code shows event[‘CALLERID(num)’] which isn’t valid.  The event headers that come from AMI do not behave like extensions.conf.  Please try 

event.headers[‘CallerIDNum’]

You can inspect the entire set by doing something like

logger.info “Received headers: #{event.headers.inspect}"

/BAK/
-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
Twitter: @MojoLingo

Il giorno Sep 17, 2014, alle ore 2:00 PM, Rajat Saxena <[hidden email]> ha scritto:

This is config/adhearsion.rb

# encoding: utf-8

Adhearsion.config do |config|

  # Centralized way to specify any Adhearsion platform or plugin configuration
  # - Execute rake config:show to view the active configuration values
  #
  # To update a plugin configuration you can write either:
  #
  #    * Option 1
  #        Adhearsion.config.<plugin-name> do |config|
  #          config.<key> = <value>
  #        end
  #
  #    * Option 2
  #        Adhearsion.config do |config|
  #          config.<plugin-name>.<key> = <value>
  #        end

  config.development do |dev|
    dev.platform.logging.level = :debug

  end

  ##
  # Use with Rayo (eg Voxeo PRISM)
  #
  # config.punchblock.username = "" # Your XMPP JID for use with Rayo
  # config.punchblock.password = "" # Your XMPP password

  ##
  # Use with Asterisk
  #
   config.punchblock.platform = :asterisk # Use Asterisk
   config.punchblock.username = "6001" # Your AMI username
   config.punchblock.password = "unsecurepassword" # Your AMI password
   config.punchblock.host = "127.0.0.1" # Your AMI host

  ##
  # Use with FreeSWITCH
  #
  # config.punchblock.platform = :freeswitch # Use FreeSWITCH
  # config.punchblock.password = "" # Your Inbound EventSocket password
  # config.punchblock.host = "127.0.0.1" # Your IES host
end

Adhearsion::Events.draw do


    ami name: 'Newchannel' do |event|
        callvar = event['CALLERID(num)']
        logger.info "+++ WE HAVE A NEW CHANNEL +++"
        logger.info callvar
        logger.info "++++++++++++++++++++++++++++++++++"
  end

  # Register global handlers for events
  #
  # eg. Handling Punchblock events
  # punchblock do |event|
  #   ...
  # end
  #
  # eg Handling PeerStatus AMI events
  # ami :name => 'PeerStatus' do |event|
  #   ...
  # end
  #
end

Adhearsion.router do

  #
  # Specify your call routes, directing calls with particular attributes to a controller
  #

  route 'default', SimonGame
end

This is the Adhearsion console.

rajat@RajatSaxena:~/Documents/Ruby193/bin/demoapp3$ ahn -
Starting Adhearsion server at /home/rajat/Documents/Ruby193/bin/demoapp3
[2014-09-17 23:29:13] INFO  Adhearsion::Initializer: Setting RAILS_ENV to "development"
[2014-09-17 23:29:13] INFO  Adhearsion::Rails::Plugin::Service: Rails loaded
[2014-09-17 23:29:13] INFO  Adhearsion::Drb::Service: Starting DRb on localhost:9050
[2014-09-17 23:29:13] INFO  Adhearsion::Drb::Service: DRB Started on druby://localhost:9050
[2014-09-17 23:29:13] DEBUG Punchblock::Connection::Asterisk: Starting up...
[2014-09-17 23:29:13] INFO  Adhearsion::PunchblockPlugin::Initializer: Starting connection to server
[2014-09-17 23:29:13] INFO  Adhearsion::PunchblockPlugin::Initializer: Connected to Punchblock server
[2014-09-17 23:29:13] INFO  Adhearsion::Process: Transitioning from booting to running with 0 active calls due to booted event.
[2014-09-17 23:29:13] INFO  Adhearsion::Initializer: Adhearsion v2.1.0 initialized in "development"!
[2014-09-17 23:29:13] INFO  Adhearsion::Console: Launching Adhearsion Console
AHN> [2014-09-17 23:29:21] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 23:29:21] INFO  Adhearsion::Events: <NilClass> nil
[2014-09-17 23:29:21] INFO  Adhearsion::Events: ++++++++++++++++++++++++++++++++++




On Wednesday, September 17, 2014 10:54:28 PM UTC+5:30, Ben Langfeld wrote:
Please provide again the full code you're using and a full log.

On 17 September 2014 13:47, Rajat Saxena <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="1dqglF80fPcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">rajats...@...> wrote:
Hi,

I did

logger.info event['CallerIDNum']


This shows me a

<NilClass> nil

message in the console, no error though.


On Wednesday, September 17, 2014 11:36:12 AM UTC+5:30, Rajat Saxena wrote:
Hi,

I am developing a simple application with Asterisk. When a new call is made from a softphone, I simply need to save the incoming caller id number.

I tried this in config/adhearsion.rb

Adhearsion::Events.draw do
    ami name: 'Newstate' do |event|
        logger.info "+++ WE HAVE A NEW CALL +++"
        @callvar = calleridnum
        logger.info "++++++++++++++++++++++++++++++++++"
    end
end

A 'Newstate' event is generated when a new call is received.

This is the snippet from Adhearsion console

[2014-09-17 11:30:46] TRACE Punchblock::Connection::Asterisk: [RECV] #<RubyAMI::Event name="Newstate", headers={"Privilege"=>"call,all", "Channel"=>"SIP/6001-0000002c", "ChannelState"=>"4", "ChannelStateDesc"=>"Ring", "CallerIDNum"=>"6001", "CallerIDName"=>"Rajat Saxena", "ConnectedLineNum"=>"", "ConnectedLineName"=>"", "Uniqueid"=>"1410933646.44"}, text_body=nil, events=[]>

[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 11:30:48] INFO  Adhearsion::Events: a873baf9-5644-4455-aa95-d22c15bd1c3b
[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++++++++++++++++++++++++++++++++

When I try
@callvar = headers[:CallerIdNum]

I get an error
<TypeError> can't convert Symbol into Integer

Is there a different or better method to store the Caller ID and pass it to the controller?


--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="1dqglF80fPcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">adhearsion+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


signature.asc (858 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Rajat Saxena
I made that change in the event because event.headers['CallerIDNum'] gives an error in the console.

<NoMethodError> undefined method `headers' for #<Punchblock::Event::Asterisk::AMI::Event:0x00000001c3bb48>




On Wednesday, September 17, 2014 11:33:20 PM UTC+5:30, Ben Klang wrote:
This code shows event[‘CALLERID(num)’] which isn’t valid.  The event headers that come from AMI do not behave like extensions.conf.  Please try 

event.headers[‘CallerIDNum’]

You can inspect the entire set by doing something like

<a href="http://logger.info" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flogger.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGOfWV_MqSEYOUyz77vBSYyM6smOg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flogger.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGOfWV_MqSEYOUyz77vBSYyM6smOg';return true;">logger.info “Received headers: #{event.headers.inspect}"

/BAK/
-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="b6uGAuitlKsJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">bkl...@...
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
<a href="http://mojolingo.com/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fmojolingo.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEdz1VI9Wu7PPmqtzifmF6XsODIog';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fmojolingo.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEdz1VI9Wu7PPmqtzifmF6XsODIog';return true;">http://mojolingo.com
Twitter: @MojoLingo

Il giorno Sep 17, 2014, alle ore 2:00 PM, Rajat Saxena <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="b6uGAuitlKsJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">rajats...@...> ha scritto:

This is config/adhearsion.rb

# encoding: utf-8

Adhearsion.config do |config|

  # Centralized way to specify any Adhearsion platform or plugin configuration
  # - Execute rake config:show to view the active configuration values
  #
  # To update a plugin configuration you can write either:
  #
  #    * Option 1
  #        Adhearsion.config.<plugin-name> do |config|
  #          config.<key> = <value>
  #        end
  #
  #    * Option 2
  #        Adhearsion.config do |config|
  #          config.<plugin-name>.<key> = <value>
  #        end

  config.development do |dev|
    dev.platform.logging.level = :debug

  end

  ##
  # Use with Rayo (eg Voxeo PRISM)
  #
  # config.punchblock.username = "" # Your XMPP JID for use with Rayo
  # config.punchblock.password = "" # Your XMPP password

  ##
  # Use with Asterisk
  #
   config.punchblock.platform = :asterisk # Use Asterisk
   config.punchblock.username = "6001" # Your AMI username
   config.punchblock.password = "unsecurepassword" # Your AMI password
   config.punchblock.host = "127.0.0.1" # Your AMI host

  ##
  # Use with FreeSWITCH
  #
  # config.punchblock.platform = :freeswitch # Use FreeSWITCH
  # config.punchblock.password = "" # Your Inbound EventSocket password
  # config.punchblock.host = "127.0.0.1" # Your IES host
end

Adhearsion::Events.draw do


    ami name: 'Newchannel' do |event|
        callvar = event['CALLERID(num)']
        logger.info "+++ WE HAVE A NEW CHANNEL +++"
        logger.info callvar
        logger.info "++++++++++++++++++++++++++++++++++"
  end

  # Register global handlers for events
  #
  # eg. Handling Punchblock events
  # punchblock do |event|
  #   ...
  # end
  #
  # eg Handling PeerStatus AMI events
  # ami :name => 'PeerStatus' do |event|
  #   ...
  # end
  #
end

Adhearsion.router do

  #
  # Specify your call routes, directing calls with particular attributes to a controller
  #

  route 'default', SimonGame
end

This is the Adhearsion console.

rajat@RajatSaxena:~/Documents/Ruby193/bin/demoapp3$ ahn -
Starting Adhearsion server at /home/rajat/Documents/Ruby193/bin/demoapp3
[2014-09-17 23:29:13] INFO  Adhearsion::Initializer: Setting RAILS_ENV to "development"
[2014-09-17 23:29:13] INFO  Adhearsion::Rails::Plugin::Service: Rails loaded
[2014-09-17 23:29:13] INFO  Adhearsion::Drb::Service: Starting DRb on localhost:9050
[2014-09-17 23:29:13] INFO  Adhearsion::Drb::Service: DRB Started on druby://localhost:9050
[2014-09-17 23:29:13] DEBUG Punchblock::Connection::Asterisk: Starting up...
[2014-09-17 23:29:13] INFO  Adhearsion::PunchblockPlugin::Initializer: Starting connection to server
[2014-09-17 23:29:13] INFO  Adhearsion::PunchblockPlugin::Initializer: Connected to Punchblock server
[2014-09-17 23:29:13] INFO  Adhearsion::Process: Transitioning from booting to running with 0 active calls due to booted event.
[2014-09-17 23:29:13] INFO  Adhearsion::Initializer: Adhearsion v2.1.0 initialized in "development"!
[2014-09-17 23:29:13] INFO  Adhearsion::Console: Launching Adhearsion Console
AHN> [2014-09-17 23:29:21] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 23:29:21] INFO  Adhearsion::Events: <NilClass> nil
[2014-09-17 23:29:21] INFO  Adhearsion::Events: ++++++++++++++++++++++++++++++++++




On Wednesday, September 17, 2014 10:54:28 PM UTC+5:30, Ben Langfeld wrote:
Please provide again the full code you're using and a full log.

On 17 September 2014 13:47, Rajat Saxena <[hidden email]> wrote:
Hi,

I did

logger.info event['CallerIDNum']


This shows me a

<NilClass> nil

message in the console, no error though.


On Wednesday, September 17, 2014 11:36:12 AM UTC+5:30, Rajat Saxena wrote:
Hi,

I am developing a simple application with Asterisk. When a new call is made from a softphone, I simply need to save the incoming caller id number.

I tried this in config/adhearsion.rb

Adhearsion::Events.draw do
    ami name: 'Newstate' do |event|
        logger.info "+++ WE HAVE A NEW CALL +++"
        @callvar = calleridnum
        logger.info "++++++++++++++++++++++++++++++++++"
    end
end

A 'Newstate' event is generated when a new call is received.

This is the snippet from Adhearsion console

[2014-09-17 11:30:46] TRACE Punchblock::Connection::Asterisk: [RECV] #<RubyAMI::Event name="Newstate", headers={"Privilege"=>"call,all", "Channel"=>"SIP/6001-0000002c", "ChannelState"=>"4", "ChannelStateDesc"=>"Ring", "CallerIDNum"=>"6001", "CallerIDName"=>"Rajat Saxena", "ConnectedLineNum"=>"", "ConnectedLineName"=>"", "Uniqueid"=>"1410933646.44"}, text_body=nil, events=[]>

[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 11:30:48] INFO  Adhearsion::Events: a873baf9-5644-4455-aa95-d22c15bd1c3b
[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++++++++++++++++++++++++++++++++

When I try
@callvar = headers[:CallerIdNum]

I get an error
<TypeError> can't convert Symbol into Integer

Is there a different or better method to store the Caller ID and pass it to the controller?


--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="1dqglF80fPcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';retu
...

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Ben Klang-2
I just tested the following code and it worked perfectly for me:

Adhearsion::Events.draw do
  ami name: 'Newchannel' do |event|
    callvar = event.headers['CallerIDNum']
    logger.info "+++ WE HAVE A NEW CHANNEL +++"
    logger.info callvar
    logger.info "++++++++++++++++++++++++++++++++++"
  end
end


Output:

[2014-09-17 14:18:26.877] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 14:18:26.877] INFO  Adhearsion::Events: usera
[2014-09-17 14:18:26.877] INFO  Adhearsion::Events: ++++++++++++++++++++++++++++++++++
-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
Twitter: @MojoLingo

Il giorno Sep 17, 2014, alle ore 2:12 PM, Rajat Saxena <[hidden email]> ha scritto:

I made that change in the event because event.headers['CallerIDNum'] gives an error in the console.

<NoMethodError> undefined method `headers' for #<Punchblock::Event::Asterisk::AMI::Event:0x00000001c3bb48>




On Wednesday, September 17, 2014 11:33:20 PM UTC+5:30, Ben Klang wrote:
This code shows event[‘CALLERID(num)’] which isn’t valid.  The event headers that come from AMI do not behave like extensions.conf.  Please try 

event.headers[‘CallerIDNum’]

You can inspect the entire set by doing something like

<a href="http://logger.info/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flogger.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGOfWV_MqSEYOUyz77vBSYyM6smOg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flogger.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGOfWV_MqSEYOUyz77vBSYyM6smOg';return true;">logger.info “Received headers: #{event.headers.inspect}"

/BAK/
-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="b6uGAuitlKsJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">bkl...@...
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
<a href="http://mojolingo.com/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fmojolingo.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEdz1VI9Wu7PPmqtzifmF6XsODIog';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fmojolingo.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEdz1VI9Wu7PPmqtzifmF6XsODIog';return true;">http://mojolingo.com
Twitter: @MojoLingo

Il giorno Sep 17, 2014, alle ore 2:00 PM, Rajat Saxena <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="b6uGAuitlKsJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">rajats...@...> ha scritto:

This is config/adhearsion.rb

# encoding: utf-8

Adhearsion.config do |config|

  # Centralized way to specify any Adhearsion platform or plugin configuration
  # - Execute rake config:show to view the active configuration values
  #
  # To update a plugin configuration you can write either:
  #
  #    * Option 1
  #        Adhearsion.config.<plugin-name> do |config|
  #          config.<key> = <value>
  #        end
  #
  #    * Option 2
  #        Adhearsion.config do |config|
  #          config.<plugin-name>.<key> = <value>
  #        end

  config.development do |dev|
    dev.platform.logging.level = :debug

  end

  ##
  # Use with Rayo (eg Voxeo PRISM)
  #
  # config.punchblock.username = "" # Your XMPP JID for use with Rayo
  # config.punchblock.password = "" # Your XMPP password

  ##
  # Use with Asterisk
  #
   config.punchblock.platform = :asterisk # Use Asterisk
   config.punchblock.username = "6001" # Your AMI username
   config.punchblock.password = "unsecurepassword" # Your AMI password
   config.punchblock.host = "127.0.0.1" # Your AMI host

  ##
  # Use with FreeSWITCH
  #
  # config.punchblock.platform = :freeswitch # Use FreeSWITCH
  # config.punchblock.password = "" # Your Inbound EventSocket password
  # config.punchblock.host = "127.0.0.1" # Your IES host
end

Adhearsion::Events.draw do


    ami name: 'Newchannel' do |event|
        callvar = event['CALLERID(num)']
        logger.info "+++ WE HAVE A NEW CHANNEL +++"
        logger.info callvar
        logger.info "++++++++++++++++++++++++++++++++++"
  end

  # Register global handlers for events
  #
  # eg. Handling Punchblock events
  # punchblock do |event|
  #   ...
  # end
  #
  # eg Handling PeerStatus AMI events
  # ami :name => 'PeerStatus' do |event|
  #   ...
  # end
  #
end

Adhearsion.router do

  #
  # Specify your call routes, directing calls with particular attributes to a controller
  #

  route 'default', SimonGame
end

This is the Adhearsion console.

rajat@RajatSaxena:~/Documents/Ruby193/bin/demoapp3$ ahn -
Starting Adhearsion server at /home/rajat/Documents/Ruby193/bin/demoapp3
[2014-09-17 23:29:13] INFO  Adhearsion::Initializer: Setting RAILS_ENV to "development"
[2014-09-17 23:29:13] INFO  Adhearsion::Rails::Plugin::Service: Rails loaded
[2014-09-17 23:29:13] INFO  Adhearsion::Drb::Service: Starting DRb on localhost:9050
[2014-09-17 23:29:13] INFO  Adhearsion::Drb::Service: DRB Started on druby://localhost:9050
[2014-09-17 23:29:13] DEBUG Punchblock::Connection::Asterisk: Starting up...
[2014-09-17 23:29:13] INFO  Adhearsion::PunchblockPlugin::Initializer: Starting connection to server
[2014-09-17 23:29:13] INFO  Adhearsion::PunchblockPlugin::Initializer: Connected to Punchblock server
[2014-09-17 23:29:13] INFO  Adhearsion::Process: Transitioning from booting to running with 0 active calls due to booted event.
[2014-09-17 23:29:13] INFO  Adhearsion::Initializer: Adhearsion v2.1.0 initialized in "development"!
[2014-09-17 23:29:13] INFO  Adhearsion::Console: Launching Adhearsion Console
AHN> [2014-09-17 23:29:21] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 23:29:21] INFO  Adhearsion::Events: <NilClass> nil
[2014-09-17 23:29:21] INFO  Adhearsion::Events: ++++++++++++++++++++++++++++++++++




On Wednesday, September 17, 2014 10:54:28 PM UTC+5:30, Ben Langfeld wrote:
Please provide again the full code you're using and a full log.

On 17 September 2014 13:47, Rajat Saxena <[hidden email]> wrote:
Hi,

I did

logger.info event['CallerIDNum']


This shows me a

<NilClass> nil

message in the console, no error though.


On Wednesday, September 17, 2014 11:36:12 AM UTC+5:30, Rajat Saxena wrote:
Hi,

I am developing a simple application with Asterisk. When a new call is made from a softphone, I simply need to save the incoming caller id number.

I tried this in config/adhearsion.rb

Adhearsion::Events.draw do
    ami name: 'Newstate' do |event|
        logger.info "+++ WE HAVE A NEW CALL +++"
        @callvar = calleridnum
        logger.info "++++++++++++++++++++++++++++++++++"
    end
end

A 'Newstate' event is generated when a new call is received.

This is the snippet from Adhearsion console

[2014-09-17 11:30:46] TRACE Punchblock::Connection::Asterisk: [RECV] #<RubyAMI::Event name="Newstate", headers={"Privilege"=>"call,all", "Channel"=>"SIP/6001-0000002c", "ChannelState"=>"4", "ChannelStateDesc"=>"Ring", "CallerIDNum"=>"6001", "CallerIDName"=>"Rajat Saxena", "ConnectedLineNum"=>"", "ConnectedLineName"=>"", "Uniqueid"=>"1410933646.44"}, text_body=nil, events=[]>

[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 11:30:48] INFO  Adhearsion::Events: a873baf9-5644-4455-aa95-d22c15bd1c3b
[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++++++++++++++++++++++++++++++++

When I try
@callvar = headers[:CallerIdNum]

I get an error
<TypeError> can't convert Symbol into Integer

Is there a different or better method to store the Caller ID and pass it to the controller?


--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="1dqglF80fPcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';retu
...

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


signature.asc (858 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Rajat Saxena
But I am still getting the same error :/

[2014-09-17 23:55:31] ERROR Adhearsion::Initializer: <NoMethodError> undefined method `headers' for #<Punchblock::Event::Asterisk::AMI::Event:0x000000021f3a18>

On Wednesday, September 17, 2014 11:49:43 PM UTC+5:30, Ben Klang wrote:
I just tested the following code and it worked perfectly for me:

Adhearsion::Events.draw do
  ami name: 'Newchannel' do |event|
    callvar = event.headers['CallerIDNum']
    <a href="http://logger.info" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flogger.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGOfWV_MqSEYOUyz77vBSYyM6smOg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flogger.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGOfWV_MqSEYOUyz77vBSYyM6smOg';return true;">logger.info "+++ WE HAVE A NEW CHANNEL +++"
    <a href="http://logger.info" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flogger.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGOfWV_MqSEYOUyz77vBSYyM6smOg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flogger.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGOfWV_MqSEYOUyz77vBSYyM6smOg';return true;">logger.info callvar
    <a href="http://logger.info" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flogger.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGOfWV_MqSEYOUyz77vBSYyM6smOg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flogger.info\46sa\75D\46sntz\0751\46usg\75AFQjCNGOfWV_MqSEYOUyz77vBSYyM6smOg';return true;">logger.info "++++++++++++++++++++++++++++++++++"
  end
end


Output:

[2014-09-17 14:18:26.877] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 14:18:26.877] INFO  Adhearsion::Events: usera
[2014-09-17 14:18:26.877] INFO  Adhearsion::Events: ++++++++++++++++++++++++++++++++++
-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="iG9smsz2uZUJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">bkl...@...
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
<a href="http://mojolingo.com/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fmojolingo.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEdz1VI9Wu7PPmqtzifmF6XsODIog';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fmojolingo.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEdz1VI9Wu7PPmqtzifmF6XsODIog';return true;">http://mojolingo.com
Twitter: @MojoLingo

Il giorno Sep 17, 2014, alle ore 2:12 PM, Rajat Saxena <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="iG9smsz2uZUJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">rajats...@...> ha scritto:

I made that change in the event because event.headers['CallerIDNum'] gives an error in the console.

<NoMethodError> undefined method `headers' for #<Punchblock::Event::Asterisk::AMI::Event:0x00000001c3bb48>




On Wednesday, September 17, 2014 11:33:20 PM UTC+5:30, Ben Klang wrote:
This code shows event[‘CALLERID(num)’] which isn’t valid.  The event headers that come from AMI do not behave like extensions.conf.  Please try 

event.headers[‘CallerIDNum’]

You can inspect the entire set by doing something like

<a href="http://logger.info/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flogger.info%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNFdDAv9pN9xxAuZivrUOpFt6Ilx5Q';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flogger.info%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNFdDAv9pN9xxAuZivrUOpFt6Ilx5Q';return true;">logger.info “Received headers: #{event.headers.inspect}"

/BAK/
-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
<a href="http://mojolingo.com/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fmojolingo.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEdz1VI9Wu7PPmqtzifmF6XsODIog';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fmojolingo.com%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNEdz1VI9Wu7PPmqtzifmF6XsODIog';return true;">http://mojolingo.com
Twitter: @MojoLingo

Il giorno Sep 17, 2014, alle ore 2:00 PM, Rajat Saxena <[hidden email]> ha scritto:

This is config/adhearsion.rb

# encoding: utf-8

Adhearsion.config do |config|

  # Centralized way to specify any Adhearsion platform or plugin configuration
  # - Execute rake config:show to view the active configuration values
  #
  # To update a plugin configuration you can write either:
  #
  #    * Option 1
  #        Adhearsion.config.<plugin-name> do |config|
  #          config.<key> = <value>
  #        end
  #
  #    * Option 2
  #        Adhearsion.config do |config|
  #          config.<plugin-name>.<key> = <value>
  #        end

  config.development do |dev|
    dev.platform.logging.level = :debug

  end

  ##
  # Use with Rayo (eg Voxeo PRISM)
  #
  # config.punchblock.username = "" # Your XMPP JID for use with Rayo
  # config.punchblock.password = "" # Your XMPP password

  ##
  # Use with Asterisk
  #
   config.punchblock.platform = :asterisk # Use Asterisk
   config.punchblock.username = "6001" # Your AMI username
   config.punchblock.password = "unsecurepassword" # Your AMI password
   config.punchblock.host = "127.0.0.1" # Your AMI host

  ##
  # Use with FreeSWITCH
  #
  # config.punchblock.platform = :freeswitch # Use FreeSWITCH
  # config.punchblock.password = "" # Your Inbound EventSocket password
  # config.punchblock.host = "127.0.0.1" # Your IES host
end

Adhearsion::Events.draw do


    ami name: 'Newchannel' do |event|
        callvar = event['CALLERID(num)']
        logger.info "+++ WE HAVE A NEW CHANNEL +++"
        logger.info callvar
        logger.info "++++++++++++++++++++++++++++++++++"
  end

  # Register global handlers for events
  #
  # eg. Handling Punchblock events
  # punchblock do |event|
  #   ...
  # end
  #
  # eg Handling PeerStatus AMI events
  # ami :name => 'PeerStatus' do |event|
  #   ...
  # end
  #
end

Adhearsion.router do

  #
  # Specify your call routes, directing calls with particular attributes to a controller
  #

  route 'default', SimonGame
end

This is the Adhearsion console.

rajat@RajatSaxena:~/Documents/Ruby193/bin/demoapp3$ ahn -
Starting Adhearsion server at /home/rajat/Documents/Ruby193/bin/demoapp3
[2014-09-17 23:29:13] INFO  Adhearsion::Initializer: Setting RAILS_ENV to "development"
[2014-09-17 23:29:13] INFO  Adhearsion::Rails::Plugin::Service: Rails loaded
[2014-09-17 23:29:13] INFO  Adhearsion::Drb::Service: Starting DRb on localhost:9050
[2014-09-17 23:29:13] INFO  Adhearsion::Drb::Service: DRB Started on druby://localhost:9050
[2014-09-17 23:29:13] DEBUG Punchblock::Connection::Asterisk: Starting up...
[2014-09-17 23:29:13] INFO  Adhearsion::PunchblockPlugin::Initializer: Starting connection to server
[2014-09-17 23:29:13] INFO  Adhearsion::PunchblockPlugin::Initializer: Connected to Punchblock server
[2014-09-17 23:29:13] INFO  Adhearsion::Process: Transitioning from booting to running with 0 active calls due to booted event.
[2014-09-17 23:29:13] INFO  Adhearsion::Initializer: Adhearsion v2.1.0 initialized in "development"!
[2014-09-17 23:29:13] INFO  Adhearsion::Console: Launching Adhearsion Console
AHN> [2014-09-17 23:29:21] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 23:29:21] INFO  Adhearsion::Events: <NilClass> nil
[2014-09-17 23:29:21] INFO  Adhearsion::Events: ++++++++++++++++++++++++++++++++++




On Wednesday, September 17, 2014 10:54:28 PM UTC+5:30, Ben Langfeld wrote:
Please provide again the full code you're using and a full log.

On 17 September 2014 13:47, Rajat Saxena <[hidden email]> wrote:
Hi,

I did

logger.info event['CallerIDNum']


This shows me a

<NilClass> nil

message in the console, no error though.


On Wednesday, September 17, 2014 11:36:12 AM UTC+5:30, Rajat Saxena wrote:
Hi,

I am developing a simple application with Asterisk. When a new call is made from a softphone, I simply need to save the incoming caller id number.

I tried this in config/adhearsion.rb

Adhearsion::Events.draw do
    ami name: 'Newstate' do |event|
        logger.info "+++ WE HAVE A NEW CALL +++"
        @callvar = calleridnum
        logger.info "++++++++++++++++++++++++++++++++++"
    end
end

A 'Newstate' event is generated when a new call is received.

This is the snippet from Adhearsion console

[2014-09-17 11:30:46] TRACE Punchblock::Connection::Asterisk: [RECV] #<RubyAMI::Event name="Newstate", headers={"Privilege"=>"call,all", "Channel"=>"SIP/6001-0000002c", "ChannelState"=>"4", "ChannelStateDesc"=>"Ring", "CallerIDNum"=>"6001", "CallerIDName"=>"Rajat Saxena", "ConnectedLineNum"=>"", "ConnectedLineName"=>"", "Uniqueid"=>"1410933646.44"}, text_body=nil, events=[]>

[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 11:30:48] INFO  Adhearsion::Events: a873baf9-5644-4455-aa95-d22c15bd1c3b
[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++++++++++++++++++++++++++++++++

When I try
@callvar = headers[:CallerIdNum]

I get an error
<TypeError> can't convert Symbol into Integer

Is there a different or better method to store the Caller ID and pass it to the controller?


--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="1dqglF80fPcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';retu
...

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="iG9smsz2uZUJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">adhearsion+...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Ben Klang-2
That is indeed strange.  So we can continue troubleshooting, please put all of the following into a gist (https://gist.github.com):

* config/adhearsion.rb
* Gemfile
* Gemfile.lock
* Full TRACE logs from the point where Adhearsion starts up

Please make sure all these files are untouched so that they exactly match the logs.

/BAK/
-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
Twitter: @MojoLingo

Il giorno Sep 17, 2014, alle ore 2:26 PM, Rajat Saxena <[hidden email]> ha scritto:

But I am still getting the same error :/

[2014-09-17 23:55:31] ERROR Adhearsion::Initializer: <NoMethodError> undefined method `headers' for #<Punchblock::Event::Asterisk::AMI::Event:0x000000021f3a18>

On Wednesday, September 17, 2014 11:49:43 PM UTC+5:30, Ben Klang wrote:
I just tested the following code and it worked perfectly for me:

Adhearsion::Events.draw do
  ami name: 'Newchannel' do |event|
    callvar = event.headers['CallerIDNum']
    logger.info "+++ WE HAVE A NEW CHANNEL +++"
    logger.info callvar
    logger.info "++++++++++++++++++++++++++++++++++"
  end
end


Output:

[2014-09-17 14:18:26.877] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 14:18:26.877] INFO  Adhearsion::Events: usera
[2014-09-17 14:18:26.877] INFO  Adhearsion::Events: ++++++++++++++++++++++++++++++++++
-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
Twitter: @MojoLingo

Il giorno Sep 17, 2014, alle ore 2:12 PM, Rajat Saxena <rajats...@gmail.com> ha scritto:

I made that change in the event because event.headers['CallerIDNum'] gives an error in the console.

<NoMethodError> undefined method `headers' for #<Punchblock::Event::Asterisk::AMI::Event:0x00000001c3bb48>




On Wednesday, September 17, 2014 11:33:20 PM UTC+5:30, Ben Klang wrote:
This code shows event[‘CALLERID(num)’] which isn’t valid.  The event headers that come from AMI do not behave like extensions.conf.  Please try 

event.headers[‘CallerIDNum’]

You can inspect the entire set by doing something like

logger.info “Received headers: #{event.headers.inspect}"

/BAK/
-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
Twitter: @MojoLingo

Il giorno Sep 17, 2014, alle ore 2:00 PM, Rajat Saxena <[hidden email]> ha scritto:

This is config/adhearsion.rb

# encoding: utf-8

Adhearsion.config do |config|

  # Centralized way to specify any Adhearsion platform or plugin configuration
  # - Execute rake config:show to view the active configuration values
  #
  # To update a plugin configuration you can write either:
  #
  #    * Option 1
  #        Adhearsion.config.<plugin-name> do |config|
  #          config.<key> = <value>
  #        end
  #
  #    * Option 2
  #        Adhearsion.config do |config|
  #          config.<plugin-name>.<key> = <value>
  #        end

  config.development do |dev|
    dev.platform.logging.level = :debug

  end

  ##
  # Use with Rayo (eg Voxeo PRISM)
  #
  # config.punchblock.username = "" # Your XMPP JID for use with Rayo
  # config.punchblock.password = "" # Your XMPP password

  ##
  # Use with Asterisk
  #
   config.punchblock.platform = :asterisk # Use Asterisk
   config.punchblock.username = "6001" # Your AMI username
   config.punchblock.password = "unsecurepassword" # Your AMI password
   config.punchblock.host = "127.0.0.1" # Your AMI host

  ##
  # Use with FreeSWITCH
  #
  # config.punchblock.platform = :freeswitch # Use FreeSWITCH
  # config.punchblock.password = "" # Your Inbound EventSocket password
  # config.punchblock.host = "127.0.0.1" # Your IES host
end

Adhearsion::Events.draw do


    ami name: 'Newchannel' do |event|
        callvar = event['CALLERID(num)']
        logger.info "+++ WE HAVE A NEW CHANNEL +++"
        logger.info callvar
        logger.info "++++++++++++++++++++++++++++++++++"
  end

  # Register global handlers for events
  #
  # eg. Handling Punchblock events
  # punchblock do |event|
  #   ...
  # end
  #
  # eg Handling PeerStatus AMI events
  # ami :name => 'PeerStatus' do |event|
  #   ...
  # end
  #
end

Adhearsion.router do

  #
  # Specify your call routes, directing calls with particular attributes to a controller
  #

  route 'default', SimonGame
end

This is the Adhearsion console.

rajat@RajatSaxena:~/Documents/Ruby193/bin/demoapp3$ ahn -
Starting Adhearsion server at /home/rajat/Documents/Ruby193/bin/demoapp3
[2014-09-17 23:29:13] INFO  Adhearsion::Initializer: Setting RAILS_ENV to "development"
[2014-09-17 23:29:13] INFO  Adhearsion::Rails::Plugin::Service: Rails loaded
[2014-09-17 23:29:13] INFO  Adhearsion::Drb::Service: Starting DRb on localhost:9050
[2014-09-17 23:29:13] INFO  Adhearsion::Drb::Service: DRB Started on druby://localhost:9050
[2014-09-17 23:29:13] DEBUG Punchblock::Connection::Asterisk: Starting up...
[2014-09-17 23:29:13] INFO  Adhearsion::PunchblockPlugin::Initializer: Starting connection to server
[2014-09-17 23:29:13] INFO  Adhearsion::PunchblockPlugin::Initializer: Connected toPunchblock server
[2014-09-17 23:29:13] INFO  Adhearsion::Process: Transitioning from booting to running with0 active calls due to booted event.
[2014-09-17 23:29:13] INFO  Adhearsion::Initializer: Adhearsion v2.1.0 initialized in"development"!
[2014-09-17 23:29:13] INFO  Adhearsion::Console: Launching Adhearsion Console
AHN> [2014-09-17 23:29:21] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 23:29:21] INFO  Adhearsion::Events: <NilClass> nil
[2014-09-17 23:29:21] INFO  Adhearsion::Events: ++++++++++++++++++++++++++++++++++




On Wednesday, September 17, 2014 10:54:28 PM UTC+5:30, Ben Langfeld wrote:
Please provide again the full code you're using and a full log.

On 17 September 2014 13:47, Rajat Saxena <[hidden email]> wrote:
Hi,

I did

logger.info event['CallerIDNum']


This shows me a

<NilClass> nil

message in the console, no error though.


On Wednesday, September 17, 2014 11:36:12 AM UTC+5:30, Rajat Saxena wrote:
Hi,

I am developing a simple application with Asterisk. When a new call is made from a softphone, I simply need to save the incoming caller id number. 

I tried this in config/adhearsion.rb

Adhearsion::Events.draw do
    ami name: 'Newstate' do |event|
        logger.info "+++ WE HAVE A NEW CALL +++"
        @callvar = calleridnum
        logger.info "++++++++++++++++++++++++++++++++++"
    end
end

A 'Newstate' event is generated when a new call is received. 

This is the snippet from Adhearsion console

[2014-09-17 11:30:46] TRACE Punchblock::Connection::Asterisk: [RECV] #<RubyAMI::Event name="Newstate", headers={"Privilege"=>"call,all", "Channel"=>"SIP/6001-0000002c", "ChannelState"=>"4", "ChannelStateDesc"=>"Ring", "CallerIDNum"=>"6001", "CallerIDName"=>"Rajat Saxena", "ConnectedLineNum"=>"", "ConnectedLineName"=>"", "Uniqueid"=>"1410933646.44"}, text_body=nil, events=[]>

[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++ WE HAVE A NEW CHANNEL +++
[2014-09-17 11:30:48] INFO  Adhearsion::Events: a873baf9-5644-4455-aa95-d22c15bd1c3b
[2014-09-17 11:30:48] INFO  Adhearsion::Events: +++++++++++++++++++++++++++++++++

When I try
@callvar = headers[:CallerIdNum]

I get an error
<TypeError> can't convert Symbol into Integer

Is there a different or better method to store the Caller ID and pass it to the controller?


-- 
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="1dqglF80fPcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';retu
...

-- 
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adhearsion+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


signature.asc (858 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Rajat Saxena
Here you go.

https://gist.github.com/bd8f8868f1b2a5c34f9d.git

Thank you!

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Rajat Saxena
Perhaps that link is broken.

Try this :)
https://gist.github.com/Rajat-Saxena/bd8f8868f1b2a5c34f9d

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Ben Klang-2
Thanks, that shows the problem.  Your Gemfile is locked to Adhearsion 2.1, and your Gemfile.lock is pinned to Punchblock 1.9.4.  Those are both very old and are the cause of your problem.

Please change your Gemfile to read:

gem “adhearsion”, “~> 2.5”

And then run “bundle update”.  This will get the latest Adhearsion as well as Punchblock, and should resolve the issue.

/BAK/
-- 
Ben Klang
Principal/Technology Strategist, Mojo Lingo
+1.404.475.4841

Mojo Lingo -- Voice applications that work like magic
Twitter: @MojoLingo

Il giorno Sep 17, 2014, alle ore 2:56 PM, Rajat Saxena <[hidden email]> ha scritto:

Perhaps that link is broken.

Try this :)
https://gist.github.com/Rajat-Saxena/bd8f8868f1b2a5c34f9d

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


signature.asc (858 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Ruby AMI Event Catching

Rajat Saxena
It couldn't be any better. Thank you so much! :)

--
You received this message because you are subscribed to the Google Groups "Adhearsion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.