Adhearsion’s RESTful Click2Call returns

Unfortunately, the Adhearsion restful_clicktocall component has been broken for some time. But fear not, we’ve fixed it up. After several posts to the mailing list reporting the issue, Mojo Lingo stepped up and sponsored getting things fixed. Both the restful_clicktocall component and the restful_adhearsion client gem are now official Adhearsion projects. Additionally, the restful_rpc example component shipped with Adhearsion has become ahn-restful-rpc, a separate component gem. The old example component will be removed in the next release of Adhearsion.

So, now that things are all rosy, how do we get things setup? First off, you’ll need a brand new Adhearsion 1.2 application:

{11:50}[ruby-1.9.2]~/Downloads ben% ahn create click2call
create
create components/simon_game
create components/disabled/stomp_gateway
create components/disabled/xmpp_gateway
create components/ami_remote
create components/disabled/restful_rpc/spec
create config
create script
create .ahnrc
create components/simon_game/simon_game.rb
create components/ami_remote/ami_remote.rb
create components/disabled/xmpp_gateway/xmpp_gateway.rb
create components/disabled/xmpp_gateway/xmpp_gateway.yml
create components/disabled/xmpp_gateway/README.markdown
create components/disabled/stomp_gateway/stomp_gateway.rb
create components/disabled/stomp_gateway/stomp_gateway.yml
create components/disabled/stomp_gateway/README.markdown
create components/disabled/restful_rpc/restful_rpc.rb
create components/disabled/restful_rpc/restful_rpc.yml
create components/disabled/restful_rpc/README.markdown
create components/disabled/restful_rpc/example-client.rb
create components/disabled/restful_rpc/spec/restful_rpc_spec.rb
create config/environment.rb
create config/startup.rb
create dialplan.rb
create events.rb
create README
create Rakefile
create Gemfile
create script/ahn

Next, you’ll need to ensure the old restful_rpc component is removed:

{11:53}[ruby-1.9.2]~/Downloads ben% cd click2call
{11:54}[ruby-1.9.2]~/Downloads/click2call ben% rm -r components/disabled/restful_rpc

Next up, the restful_clicktocall component:

{11:54}[ruby-1.9.2]~/Downloads/click2call ben% cd components
{11:55}[ruby-1.9.2]~/Downloads/click2call/components ben% git clone git://github.com/adhearsion/restful_clicktocall.git
Cloning into restful_clicktocall...
remote: Counting objects: 97, done.
remote: Compressing objects: 100% (60/60), done.
remote: Total 97 (delta 46), reused 84 (delta 33)
Receiving objects: 100% (97/97), 44.29 KiB, done.
Resolving deltas: 100% (46/46), done.

Now, we need to install the ahn-restful-rpc component which the clicktocall app depends on:

{11:55}[ruby-1.9.2]~/Downloads/click2call/components ben% cd ..
{11:55}[ruby-1.9.2]~/Downloads/click2call/components ben% echo "gem 'ahn-restful-rpc', :group => :components" >> Gemfile
{11:55}[ruby-1.9.2]~/Downloads/click2call/components ben% bundle install
Using rake (0.9.2)
Using activesupport (3.0.10)
Using bundler (1.0.15)
Using i18n (0.6.0)
Using json (1.5.3)
Using log4r (1.1.9)
Using coderay (0.9.8)
Using sexp_processor (3.0.6)
Using ruby_parser (2.2.0)
Using method_source (0.6.0)
Using slop (1.9.1)
Using pry (0.9.3)
Using rubigen (1.5.6)
Using adhearsion (1.2.0)
Using rack (1.3.2)
Using ahn-restful-rpc (0.1.1)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

You’ll also need to add the following line to startup.rb to enable the component:

config.add_component 'ahn-restful-rpc'

While you are in that file, make sure to enable the connection to Asterisk AMI as well by uncommenting the following line (and changing the username/password as appropriate):

config.asterisk.enable_ami :host => "127.0.0.1", :username => "admin", :password => "password", :events => true

And then generate the component config:

{12:01}[ruby-1.9.2]~/Downloads/click2call ben% rake components:genconfig
Installed default configuration for component ahn-restful-rpc

Once the first leg of your calls get into Adhearsion, you’ll need to pass them through. Add the following to your dialplan.rb:

adhearsion {
  call.variables[:destination] = get_variable("destination")
  dial call.variables[:destination]
}

You can now start Adhearsion:

{12:08}[ruby-1.9.2]~/Downloads/click2call ben% ahn -
[2011-08-26 12:09:18] INFO WEBrick 1.3.1
[2011-08-26 12:09:18] INFO ruby 1.9.2 (2011-07-09) [x86_64-darwin10.8.0]
INFO ahn: Adhearsion v1.2.0 initialized!
[2011-08-26 12:09:18] INFO WEBrick::HTTPServer#start: pid=8089 port=5000
INFO ami: Successful AMI actions-only connection into test@127.0.0.1
INFO ami: Successful AMI events-only connection into test@127.0.0.1
INFO agi: Adhearsion::VoIP::Asterisk::AGI::Server::RubyServer 0.0.0.0:4573 start

The last step is to get the web app up and running:

{12:09}[ruby-1.9.2]~/Downloads/click2call ben% cd components/restful_clicktocall/web
{12:09}[ruby-1.9.2]~/Downloads/click2call/components/restful_clicktocall/web@master ben% bundle install && bundle exec rackup
Fetching source index for http://rubygems.org/
Using json (1.5.3)
Using mime-types (1.16)
Using rack (1.3.2)
Using rest-client (1.6.7)
Installing restful_adhearsion (0.2.0)
Using tilt (1.3.3)
Using sinatra (1.2.6)
Using bundler (1.0.15)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
bundle install 47.40s user 0.59s system 95% cpu 50.370 total
[2011-08-26 12:11:01] INFO WEBrick 1.3.1
[2011-08-26 12:11:01] INFO ruby 1.9.2 (2011-07-09) [x86_64-darwin10.8.0]
[2011-08-26 12:11:01] INFO WEBrick::HTTPServer#start: pid=8307 port=9292

Now when you visit http://localhost:9292/, you’ll be able to make sweet click2call goodness, courtesy of Adhearsion.

Subscribe to our mailing list

* indicates required
I want to read about...
Email Format

4 thoughts on “Adhearsion’s RESTful Click2Call returns

What do you think?