Initiate a Call programatically


I have an Asterisk setup that has a fairly complex dialplan which does various tasks when a PJSIP endpoint (hardware sip phone) initiates outbound calls to the PSTN service.

I’ve been tasked to write something for our CRM that tells Asterisk to initiate calls when a user requests it.
I assume I’ll need to initiate both directions of the call?

  • initiate call to the local hardware sip phone
  • initiate outbound call to the PSTN service

What’s the simplest way to do this?
How can I ensure that the local hardware sip phone has been answered prior to dialling the PSTN service?

Thanks so much!

Various variations on Originate provide less simple options.

1 Like

Wow! Working perfectly using a test call file. That was easy! Thanks so much!

Is there any way to get the initial call to include auto-answer headers?

You need to use a local channel so that you can call Dial in the normal way.

1 Like

The time to get it working exceeded my attention span, but this is where I ended with my call file generator:

# auto answer -- doesn't seem to work with my Polycom IP501                                                                                                                  
#       printf 'set:\t\t__SIPADDHEADER=Alert-Info: Auto Answer\n'                                                                                                            
#       printf 'set:\t\t__SIPADDHEADER=Alert-Info: Paging\n'                                                                                                                 
#       printf 'set:\t\t__SIPADDHEADER=Alert-Info: Ring Answer\n'                                                                                                            
#       printf 'set:\t\t__SIPADDHEADER=Alert-Info: info=Auto Answer\n'                                                                                                       
#       printf 'set:\t\t__SIPADDHEADER=Call-Info: answer-after=0\n'                                                                                                          

If you get it working, please post the secret sauce.

Only chan_sip uses inheritable variables for this (although I thought the names contained a serial number, and that this was an undocumented interface.

It is possible that you can invoke the PJSIP header manipulation function using the call file variable setting feature, but you would have to pass the header name as a parameter.

(If doing this, in a call file, for chan_sip, I doubt you will need the _s, as I think you are already on the right channel. I’m not certain that call files set variables early enough to do this without a local channel, and for chan_pjsip, a pre-dial handler.)

You need to use a local channel so that you can call Dial in the normal way.

Ah, that worked but didn’t work.

The device auto-answered, but using a Local channel makes the outbound leg appear to be initiated by the Local channel, and that breaks the logic of the existing dialplan since it’s expecting outbound calls to be initiated by PJSIP extensions, not Local channels.

The “inbound” end does not need to be “Local/context”, it can be something like “PJSIP/endpoint”.

It does if you want to do anything special. Whilst I can’t rule out that PJSIP_HEADER(…) might work as a “variable” here, if you need to do anything in pre-dial handler. you do need a local channel, and the normal way of doing Set(PJSIP_HEADER(…)… is to use a pre-dial handler. The OP needs this to be able to tell the phone to autoanswer.

PJSIP_HEADER does work as a variable in call files, and on ARI originates, and AMI originates. All dialplan functions do.

1 Like

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