Unable to set Diversion

I have Asterisk sending unanswered calls to Exchange Unified Messaging. Exchange needs to see a diversion to know where to direct the call. I set the diversion header but the Dial is using a different diversion header that I did not set, which is wrong.

The correct header would be this:
Diversion: tel:200;reason=no-answer;screen=no;privacy=off

Asterisk is sending this:
Diversion: sip:+1410888888@;reason=unconditional

I cannot figure out where that is coming from. I set a header “X-debug” and it gets set correctly.


exten => _[*0-9]!,1,Noop(exchange UM)
same => n,Set(PJSIP_HEADER(remove,*)=)
same => n,Dial(PJSIP/Exchange_2,,b(diversion^${EXTEN}^1))

exten => _[*0-9]!,1,Noop(set diversion)
same => n,Set(PJSIP_HEADER(remove,*)=)
same => n,Set(PJSIP_HEADER(add,X-debug)=<tel:${EXTEN}>\;reason=no-answer\;screen=no\;privacy=off)
same => n,Set(PJSIP_HEADER(add,Diversion)=<tel:${EXTEN}>\;reason=no-answer\;screen=no\;privacy=off)
same => n,Return()

Log output:
 Executing [200@exchange:1] NoOp("PJSIP/Twilio-East-0000002d", "exchange UM") in new stack
    -- Executing [200@exchange:2] Set("PJSIP/Twilio-East-0000002d", "PJSIP_HEADER(remove,*)=") in new stack
    -- Executing [200@exchange:3] Dial("PJSIP/Twilio-East-0000002d", "PJSIP/Exchange_2,,b(diversion^200^1)") in new stack
    -- PJSIP/Exchange_2-0000002e Internal Gosub(diversion,200,1) start
    -- Executing [200@diversion:1] NoOp("PJSIP/Exchange_2-0000002e", "set diversion") in new stack
    -- Executing [200@diversion:2] Set("PJSIP/Exchange_2-0000002e", "PJSIP_HEADER(remove,*)=") in new stack
[2018-10-12 14:16:43] ERROR[31760]: res_pjsip_header_funcs.c:410 remove_header: No headers had been previously added to this session.
    -- Executing [200@diversion:3] Set("PJSIP/Exchange_2-0000002e", "PJSIP_HEADER(add,X-Aquila)=<tel:200>;reason=no-answer;screen=no;privacy=off") in new stack
    -- Executing [200@diversion:4] Set("PJSIP/Exchange_2-0000002e", "PJSIP_HEADER(add,Diversion)=<tel:200>;reason=no-answer;screen=no;privacy=off") in new stack
    -- Executing [200@diversion:5] Return("PJSIP/Exchange_2-0000002e", "") in new stack
  == Spawn extension (from-internal, 200, 1) exited non-zero on 'PJSIP/Exchange_2-0000002e'
    -- PJSIP/Exchange_2-0000002e Internal Gosub(diversion,200,1) complete GOSUB_RETVAL=
    -- Called PJSIP/Exchange_2
  == Everyone is busy/congested at this time (1:0/0/1)
    -- Auto fallthrough, channel 'PJSIP/Twilio-East-0000002d' status is 'CHANUNAVAIL'

And finally, this is what was actually sent to Exchange:
Session Initiation Protocol (INVITE)
    Request-Line: INVITE sip:aquila-dag.aquila.local:5067 SIP/2.0
    Message Header
        Via: SIP/2.0/TCP;rport;branch=z9hG4bKPj8ba4048b-21d8-46ef-a34b-e908deb7ba4c;alias
        From: "3018888888" <sip:3018888888@>;tag=278ca39d-ff44-4444-a8da-0879a9b6e3b3
        To: <sip:aquila-dag.aquila.local>
        Contact: <sip:asterisk@;transport=TCP>
        Call-ID: 830f5254-1781-440c-ac4f-3ee2d531860b
        CSeq: 1907 INVITE
        Supported: 100rel, timer, replaces, norefersub
        Session-Expires: 1800
        Min-SE: 90
        X-debug: <tel:200>;reason=no-answer;screen=no;privacy=off
        Diversion: <sip:+14108888888@>;reason=unconditional
        Max-Forwards: 70
        User-Agent: FPBX-
        Content-Type: application/sdp
        Content-Length:   333
    Message Body

As you can see, the X-debug is correct, but the Diversion is wrong.
One final clue, if the source endpoint is local, it works. If the source endpoint is an outside caller, the diversion gets messed up.

Diversion is maintained by Asterisk. You should not try to manually add headers that Asterisk directly maintains.

See https://wiki.asterisk.org/wiki/display/AST/Manipulating+Party+ID+Information#ManipulatingPartyIDInformation-REDIRECTINGdialplanfunction


I’m all for doing it the cleanest way possible. I’ve read this page 5 times and got some code working using REDIRECTING. It is setting a FROM field that correctly shows the redirection intention, and it is updating the calling party display, that’s cool, I’m going to use that.

However, my Diversion is still not being set and the call is still rejected for that reason.
I would be grateful for a bit more of a hint.

Thanks, got it working now, I think.

1 Like