DRY up Adhearsion Menus

15 views
Skip to first unread message

Justin Grammens

unread,
Jun 10, 2008, 5:27:51 PM6/10/08
to adhea...@googlegroups.com
I am using the new menu syntax in Adhearsion with my data model and am finding myself repeating the on_invalid, on_premature_timeout and on_failure calls in each block. Is there a way to have my on_invalid, on_premature_timeout and on_failure in each block call the same code? Looking for ways to DRY this up. Thanks for any advice.

For example in dialplan.rb:

adhearsion {
  menu 'productcode', :timeout => 8.seconds, :tries => 3 do |link|
        for product in Product.find(:all)
          link.product product.code
        end
       
        link.on_invalid { play 'invalid' }

        link.on_premature_timeout do |str|
          play 'sorry'
        end

        link.on_failure do
          play 'goodbye'
          hangup
        end
  end
}

product {
  menu 'vendorcode', :timeout => 5.seconds, :tries => 3 do |link|
      link.vendor 1

      link.on_invalid { play 'invalid' }

      link.on_premature_timeout do |str|
          play 'sorry'
      end

      link.on_failure do
          play 'goodbye'
          hangup
      end

  end
}

vendor {
    # do another menu here blah.. blah....
    link.on_invalid { play 'invalid' }

    link.on_premature_timeout do |str|
        play 'sorry'
    end

   link.on_failure do
        play 'goodbye'
        hangup
   end
}

Jay Phillips

unread,
Jun 10, 2008, 5:43:21 PM6/10/08
to adhea...@googlegroups.com
Hey Justin,

Sure, I can think of a few ways to do this. How about this:

Define this instance variable in the context entrypoint for your
application. I think "adhearsion" is your entrypoint in your example
so I'll use that.

adhearsion {
@mishap_handler = lambda do |link|
link.on_invalid { play 'invalid' }
link.on_premature_timeout { play 'sorry' }
link.on_failure { play 'goodbye' }
end

menu do |link|
@mishap_handler[link]
link.other_context 1
# Rest of menu here
end
}

other_context {
menu do |link|
@mishap_handler[link]
link.somewhere 1
end
}

Alternatively, you could create a custom dialplan command (dry_menu()
maybe?) that automatically ran those callbacks on the "link"
MenuBuilder object.

Jay Phillips

jan....@gmail.com

unread,
Jun 11, 2008, 4:43:57 AM6/11/08
to Adhearsion
How about defining a separate context, would that make sense?

link.on_premature_timeout do |str|
+on_timeout
end
}

on_timeout {
play 'sorry'
}

Works for me..

Jan

Jay Phillips

unread,
Jun 11, 2008, 4:48:38 AM6/11/08
to adhea...@googlegroups.com
Jan,

That'll work fine when :tries => 1. If you have multiple tries, it
won't continue trying once you've jumped to another context.

Jay Phillips

Justin Grammens

unread,
Jun 11, 2008, 11:34:36 AM6/11/08
to adhea...@googlegroups.com
This is exactly what I was looking for. Thanks Jay!

anthony waweru

unread,
Jul 4, 2008, 6:07:27 AM7/4/08
to adhea...@googlegroups.com
Hi yall,
I am trying to use adhearsion on elastix and i create something like

wyde{
play 'tt-monkeys'
}

then i define my context in extensions_custom.conf like
[wyde ]
exten 456,1,AGI(agi://174.78.99.20)


but i does not work. I appreciate yo help. thanks for you time.

Ahmed MICKY

unread,
Jul 4, 2008, 6:21:45 AM7/4/08
to adhea...@googlegroups.com
I am using this in my extension.conf(asterisk side ) and everything is ok.

asterisk side:

 [default]
 exten => _X.,1,AGI(agi://127.0.0.1) ; change this to the IP of the server running adhearsion    


adhearsion side:(dialplan.rb)

default {
play 'something'
}

i think you forgot the =>

good luck

Le 4 juil. 08 à 12:07, anthony waweru a écrit :

anthony waweru

unread,
Jul 4, 2008, 6:37:54 AM7/4/08
to adhea...@googlegroups.com
hi ahmend

I am using that in Elastix on the extensions_custom.conf but it
does not work at all
but with asterisk it does work with no problems.
how do i go about in Elastix, you got any clue for me, man i 'd appreciate .

thanks man for the response

cheers

Ahmed MICKY

unread,
Jul 4, 2008, 6:56:06 AM7/4/08
to adhea...@googlegroups.com
Sorry man, no idea.

good luck
Le 4 juil. 08 à 12:37, anthony waweru a écrit :

anthony waweru

unread,
Jul 4, 2008, 7:04:11 AM7/4/08
to adhea...@googlegroups.com
you havent' tried out Elastix have?

Ahmed MICKY

unread,
Jul 4, 2008, 7:15:25 AM7/4/08
to adhea...@googlegroups.com
no i did not. i just used adhearsion with Asterisk.
now i did a simple config to see if everything is working .
then i wil build a poject with it (but my big problem is to use ss7 trunking with Asterisk).
any experience with asterisk and ss7??

Le 4 juil. 08 à 13:04, anthony waweru a écrit :

anthony waweru

unread,
Jul 4, 2008, 7:36:09 AM7/4/08
to adhea...@googlegroups.com
man i haven't tried that out, but since you havre brought it up, why
not, i will let u know how it goes.

Ahmed MICKY

unread,
Jul 4, 2008, 8:18:39 AM7/4/08
to adhea...@googlegroups.com
Thank you, if you have any information, i am verry interested.
i already read some docs about (libss7, openSS7,...) but these libraries are in beta development.
Th second possibility is to buy a non open source lib or built server like (sangoma's SMG gate way).
the third one is to  buy a sip/ss7 gateway (like teles ss7/sip gateway).
But the last two solutions are expensive for me.


Le 4 juil. 08 à 13:36, anthony waweru a écrit :

Reply all
Reply to author
Forward
0 new messages