Record a message, hangup, dial other numbers and playback recording

Hi, I’ve got an interesting set of requirements.

Basically want to have customers dial us in, play back a message, record a message and then allow the customer to hangup.

Afterwards want to start dialing other queues, once they connect playback a message.

The two parts I’m not sure how to do are:

  1. Do a long running process once the call is hungup. I assume I can just use the h extension and be okay, but I’m not sure what happens if I try to dial a queue in h
  2. Once the call is connected to the queue, instead of having the two channels communicate, just playback the message.

Thanks for any assistance or help :slight_smile: I don’t really need examples or anything, just a general direction would be great

Actually, I just found that the Cmd Queue can execute a gosub as one of it’s optional parameters, it’s not very well documented. So I think that might be the key to solving this problem. I’ll continue investigating

I’ve gotten more along the way, the only problem I am experiencing now is when the Queue cmd is dialed, it hangs up immediately :frowning:

My diaplan (simplified for brevity):

[standard-gn-helpdesk-corona-afterhours]
; Hangup Extension
exten => h,1, NoOp(hangup standard-gn-helpdesk-corona-afterhours)
same => n, Gosub(sub-queue-gn-afterhours,s,1)
same => n, Return()

exten => s,1, NoOp(standard-gn-helpdesk-corona-afterhours)
same => n, Record(gn_ah_recording%d:ulaw)
same => n, Hangup()
; Callee has hungup by this point. `h` should be executed

[playback-recorded-message]
exten => s,1, NoOp(playback-recorded-message)
same => n, Playback(${RECORDED_FILE})

[sub-queue-gn-afterhours]
exten => s,1,NoOp(sub-queue-gn-afterhours)
; Has the `c` option which allows the queue to continue when callee hangs
same => n,Queue(GNAfterHours1,tkc,,,540,,,playback-recorded-message)
same => n,Return()

I actually couldn’t figure a way around all the issues encountered, my final solution ended up being a hacky workaround using AGI to initiate a new call using a local channel instead. My dial plan ended up looking something like this:

[standard-gn-helpdesk-corona-afterhours]
; Hangup Extension
exten => h,1, NoOp(hangup standard-gn-helpdesk-corona-afterhours)
same => n, AGI(dial-playback-recorded-messages.php)
same => n, Hangup()

exten => s,1, NoOp(standard-gn-helpdesk-corona-afterhours)
same => n, Record(gn_ah_recording%d:wav)
same => n, Hangup()
; Callee has hungup by this point. `h` should be executed

[playback-recorded-message]
exten => s,1, NoOp(playback-recorded-message)
same => n, Playback(${RECORDED_FILE})

[sub-queue-gn-afterhours]
exten => s,1,NoOp(sub-queue-gn-afterhours)
 ; Total hack! This is bad practice, but I don't have shared func and I couldn't find another way to keep this variable in scope when using Queue -> Sub
same => n, Set(GLOBAL(RECORDED_FILE)=${RECORDED_FILE})
same => n,Queue(GNAfterHours1,tk,,,540,,,playback-recorded-message)
same => n,Return()

[from-internal-default]
; Outbound dial for AH
exten => 8745111,1, Answer()
same => n, Gosub(sub-queue-gn-afterhours,s,1)
same => n, Hangup()

; Inbound dial for AH
exten => 8745112,1, Answer()
same => n, Wait(3600)
same => n, Hangup()

My AGI script looked like this (cut down for simplicity)

<?php
$recordingFile = $agi->get_variable("RECORDED_FILE", true);
$hasAh = (string) $agi->get_variable("HAS_AFTERHOURS", true); 

$originateMsg = new OriginateAction('local/8745112@from-internal-default');
$originateMsg->setContext('from-internal-default');
$originateMsg->setPriority('1');
$originateMsg->setExtension('8745111');
$originateMsg->setAsync(true);
$originateMsg->setTimeout(19000);
$originateMsg->setVariable('RECORDED_FILE', $recordingFile);
$originateMsg->setVariable('HAS_AFTERHOURS', $hasAh);
$response = $pamiClient->send($originateMsg);

How it works:

  1. Caller comes in and records a message
  2. Call hangs up and executes the AGI script which initiates a new call between a local channel of 8745112 and dialing local extension 8745111
  3. Extension 8745112 just waits to keep the connection open
  4. Channel 8745111 moves into a queue, once a call is connected it then runs the post queue sub playback-recorded-message which plays back a message

I’m confident there is a much better, less hacky solution, but with my level of understanding of Asterisk, this is the best I could come up with. Hope it helps someone

1 Like

Nice! BTW the Originate() application got the 'a’sync option in version 16 - lets you do more of this in dial plan instead of AGI.

Thanks for the tip :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.