Reputation: 36048
This is how my dialplan (/etc/asterisk/extensions.conf
) looks like:
[default]
exten => _X.,1,NoOp(New call from ${EXTEN} ! )
same => n,NoOp( The header X-Twilio-CallSid = ${SIP_HEADER(X-Twilio-CallSid)})
same => Dial(SIP/SomePeer)
... etc
Thanks to the function SIP_HEADER I am able to get the id of the call that my provider sends me.
This works great for incoming calls. Now my problem is for outgoing calls. The sip header X-Twilio-CallSid
does not exists until the call is answered. How can I read that header once the call is answered? I have tried placing ${SIP_HEADER(X-Twilio-CallSid)}
once the call hangs up. Analyzing the traffic through Wireshark that header appears after the INVITE request.
Upvotes: 1
Views: 5117
Reputation: 1112
I haven't tested this, but according to the docs, you can write a post-answer handler as either a macro (using M()
) or a GoSub (using U()
):
[outbound-twilio]
exten => _X.,1,Dial(SIP/${EXTEN}@twilio-trunk,,M(post-answer))
[macro-post-answer]
exten => s,1,Verbose("Answer header shows ${SIP_HEADER(X-Twilio-CallSid)}")
same => s,n,Return()
I'm not sure if this will be any different, since the INVITE transaction may only track the initial request, and not the response, even when we execute it from the other channel. You may also want to look into switching to chan_pjsip
, which has PJSIP_HEADER
:
PJSIP_HEADER allows you to read specific SIP headers from the inbound PJSIP channel as well as write(add, update, remove) headers on the outbound channel. One exception is that you can read headers that you have already added on the outbound channel
Perhaps this is implemented differently than chan_sip
's SIP_HEADER
function?
Also, more docs on Macros from the book.
Upvotes: 3
Reputation: 15259
SIP_HEADER function work only for ONE packet - inbound FIRST invite message.
You have write your own function using c/c++ or use some other soft like homer/sipcapture.
Upvotes: 3