Pre-dial handler help

I am new to this and doing a bit of research.

I am trying to execute an AGI script BEFORE a call is dialled out (to download Sound assets on to the server from an AWS S3 bucket), so far it seems that ‘pre-dial handler’ is the route I should be going down and certainly appears to work BUT I am having issues with ARI (where the call is originated externally) - the number appears to dial twice??

My dial plan looks like this:

[test]
exten => start,1,Dial(PJSIP/{NUMBER},,B(test^prepare^1))
exten => start,n,NoOp(${EXTEN})
exten => start,n,Playback(${PREPARED_SOUND})
exten => start,n,Hangup()
exten => prepare,1,NoOp(${EXTEN})
exten => prepare,n,AGI(prepare-sounds-script)
exten => prepare,n,Return()

Where the AGI prepare-sounds-script downloads the sound from AWS and sets the variable PREPARED_SOUND with the path to the sound file.

The ARI POST request body to /ari/channels is:

{
    "endpoint" : "Local/{NUMBER}",
    "extension" : "start",
    "context" : "test",
    "priority" : 1,
    "timeout" : 3000
}
  1. is this right path to go down?
  2. ARI is essential in this process but not sure if the POST /ari/channels is correct?

Any help/advice would be greatly appreciated.

I dont use ARI , but I guess you re diaing the NUMBER twice with the Dial() command and also with the ARI originateWithId: POST /channels/{channelId}

AFAIK, you can only create channels to real endpoints, such as SIP/PJSIP and not Local channels. But I may be wrong here…

See ARI channel documentation: Asterisk 18 Channels REST API - Asterisk Project - Asterisk Project Wiki

You can also use swagger ari.asterisk.org to test your ARI interaction.

ARI doesn’t care, you can create Local channels fine. They behave the same way they do when used with Originate in AMI, for example.

1 Like

Yep, this appears to be the issue I have, in order to use ARI, it will originate a call using the POST /channels (not /channels/{channelId} although the outcome is the same (originating a call and then executing the dealing plan - thus two calls).

I think there’s just a misunderstanding of originate, Local channels, and the dialplan here.

{
    "endpoint" : "Local/{NUMBER}",
    "extension" : "start",
    "context" : "test",
    "priority" : 1,
    "timeout" : 3000
}

This means: Call Local/{NUMBER} and once answered send it into the dialplan at extension start in context test. If these end up doing the same thing, then you’ll have it in the same dialplan twice doing the same thing.

[test]
exten => start,1,Dial(PJSIP/{NUMBER},,B(test^prepare^1))
exten => start,n,NoOp(${EXTEN})
exten => start,n,Playback(${PREPARED_SOUND})
exten => start,n,Hangup()

This means Dial PJSIP/{NUMBER}. If the call is answered, then the channel will remain inside of Dial() as it is bridged. It will not go to the next part of the dialplan.

What you LIKELY want to do is have the Playback and such happen on the extension you pass to the originate - this would cause the audio to be played back to the called endpoint.

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