Asterisk AMI Question

I’m working with a PHP script which initiates a call using asterisk AMI and the call is initiated using the following command it appears:

Action: Originate
Channel: SIP/301
WaitTime: 30
Context: from-internal
Exten: 02081231234
Priority: 1
Async: yes

So it calls extension 301 then when that extension answers, it dials the Exten number for example 02081231234. However, extension 301 requires a pin to dial to number matching that pattern. Is it possible to use comma followed by pin and # as the Exten value for example below:

Action: Originate
Channel: SIP/301
WaitTime: 30
Context: from-internal
Exten: 02081231234,0000#
Priority: 1
Async: yes

If comma and # is not supported via this method, what are my options to include the pin the the call initialization?

So I asked AI about this and it suggested the following solution. Given how inaccurate AI can be sometimes, can someone check this and tell me if it sounds ok and if it will work? specially syntaxes and commands for FreePBX 17

  1. Edit the extensions_custom.conf file to create a new custom context as follows:
    nano /etc/asterisk/extensions_custom.conf

  2. Add this custom context at the end of the file:

[clicktocall-pin]
exten => s,1,NoOp(Click-to-Call with PIN: ${number} PIN: ${pin})
exten => s,n,Dial(${DIALSTRING}/${number},,D(wwww${pin}#))
exten => s,n,Hangup()
  1. Save and exit
    Ctrl+X, then Y, then Enter in nano

  2. Reload the dialplan:
    asterisk -rx "dialplan reload"

  3. Verify the Custom Context
    asterisk -rx "dialplan show clicktocall-pin"

  4. User variable in AMI
    Variable: number=$number,pin=$pin

How It Works:
Normal Call: Uses from-internal context and Directly dials the number

PIN Call (when conditions are met):

Uses clicktocall-pin context
Passes number and pin as variables
Custom dialplan waits 2 seconds (wwww) after remote party answers
Sends PIN followed by # as DTMF tones

It’s not given you how you achieve this part.

Means you can’t select the latest Asterisk, but you must either select a legacy version, or obtain a chan_sip from a forked project. (If you want an extension, in the Asterisk sense, you should use Local/301@from-internal.

, and # would be sent to your SIP provider, who would probably fault them, but would be permitted to interpret them in the way you wanted. It is probably only analogue FXO gateways that might, normally, be expected to understand this format.

Actually the easiest way of doing this is to completely bypass FreePBX, and call the custom context direct from the originate. In that case, it would probably be easier to read if you replaced s by _X., and DIALSTRING by EXTEN.

It would also be possible to parse the exact string, but you seem to be using UK numbers, so you would need patterns for each possible number length - not all UK numbers are the same length.

1 Like

So basically call it like:

Channel: local/301@from-internal

Create an Outbound Route that doesn’t require a PIN but uses a prefix. Example:

prepend: (blank)
prefix: 00
match pattern: 0ZXXXXXX.
CallerID: (blank)

Use the same trunk(s) as the regular route. Put this route after your emergency routes and before the regular route.

Then call AMI with:
Action: Originate
Channel: local/301@from-internal
WaitTime: 30
Context: from-internal
Exten: 0002081231234
Priority: 1
Async: yes