DTMF to file

Is it how possible to write incoming DTMF to a file on asterisk?

Example: Call asterisk to a specific inboud route, asterisk answers, you input some DTMF digits, asterisk waits 3 seconds, writes this digits pressed to a file (template with callerid an DTMF code, maybe timestamp) and hangsup the line.

I found something similar with AlarmReceiver, but I don’t think Ican use it, because the incoming device calling won’t be an alarm but regular phone or mobile. Or can I?

Thank you

I have not tried this, but it should be possible to use the Read() function to prompt the caller and accept DTMF into a variable, and then use an AGI program to write the digits to a file:

exten=>s,1,Answer()
exten=>s,n,Read(digits,5)
AGI(WriteFile, ${digits})
Hangup

Then place the following Linux shell commands in an executable file named WriteFile in your agi directory:

#!/bin/bash
echo $1 > FILE
exit 0

sebek,

I haven’t tried Dave’s solution yet but I just want to share how I solved this one. In my case I made an AGI executable program that is responsible for collecting the tones and then from there, I saved it to file.

just an excerpt from my program

  • in extensions.conf, add this line

where GetDTMF.py - is an executable program which in my case is a python executable program which I named GetDTMF.py

sys.stdout.write("GET DATA PlayAudio 10000\n")
sys.stdout.flush()

ReceivedDTMF = sys.stdin.readline().strip()

where GET DATA is the command for capturing streams of DTMF tones, PlayAudio is a sound file, just to play something while waiting for the tones, and 10000 is the timeout in ms, see >> http://www.voip-info.org/wiki/view/get+data

ReceivedDTMF - was just the name of the variable I used where the DTMF are stored as a string

If you want this to be saved on file, it depends on your Programming language used, just look it up on how to save this one on a file, and voila, you will have what you need.

I havent tried Dave’s solution but I think his solution is a lot better however, in my case, I just want to show you other flavor and I must say that the solution I presented to you is 100% guaranteed.

I’ve inserted this to my dialplan (extensions_custom.conf)

[ext-did-0002-custom]
exten=> 555666,1,Answer()
exten=> 555666,n,Read(digits,5)
exten=> 555666,3,AGI(WriteFile, ${digits})
exten=> 555666,4,Hangup

and it seems that incoming call on this route in correctly routed to agi script, but i get the next error:

[2009-11-25 13:38:12] VERBOSE[5634] logger.c: -- Executing [s@from-sip-external:1] GotoIf("SIP/gsm2-b790b2f8", "1?from-trunk|555666|1") in new stack [2009-11-25 13:38:12] VERBOSE[5634] logger.c: -- Goto (from-trunk,555666,1) [2009-11-25 13:38:12] VERBOSE[5634] logger.c: -- Executing [555666@from-trunk:1] Answer("SIP/gsm2-b790b2f8", "") in new stack [2009-11-25 13:38:12] VERBOSE[5634] logger.c: -- Executing [555666@from-trunk:2] Read("SIP/gsm2-b790b2f8", "digits|5") in new stack [2009-11-25 13:38:12] WARNING[5634] file.c: File 5 does not exist in any format [2009-11-25 13:38:12] WARNING[5634] file.c: Unable to open 5 (format 0x4 (ulaw)): No such file or directory [2009-11-25 13:38:12] VERBOSE[5634] logger.c: -- User disconnected [2009-11-25 13:38:12] VERBOSE[5634] logger.c: == Spawn extension (from-trunk, 555666, 2) exited non-zero on 'SIP/gsm2-b790b2f8' [2009-11-25 13:38:12] VERBOSE[5634] logger.c: -- Executing [h@from-trunk:1] Hangup("SIP/gsm2-b790b2f8", "") in new stack [2009-11-25 13:38:12] VERBOSE[5634] logger.c: == Spawn extension (from-trunk, h, 1) exited non-zero on 'SIP/gsm2-b790b2f8'

Any clues? :smile:
How can i modify this script to insert to file callerid and timestamp alongside DTMF code?
Thank you

[quote=“sebek72”]I’ve inserted this to my dialplan (extensions_custom.conf)

[ext-did-0002-custom]
exten=> 555666,1,Answer()
exten=> 555666,n,Read(digits,5)

Any clues? :smile:
How can i modify this script to insert to file callerid and timestamp alongside DTMF code?
Thank you[/quote]

I believe that should be:

Notice the extra comma. The error that you get says that it is looking for a file called 5. The Read() page on voip-info.org gives this:

[quote]As of Asterisk 1.4:
Read(variable[,filename][,maxdigits][,option][,attempts][,timeout])
[/quote]

thank you now the script gets executed.
But still no file created.

[2009-11-25 18:32:46] VERBOSE[6209] logger.c: -- Executing [555666@from-trunk:2] Read("SIP/gsm2-b76033e0", "digits||5") in new stack [2009-11-25 18:32:46] VERBOSE[6209] logger.c: -- Accepting a maximum of 5 digits. [2009-11-25 18:32:54] VERBOSE[6209] logger.c: -- User entered '11223' [2009-11-25 18:32:54] VERBOSE[6209] logger.c: -- Executing [555666@from-trunk:3] AGI("SIP/gsm2-b76033e0", "WriteFile| 11223") in new stack [2009-11-25 18:32:54] VERBOSE[6209] logger.c: -- Launched AGI Script /var/lib/asterisk/agi-bin/WriteFile [2009-11-25 18:32:54] VERBOSE[6209] logger.c: -- AGI Script WriteFile completed, returning 0 [2009-11-25 18:32:54] VERBOSE[6209] logger.c: -- Executing [555666@from-trunk:4] Hangup("SIP/gsm2-b76033e0", "") in new stack [2009-11-25 18:32:54] VERBOSE[6209] logger.c: == Spawn extension (from-trunk, 555666, 4) exited non-zero on 'SIP/gsm2-b76033e0' [2009-11-25 18:32:54] VERBOSE[6209] logger.c: -- Executing [h@from-trunk:1] Hangup("SIP/gsm2-b76033e0", "") in new stack [2009-11-25 18:32:54] VERBOSE[6209] logger.c: == Spawn extension (from-trunk, h, 1) exited non-zero on 'SIP/gsm2-b76033e0'

Is the bash script wrong?

Thank you

[quote=“sebek72”]thank you now the script gets executed.
But still no file created.

Is the bash script wrong?

Thank you[/quote]

I’m glad it worked!

I’m not very good at this, but I believe that you should find a file called FILE in your agi directory that has the digits. You also might want to make sure that whatever user is executing that script (asterisk?) has write permissions to that folder.

It was the permissions on files.

Thanks a lot…
I tought that the file would be created, but is has to already exist and have the right permissions.

I’m not so good at bash.

Anyone with an idea for a script like this? Every call gets saved to a file named: MM/DD/YYYY/HH:MM:SS
Inside the file there is lines for: CALLERID, DTMF pressed, TIMESTAMP.

Any help would be great :wink:

Hi,

Here’s the source for a php/agi file and dialplan sample I made, which can help you implement what you need :

#extensions.conf

exten => 12345,1,Goto(dtmf-recording,${EXTEN},1)

[dtmf-recording]
exten => _X.,1,Answer
exten => _X.,2,Set(TIMEOUT(digits)=5)
exten => _X.,3,Set(TIMEOUT(response)=10)
exten => _X.,4,Set(TIMESTAMP=${STRFTIME(${EPOCH},%Y%m%d-%H%M%S)})
exten => _X.,n,Read(DTMF|/var/lib/asterisk/agi-bin/sounds/whatever)
exten => _X.,n,Hangup
exten => h,1,Deadagi(agi-bin/report_dtmf.php|${TIMESTAMP}|${DTMF})


report_dtmf.php :

<?php set_time_limit(30); require_once "phpagi.php"; declare(ticks = 1); ob_implicit_flush(true); $AGI = new AGI(); $DSTDIR = "/var/lib/asterisk/agi-bin/recordings/"; //Folder where you want to store the file. $CALLERID = $AGI->request['agi_callerid']; $DATE = $_SERVER["argv"][1]; $DTMF = $_SERVER["argv"][2]; $contents = " Caller ID: $CALLERID DTMF: $DTMF Date: $DATE "; $fp = fopen($DSTDIR.$recfile.'.txt', 'w'); fwrite($fp, $contents); fclose($fp); ?>

Best regards,

Joao Cohen
Telecom Systems and Audiotext Specialist
linkedin.com/in/joaocohen

for this context:

[dtmf-recording] exten => _X.,1,Answer exten => _X.,2,Set(TIMEOUT(digits)=5) exten => _X.,3,Set(TIMEOUT(response)=10) exten => _X.,4,Set(TIMESTAMP=${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}) exten => _X.,n,Read(DTMF|/var/lib/asterisk/agi-bin/sounds/whatever) exten => _X.,n,Hangup exten => h,1,Deadagi(agi-bin/report_dtmf.php|${TIMESTAMP}|${DTMF})

what is the destination of the path: /var/lib/asterisk/agi-bin/sounds/whatever ??