Asterisk AGI not receiving DTMF digits after Background(), but CLI shows DTMF events

Hi everyone,

I’m facing an issue where DTMF digits are detected by Asterisk and visible in the CLI, but my AGI script is unable to receive them.

Environment

  • Asterisk 18.26.4-vici

  • AGI script written in Perl

  • Incoming SIP trunk call

Call Flow

  1. Answer call

  2. Play welcome message

  3. Play language selection menu

  4. Wait for caller to press a digit

Dialplan:

#!/usr/bin/perl

use strict;
use warnings;
use Asterisk::AGI;

my $agi = new Asterisk::AGI;

Play welcome

$agi->exec(‘Playback’, ‘SeylanPL/Ann01_Welcome’);

Play language prompt and wait for one digit

my $result = $agi->exec(‘Background’, ‘SeylanPL/Ann02_Lang’, 10000, 1);
my $digit = $result->{result} // ‘’;

$agi->verbose(“Digit pressed: [$digit]”, 1);

my $szLanguage = ‘’;

if ($digit eq ‘1’) {
$szLanguage = ‘ENG’;
}
elsif ($digit eq ‘2’) {
$szLanguage = ‘SIN’;
}
else {
$szLanguage = ‘No Input’;
}

$agi->verbose(“Language: $szLanguage”, 1);

Branch based on language

if ($szLanguage eq ‘ENG’) {
$agi->exec(‘Playback’, ‘SeylanPL/ENG/Seylan_MainMenu_old’);
}
elsif ($szLanguage eq ‘SIN’) {
$agi->exec(‘Playback’, ‘SeylanPL/SIN/Seylan_MainMenu_old’);
}
else {
$agi->exec(‘Playback’, ‘vm-goodbye’);
}

CLI Output

Language menu is played correctly:

root’
Connected to Asterisk 18.26.4-vici currently running on cx (pid = 14357)
[Jun 4 17:52:23] == Using SIP RTP CoS mark 5
[Jun 4 17:52:23] > 0x7f032803f540 – Strict RTP learning after remote address set to: 10.1.9.246:17060
[Jun 4 17:52:23] – Executing [27893000@trunkinbound:1] AGI(“SIP/Carrier_1-00000096”, “agi-DID_route.agi”) in new stack
[Jun 4 17:52:23] – Launched AGI Script /usr/share/asterisk/agi-bin/agi-DID_route.agi
[Jun 4 17:52:23] – <SIP/Carrier_1-00000096>AGI Script agi-DID_route.agi completed, returning 0
[Jun 4 17:52:23] – Executing [s@SeylanPL:1] Answer(“SIP/Carrier_1-00000096”, “”) in new stack
[Jun 4 17:52:23] > 0x7f032803f540 – Strict RTP switching to RTP target address 10.1.9.246:17060 as source
[Jun 4 17:52:23] – Executing [s@SeylanPL:2] AGI(“SIP/Carrier_1-00000096”, “agi-VDAD_inbound_calltime_check.agi,CALLMENU-----YES-----SeylanPL-------------------------NO-----YES”) in new stack
[Jun 4 17:52:23] – Launched AGI Script /usr/share/asterisk/agi-bin/agi-VDAD_inbound_calltime_check.agi
[Jun 4 17:52:23] – <SIP/Carrier_1-00000096> Playing ‘sip-silence.gsm’ (escape_digits=) (sample_offset 0) (language ‘en’)
[Jun 4 17:52:23] – <SIP/Carrier_1-00000096> Playing ‘sip-silence.gsm’ (escape_digits=) (sample_offset 0) (language ‘en’)
[Jun 4 17:52:23] – <SIP/Carrier_1-00000096>AGI Script agi-VDAD_inbound_calltime_check.agi completed, returning 0
[Jun 4 17:52:23] – Executing [s@SeylanPL:3] Set(“SIP/Carrier_1-00000096”, “INVCOUNT=0”) in new stack
[Jun 4 17:52:23] – Executing [s@SeylanPL:4] AGI(“SIP/Carrier_1-00000096”, “AGIseylanPL.agi”) in new stack
[Jun 4 17:52:23] – Launched AGI Script /usr/share/asterisk/agi-bin/AGIseylanPL.agi
[Jun 4 17:52:23] – AGI Script Executing Application: (Playback) Options: (SeylanPL/Ann01_Welcome)
[Jun 4 17:52:23] – <SIP/Carrier_1-00000096> Playing ‘SeylanPL/Ann01_Welcome.slin’ (language ‘en’)
[Jun 4 17:52:25] – AGI Script Executing Application: (Background) Options: (SeylanPL/Ann02_Lang)
[Jun 4 17:52:25] – <SIP/Carrier_1-00000096> Playing ‘SeylanPL/Ann02_Lang.slin’ (language ‘en’)
[Jun 4 17:52:28] > 0x7f032803f540 – Strict RTP learning complete - Locking on source address 10.1.9.246:17060
[Jun 4 17:52:30] DTMF[32625][C-00000097]: channel.c:4027 __ast_read: DTMF begin ‘2’ received on SIP/Carrier_1-00000096
[Jun 4 17:52:30] DTMF[32625][C-00000097]: channel.c:4031 __ast_read: DTMF begin ignored ‘2’ on SIP/Carrier_1-00000096
[Jun 4 17:52:30] DTMF[32625][C-00000097]: channel.c:3913 __ast_read: DTMF end ‘2’ received on SIP/Carrier_1-00000096, duration 80 ms
[Jun 4 17:52:30] DTMF[32625][C-00000097]: channel.c:4002 __ast_read: DTMF end passthrough ‘2’ on SIP/Carrier_1-00000096
[Jun 4 17:52:30] AGIseylanPL.agi: Digit pressed:
[Jun 4 17:52:30] AGIseylanPL.agi: Language: No Input
[Jun 4 17:52:30] – AGI Script Executing Application: (Playback) Options: (vm-goodbye)
[Jun 4 17:52:30] – <SIP/Carrier_1-00000096> Playing ‘vm-goodbye.gsm’ (language ‘en’)
[Jun 4 17:52:31] – <SIP/Carrier_1-00000096>AGI Script AGIseylanPL.agi completed, returning 0
[Jun 4 17:52:31] – Auto fallthrough, channel ‘SIP/Carrier_1-00000096’ status is ‘UNKNOWN’
[Jun 4 17:52:31] WARNING[32625][C-00000097]: func_hangupcause.c:138 hangupcause_read: Unable to find information for channel
[Jun 4 17:52:31] – Executing [h@SeylanPL:1] AGI(“SIP/Carrier_1-00000096”, “agi://127.0.0.1:4577/call_log–HVcauses–PRI-----NODEBUG-----0--------------------)”) in new stack
[Jun 4 17:52:31] WARNING[32625][C-00000097]: res_agi.c:2038 handle_connection: Connecting to ‘127.0.0.1:4577’ failed for url ‘agi://127.0.0.1:4577/call_log–HVcauses–PRI-----NODEBUG-----0--------------------)’: Connection refused
[Jun 4 17:52:31] WARNING[32625][C-00000097]: res_agi.c:2098 launch_netscript: Couldn’t connect to any host. FastAGI failed.
cx*CLI>

Question

Why is the DTMF visible in the Asterisk CLI but not available to the AGI script?

How fix this issue?

Background is meant for dialplan usage, and internally would handle DTMF. If you want access to the DTMF, you would instead use the actual AGI command instead[1].

[1] GET DATA - Asterisk Documentation

It has been my experience that using the AGI exec command to execute a dialplan application yields less control and fewer features than using the ‘native’ AGI command.

The only dialplan applications I’ve exec’d in over 20 years are dumpchan, monitor, and resetcdr.