Local Channel Problem


#1

We currently have a dialer application that connects to the AMI of the asterisk to ORIGINATE calls.

When originating the call we dial a LOCAL channel which goes into a context that subsequently dials an outbound sip call.

Once the call connects it gets bridged to another context that executes a playback to the sip channel.

Everything works perfect, the problem is obtaining variables from the SIP channel when it does not connect.

In other words, to do our accounting, we use the call-id to match to our Nextone server.

When the call connects we can easily access ${SIPCALLID} and save our CDR , BUT if the call fails for any reason,
the variable ${SIPCALLID} is empty together with all the other options empty as well.

We also tried calling
exten => _X.,n,Set(callid=${SIP_HEADER(Call-ID)})

but asterisk responds.

chan_sip.c:17441 func_header_read: This function can only be used on SIP channels.

How can we access the results of the dial command from a local channel?

Our extensions looks like this
[dialer-out]
exten => _X.,n,Set(CDR(accountcode)=${CAMP_ID})
exten => _X.,n,Set(CDR(userfield)=${OWNER})
exten => _X.,n,Set(WAITT=${MATH(${WAFA} + 0)})
exten => _X.,n,Set(MAX_CALL_DURATION=$[ ${MAX_DURATION} + 1 ])

exten => _X.,n,Dial(SIP/${EXTEN}@${PEER},${WAITT},S(${MAX_DURATION}))
exten => _X.,n,Noop(${SIPCALLID}) //This variable prints EMPTY

exten => _X.,n,Wait(1)
exten => _X.,n,Hangup()

exten => h,n,Hangup()
exten => h,n(end),Noop(${DIALSTATUS})

[dialer-voice-answered]
exten => dialer,1,Answer()
exten => dialer,n,Set(ST=${EPOCH})
exten => dialer,n,Wait(1)
exten => dialer,n,Playback(${AUDIO_FILE})
exten => dialer,n,Noop(${SIPCALLID}) //This variable prints out PERFECT
exten => dialer,n,Hangup()


#2

Hi,

What is {SIPCALLID} ? Its a static variable defined by you ?

Ketan


#3

No it is set by Asterisk:

chan_sip.c:

if (!ast_strlen_zero(i->callid)) pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid);

His problem is that it belongs to the SIP channel on the far side of the Dial application. Only when the call succeeds does the local channel get optimised out and this channel and its local variables become the A side of the originate.

The information is available on ChannelUpdate AMI event. As I’m looking at a pre-CEL version, I don’t know if it is also available via CEL.

/* Inform manager user about new channel and their SIP call ID */ if (global_callevents) manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate", "Channel: %s\r\nUniqueid: %s\r\nChanneltype: %s\r\nSIPcallid: %s\r\nSIPfullcontact: %s\r\n", tmp->name, tmp->uniqueid, "SIP", i->callid, i->fullcontact);