Using Java Live API for sending DTMF

Hi,

I have an a java application which needs to send numeric pages using asterisk. I am using Asterisk 1.4.22 and Asterisk Java API 0.3.1

For this I have written the following code which (almost ) works.

AsteriskChannel asteriskChannel1 = asteriskServer.originateToApplication(
“DAHDI/g0/1235551212”,
“SendDtmf”,
“1234567890”,
10000);

The problem is the digits are being sent immediately on answer which result in some initial digits getting dropped.

We are suppose to wait for a beep and then send the digits.
The beep is coming after 5 to 10 secs.

I want to find out what is the best way to do this ??

Is it possible to wait to beep or detect a beep ?
OR
Wait for (say ) 10 secs

Appreciate your help and responses.
Thanks in advance.

Irfan

you have a couple of options here.

1 - you could send the call to a context in the dial plan which would have a Wait(5) before doing a SendDTMF call

2 - you could hand off control of the call to a FastAGI script… and seeing as you are already using Asterisk-Java, this would be pretty trivial.

Thanks for your response.

1 - you could send the call to a context in the dial plan which
would have a Wait(5) before doing a SendDTMF call

How do you extract the arguments passed when executing in the context of the dial plan, namely the digits to be sent ??

I don’t use the “live” components of the asterisk-java package. I manage the manager interaction at a slightly lower level… should translate well though.

One thing you are going to want to do is to utilize the Local channel feature built into asterisk. It gives you much more control over the progress of a call generated by a .call file or the AMI Originate.

voip-info.org/wiki/index.php … l+channels

Here is a little example with some variables generated in Java and accessed in asterisk:

OriginateAction dial = new OriginateAction();
dial.setChannel("Local/DIAL@my_context");
dial.setContext("my_context");
dial.setExten("ANSWER");
dial.setPriority(1);
dial.setAsync(true);
dial.setVariable("dial_string","DAHDI/g0/1235551212");
dial.setVariable("timeout","30");
dial.setVariable("post_dtmf","1234567890");

You would then need something similar in the asterisk dialplan to handle this:

[my_context]
exten => DIAL,1,Dial(${dial_string},${timeout})
exten => DIAL,n,Verbose(1,Dial failed with result ${DIALSTATUS})
exten => DIAL,n,Hangup()

exten => ANSWER,1,Verbose(1,Received an ANSWER)
exten => ANSWER,n,Wait(5) 
exten => ANSWER,n,SendDTMF(${post_dtmf})
exten => ANSWER,n,Hangup()

You could either do a regular Wait(X) or a WaitForSilence(X) depending on what the answering end is doing that you are waiting for.

Hope this helps.

p.s. nothing was tested, i just wrote it off the top of my head, so you may need to debug a bit :smile:

g2010,

Thanks a million, The sample code worked perfectly.
The party at the other end is a paging company sending a beep prompting
to enter the digits. I used the WaitForSilence(5) function.
I saw “Got 0 ms silence < 5 ms required” , What does it mean ? See log below.

Is there something like WaitForBeep(5) function ??? That would be nice!

Thanks and Regards,
Irfan

-- DAHDI/1-1 answered Local/DIAL@numeric_pager_context-d240,2
   > Channel Local/DIAL@numeric_pager_context-d240,1 was answered.
-- Executing [ANSWER@numeric_pager_context:1] Verbose("Local/DIAL@numeric_pager_context-d240,1", "1|Received an ANSWER") in new stack

Received an ANSWER
– Executing [ANSWER@numeric_pager_context:2] WaitForSilence(“Local/DIAL@numeric_pager_context-d240,1”, “5”) in new stack
– Waiting 1 time(s) for 5 ms silence with 0 timeout
– Got 0ms silence< 5ms required
– Got 0ms silence< 5ms required
– Got 0ms silence< 5ms required
== Spawn extension (numeric_pager_context, DIAL, 1) exited non-zero on ‘Local/DIAL@numeric_pager_context-d240,2’
– Executing [ANSWER@numeric_pager_context:3] SendDTMF(“DAHDI/1-1”, “0987654321”) in new stack
– Executing [ANSWER@numeric_pager_context:4] Hangup(“DAHDI/1-1”, “”) in new stack
== Spawn extension (numeric_pager_context, ANSWER, 4) exited non-zero on ‘DAHDI/1-1’
– Hungup ‘DAHDI/1-1’

I meant to write WaitForSilence(5000) as that would wait for 5 seconds of silence… not 5 milliseconds!

Try that, it may work better.