GotoIf hash key pressed at the end of Record command - asterisk

We ask the caller to record their name then press hash key #. If the hash key has been pressed they should move to next step, otherwise go back and ask them to record the name again.
exten => s,n(RecordName), Playback(Please Record Your Name After Beeb then press '#')
exten => s,n,Record(recordpath/namefile.wav,60)
exten => s,n,GotoIf ('# isn't pressed')?RecordName)
Is there any way to detect if # is pressed at the end of Record command?

Please check documentation of Record command.
It clearly say which variables it set on # key.
pro-sip*CLI> core show application Record
-= Info about application 'Record' =-
[Synopsis]
Record to a file.
[Description]
If filename contains '%d', these characters will be replaced with a number
incremented by one each time the file is recorded. Use 'core show file formats'
to see the available formats on your system User can press '#' to terminate
the recording and continue to the next priority. If the user hangs up during
a recording, all data will be lost and the application will terminate.
${RECORDED_FILE}: Will be set to the final filename of the recording.
${RECORD_STATUS}: This is the final status of the command
DTMF:A terminating DTMF was received ('#' or '*', depending upon
option 't')
SILENCE:The maximum silence occurred in the recording.
SKIP:The line was not yet answered and the 's' option was specified.
TIMEOUT:The maximum length was reached.
HANGUP:The channel was hung up.
ERROR:An unrecoverable error occurred, which resulted in a WARNING
to the logs.
[Syntax]
Record(filename.format[,silence[,maxduration[,options]]])
[Arguments]
format
Is the format of the file type to be recorded (wav, gsm, etc).
silence
Is the number of seconds of silence to allow before returning.
maxduration
Is the maximum recording duration in seconds. If missing or 0 there
is no maximum.
options
a: Append to existing recording rather than replacing.
n: Do not answer, but record anyway if line not yet answered.
q: quiet (do not play a beep tone).
s: skip recording if the line is not yet answered.
t: use alternate '*' terminator key (DTMF) instead of default '#'
x: Ignore all terminator keys (DTMF) and keep recording until hangup.
k: Keep recorded file upon hangup.
y: Terminate recording if *any* DTMF digit is received.
[See Also]
Not available

Related

Kernel cancelling a `input_request` at the end of the execution of a cell

I'm implementing a new Go kernel, using directly the ZMQ messages. But as an extra I want it to execute any bash command when a line is prefixed with !, similar to the usual ipython kernel.
One of the tricky parts seems to be bash scripts that take input -- there is no way (that I know of) to predict when I need to request input. So I took the following approach:
Whenever I execute a bash script, if it hasn't ended after 500ms (configurable), it issues an input_request.
If the kernel receives any input back (input_reply message), it writes the contents to the bash program's piped stdin (concurrently, not to block), and immediately issues another input_request.
Now at the end of the execution of the bash program, there is always the last input_request pending, and the corresponding widget expecting input from the user.
Jupyter doesn't drop the input_request after the execution of the cell ended, and requires the user to type enter and send an input_reply before another cell can be executed. It complains with "Cell not executed due to pending input"
Is there a way to cancel the input_request (the pending input) if the execution of the last cell already finished ?
Maybe there is some undocumented message that can be send once the bash program ends ?
Any other suggested approach ?
I know something similar works in colab.research.google.com, if I do:
!while read ii; do if [[ "${ii}" == "done" ]] ; then exit 0; fi ; echo "Input: $ii"; done
It correctly asks for inputs, and closes the last one.
But I'm not sure how that is achieved.
Jupyter's ipython notebook doesn't seem to have that smarts though, at least here the line above just locks. I suppose it never sends a input_request message.
many thanks in advance!

How to buffer DTMF in Asterisk?

Consider the following AGI script. The dialplan entry for it is simply exten => *,1,AGI(test.agi). Analog card TDM410P is used.
#!/bin/sh
read REPLY; while [ "$REPLY" ]; do
read REPLY
done
#sleep 5
echo ANSWER; read REPLY
#sleep 5
while [ 1 ]; do
echo WAIT FOR DIGIT -1; read REPLY
echo $REPLY >>/tmp/agi
done
The problem is this: I take the phone off-hook and press *12345 very fast; the result is that the first one or two digits are sometimes lost (i.e., not recorded to /tmp/agi).
How to make it so that asterisk will buffer DTMF digits until they are read?
EDIT
I guess I need to create pseudoterminal (because it can buffer data) in the channel and write dtmf digits to it as soon as they are decoded, and set the name of the pseudoterminal slave in channel variables. Then AGI script will take the name of pty slave from AGI initialization data and will just read from the pty slave instead of via "WAIT FOR DIGIT".
So, does anybody know how to hack asterisk chan_dahdi? Or maybe there is a higher channel layer, not tied to specific module? Where should I look? Any hints...
AGI script already have STDIN which do buffering for you.
If you are not reading it, it will be in buffer.
Your issue with DTMF not related to AGI nor buffering. Check "DTMF Radio Relax" or just check you have correct DTMF settings on trunk.

Asterisk random audio within dialplan

I would like to setup a dialplan to play audio at certain durations.
For example..
play an Audio file to say that the call duration is one minute, then play another file stating two minutes, then another saying ten minutes.
For that you can use goto and function RAND
pro-sip*CLI> core show function RAND
-= Info about function 'RAND' =-
[Synopsis]
Choose a random number in a range.
[Description]
Choose a random number between <min> and <max>. <min> defaults to '0', if
not specified, while <max> defaults to 'RAND_MAX' (2147483647 on many
systems).
Example: Set(junky=${RAND(1,8)}); Sets junky to a random number between
1 and 8, inclusive.
[Syntax]
RAND([min][,max])
[Arguments]
Not available
[See Also]
Not available
You also can just name files as 1.wav,2.wav etc and use playback(${RAND(1,2)} or you can add that to musiconhold folder and play random MOH

IPCS message passing related queries

I am dealing with Message Passing IPCS method. I do have few question regarding this:
KEY field in ipcs -q shows me 0x00000000 what does this means ?
Can i see what messsage is passes using msqid ?
If two entries are present (for a particular user) after executing command ipcs -q. Does this means that two messages were passed by this particular user ?
If used-bytes and message fields are set as 0 what does this mean?
Is there away to see if message queue is full or not?
How many queues can we have for one particular user?
I tried goggling, but was not able to find answer to these questions.
Please help
1. The "key" field of the Shared memory segments is usually 0x00000000. This indicates the IPC_PRIVATE key specified during creation of the shared memory segment. The manual of shmget() contains more details.
2. AFAIK, this cannot be done. If any msg is "de-queued" from the msgQ, then the intended receiver will not see it.
3. The 2 entries in the list of message queues indicates that there are currently 2 active message queues on the system identified by their corresponding unique keys.
Creating additional msgQ : ipcmk -Q
Deleting an existing msgQ : ipcrm -Q <unique-key>
4. The used-bytes and messages fields set to 0 indicate that currently no transfers have occurred using that particular msgQ.
5. Currently one way to do this to obtain the number of msgs currently queued-up in the msgQ programmatically as shown in the following C snippet. Next this can be compared with the size of the msgQ as demonstrated in this answer.
int ret = msgctl(msqid, IPC_STAT, &buf);
uint msg = (uint)(buf.msg_qnum);
printf("msgs in Q = %u\n", msg);
6. There exists a limit on the total memory used by all the msgQs on the system combined together. This can be obtained by ulimit -q. The amount of bytes used in a msgQ is listed under the used-bytes column in the output of ipcs -Q. The total number of msgQs is limited only by the amount of memory available to create a new msgQ from the msgQ memory pool limit seen above.
Also checkout the latter part of this answer for a few sample operations on POSIX message queues.

Asterisk: Record application is generating empty files

User making the call is asked to dial an extension. This is done by 1#playing a prompt with Background and then 2#wait_for_digit. Based on the extension that has been dialed, the destination number is determined and the call is forwarded to that number.
If the called person doesn't not answer, then Playback is used to play a prompt that asks the user to record the voice message; recording the voice message is done with the Record application.
This Record application is always generating empty wav files, size 44 bytes. If I remove the 1#playing a prompt with Background the Record application is generating proper files. If the Background is included, all recordings are empty.
I am using Perl Asterisk::AGI module.
$agi->exec('Answer');
....
.....
$agi->exec('Background', 'en/extra/please-enter-the-extension,n'); # this is the troubling part
my $my_extension = $agi->wait_for_digit(5000);
....
.....
$agi->exec('Playback', 'en/extra/the-party-you-are-calling&en/extra/is-curntly-busy,noanswer');
$agi->exec('Playback', 'en/vm-intro,noanswer');
my $file = 'xyz.wav';
$agi->exec('Record', "$file,0,10,k");
...
...
What should I do to make it work as I want it to?
Thank you.
UPDATE 1:
The same script is working without glitches now. Not sure if something unrelated to the script has changed.
Most likly you have check your codecs. IF you use g729 or g723 and no transcoder,it just can't write in wav format.

Resources