# Converting SIP to PJSIP , i need DIALSTATUS ? is it changed?

**URL:** <https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009>\
**Category:** Asterisk Dialplan\
**Created:** [March 18, 2022, 12:12pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009 "2022-03-18T12:12:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![NoFate](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/nofate/32/6511_2.png) [@NoFate](https://community.asterisk.org/u/NoFate)\
**Post date:** [March 18, 2022, 12:12pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/1 "2022-03-18T12:12:39Z")

</div>

Hey, see below, i have this in my dialplan

I first send a push message to activate the registraion on my android, i wait 3 sec , then i dial  
When i answer, all is fine

When i decline the call , it should go to line 11 =\> hangup, this was working on chan\_sip  
Now i use PJSIP, i decline the call, it starts ringing again… seems the BUSY status is different?

```auto
exten => s,1,Set(CURL_RESULT=${SHELL(curl -X POST -H "Content-Type: application/json" -d '{ "user" : "notify.registration" }' http://webhook)})
exten => s,2,Wait(3)
exten => s,3,Dial(PJSIP/6000,45)
exten => s,4,GotoIf($[${DIALSTATUS} = CHANUNAVAIL]?9)
exten => s,5,GotoIf($[${DIALSTATUS} = NOANSWER]?11)
exten => s,6,GotoIf($[${DIALSTATUS} = CONGESTION]?11)
exten => s,7,GotoIf($[${DIALSTATUS} = BUSY]?11)
exten => s,8,GotoIf($[${DIALSTATUS} = CANCEL]?11)
exten => s,9,Wait(2)
exten => s,10,Dial(PJSIP/6000,45)
exten => s,11,Hangup()
exten => s,12,NoOp(reporting noanswer returning to caller)
exten => s,13,Verbose(2, Dial status ${DIALSTATUS})

```

thnx for the info

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [March 18, 2022, 12:24pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/2 "2022-03-18T12:24:02Z")

</div>

It works the same. You’d need to provide what is actually happening for anyone to be able to provide any further information.

---

<div class="post-metadata">

**Author:** ![NoFate](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/nofate/32/6511_2.png) [@NoFate](https://community.asterisk.org/u/NoFate)\
**Post date:** [March 18, 2022, 12:28pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/3 "2022-03-18T12:28:08Z")

</div>

Here you go,

Here is where i declined the call

`[Mar 18 12:26:40] == Everyone is busy/congested at this time (1:0/0/1)`

Then it starts ringing again 🙂

```auto

[Mar 18 12:26:31] -- Added contact 'sip:6001@192.168.0.232;transport=udp' to AOR '6001' with expiration of 3600 seconds
[Mar 18 12:26:31] == Endpoint 6001 is now Reachable
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed

  0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 48 0 0 100 48 0 24000 --:--:-- --:--:-- --:--:-- 24000
[Mar 18 12:26:34] -- Executing [s@default:1] Set("PJSIP/6001-00000000", "CURL_RESULT=") in new stack
[Mar 18 12:26:34] -- Executing [s@default:2] Wait("PJSIP/6001-00000000", "3") in new stack
[Mar 18 12:26:35] -- Added contact 'sip:6000@192.168.0.168:48484;transport=udp' to AOR '6000' with expiration of 3600 seconds
[Mar 18 12:26:35] == Endpoint 6000 is now Reachable
[Mar 18 12:26:37] -- Executing [s@default:3] Dial("PJSIP/6001-00000000", "PJSIP/6000,45") in new stack
[Mar 18 12:26:37] -- Called PJSIP/6000
[Mar 18 12:26:38] -- PJSIP/6000-00000001 is ringing
[Mar 18 12:26:40] == Everyone is busy/congested at this time (1:0/0/1)
[Mar 18 12:26:40] -- Executing [s@default:4] GotoIf("PJSIP/6001-00000000", "1?9") in new stack
[Mar 18 12:26:40] -- Goto (default,s,9)
[Mar 18 12:26:40] -- Executing [s@default:9] Wait("PJSIP/6001-00000000", "2") in new stack
[Mar 18 12:26:42] -- Executing [s@default:10] Dial("PJSIP/6001-00000000", "PJSIP/6000,45") in new stack
[Mar 18 12:26:42] -- Called PJSIP/6000
[Mar 18 12:26:42] -- PJSIP/6000-00000002 is ringing
[Mar 18 12:26:48] == Everyone is busy/congested at this time (1:0/0/1)
[Mar 18 12:26:48] -- Executing [s@default:11] Hangup("PJSIP/6001-00000000", "") in new stack
[Mar 18 12:26:48] == Spawn extension (default, s, 11) exited non-zero on 'PJSIP/6001-00000000'

```

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [March 18, 2022, 12:29pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/4 "2022-03-18T12:29:25Z")

</div>

What is the actual SIP signaling? (pjsip set logger on). What is the actual value of DIALSTATUS?

---

<div class="post-metadata">

**Author:** ![NoFate](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/nofate/32/6511_2.png) [@NoFate](https://community.asterisk.org/u/NoFate)\
**Post date:** [March 18, 2022, 12:35pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/5 "2022-03-18T12:35:12Z")

</div>

hmm, not sure, dont see a dialstatus there?

```auto
<--- Transmitting SIP request (437 bytes) to UDP:192.168.0.168:48484 --->
OPTIONS sip:6000@192.168.0.168:48484;transport=udp SIP/2.0
Via: SIP/2.0/UDP 192.168.0.17:5060;rport;branch=z9hG4bKPje341024d-f2ba-4e7b-a203-799149ce478e
From: <sip:6000@192.168.0.17>;tag=2290d7de-173b-44ab-95ac-e42ec00deafa
To: <sip:6000@192.168.0.168>
Contact: <sip:6000@192.168.0.17:5060>
Call-ID: 3bbe9572-8af9-4189-9016-88146908e2e1
CSeq: 4630 OPTIONS
Max-Forwards: 70
User-Agent: Asterisk PBX 18.10.1
Content-Length: 0

<--- Received SIP response (391 bytes) from UDP:192.168.0.168:49765 --->
SIP/2.0 603 Decline
Via: SIP/2.0/UDP 192.168.0.17:5060;rport;branch=z9hG4bKPj2003b04c-aae1-4fea-8e96-c14b43efa7c5
From: "6001" <sip:6001@192.168.0.17>;tag=87b4e705-69d2-4191-91ae-8a404621569f
To: <sip:6000@192.168.0.168>;tag=Qw4q2tw
Call-ID: 1c8f6c4d-b3ea-4108-a2b1-4021d6353abd
CSeq: 6704 INVITE
User-Agent: LinphoneAndroid/2.1.730 (belle-sip/1.6.3)
Supported: replaces, outbound

<--- Transmitting SIP request (409 bytes) to UDP:192.168.0.168:49765 --->
ACK sip:6000@192.168.0.168:49765;transport=udp SIP/2.0
Via: SIP/2.0/UDP 192.168.0.17:5060;rport;branch=z9hG4bKPj2003b04c-aae1-4fea-8e96-c14b43efa7c5
From: "6001" <sip:6001@192.168.0.17>;tag=87b4e705-69d2-4191-91ae-8a404621569f
To: <sip:6000@192.168.0.168>;tag=Qw4q2tw
Call-ID: 1c8f6c4d-b3ea-4108-a2b1-4021d6353abd
CSeq: 6704 ACK
Max-Forwards: 70
User-Agent: Asterisk PBX 18.10.1
Content-Length: 0

  == Everyone is busy/congested at this time (1:0/0/1)
    -- Executing [s@default:4] GotoIf("PJSIP/6001-00000000", "1?9") in new stack
    -- Goto (default,s,9)
    -- Executing [s@default:9] Wait("PJSIP/6001-00000000", "2") in new stack
<--- Received SIP request (820 bytes) from UDP:192.168.0.168:49765 --->
REGISTER sip:192.168.0.17 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.168:49765;branch=z9hG4bK.qC-Ste1on;rport
From: <sip:6000@192.168.0.17>;tag=0tL1I8E91
To: sip:6000@192.168.0.17
CSeq: 23 REGISTER
Call-ID: cvJnDUJ3Eh
Max-Forwards: 70
Supported: replaces, outbound
Accept: application/sdp
Accept: text/plain
Accept: application/vnd.gsma.rcs-ft-http+xml
Contact: <sip:6000@192.168.0.168:49765;transport=udp>;+sip.instance="<urn:uuid:dc2169e5-5870-4374-8d64-1cdb1c9efc6b>"
Expires: 3600
User-Agent: LinphoneAndroid/2.1.730 (belle-sip/1.6.3)

```

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [March 18, 2022, 12:35pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/6 "2022-03-18T12:35:56Z")

</div>

You would need to adjust the dialplan in order to print out the value, for example using NoOp.

---

<div class="post-metadata">

**Author:** ![NoFate](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/nofate/32/6511_2.png) [@NoFate](https://community.asterisk.org/u/NoFate)\
**Post date:** [March 18, 2022, 12:40pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/7 "2022-03-18T12:40:05Z")

</div>

ah, i need to add this ath the top?

exten =\> s,1,NoOp(#### [default] ####)

sorry new to me 🙂

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [March 18, 2022, 12:42pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/8 "2022-03-18T12:42:27Z")

</div>

I’ve dug in a bit. From looking at the code stuff should be working, but it’s seemingly not. You can file an issue[1]. You’ll need to provide specific dialplan as well as the SIP trace. There is no time frame on when it would get looked into. You could see in the mean time if the hangup cause functionality[2] could be used instead. If you don’t know/understand dialplan though, you’re probably going to run into issues with it however.

[1] [System Dashboard - Digium/Asterisk JIRA](https://issues.asterisk.org/jira)  
[2] [Hangup Cause - Asterisk Project - Asterisk Project Wiki](https://wiki.asterisk.org/wiki/display/AST/Hangup+Cause)

---

<div class="post-metadata">

**Author:** ![NoFate](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/nofate/32/6511_2.png) [@NoFate](https://community.asterisk.org/u/NoFate)\
**Post date:** [March 18, 2022, 12:47pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/9 "2022-03-18T12:47:06Z")

</div>

ok, maybe i can do it the other way around, seems if i decline

this line is activated :

`exten => s,5,GotoIf($[${DIALSTATUS} = CHANUNAVAIL]?12)`

I used that line on chan\_sip before, it the endpoint was not registered, in that case it did a retry

Is there maybe aonther wat like the line above, that i can use to find out if 6000 is registered or not?

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [March 18, 2022, 12:47pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/10 "2022-03-18T12:47:57Z")

</div>

There is the DEVICE\_STATE dialplan function[1].

[1] [Asterisk 19 Function\_DEVICE\_STATE - Asterisk Project - Asterisk Project Wiki](https://wiki.asterisk.org/wiki/display/AST/Asterisk+19+Function_DEVICE_STATE)

---

<div class="post-metadata">

**Author:** ![NoFate](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/nofate/32/6511_2.png) [@NoFate](https://community.asterisk.org/u/NoFate)\
**Post date:** [March 18, 2022, 12:49pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/11 "2022-03-18T12:49:44Z")

</div>

ok thnx ill have a look

---

<div class="post-metadata">

**Author:** ![NoFate](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/nofate/32/6511_2.png) [@NoFate](https://community.asterisk.org/u/NoFate)\
**Post date:** [March 18, 2022, 12:57pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/12 "2022-03-18T12:57:46Z")

</div>

hmm not 100% clear to be

is it enough if i convert this:

exten =\> s,8,GotoIf($[${DIALSTATUS} = BUSY]?10)

to  
exten =\> s,8,GotoIf($[${DEVICE\_STATE} = BUSY]?10)

---

<div class="post-metadata">

**Author:** ![PitzKey](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/pitzkey/32/5827_2.png) [@PitzKey](https://community.asterisk.org/u/PitzKey)\
**Post date:** [March 18, 2022, 1:41pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/13 "2022-03-18T13:41:35Z")

</div>

> [@NoFate](#):
>
> ah, i need to add this ath the top?
> 
> exten =\> s,1,NoOp(#### [default] ####)

You need this after the Dial() so you can read what Asterisk set the dial status to.

```auto
Noop(Dial status: ${DIALSTATUS})

```

---

<div class="post-metadata">

**Author:** ![PitzKey](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/pitzkey/32/5827_2.png) [@PitzKey](https://community.asterisk.org/u/PitzKey)\
**Post date:** [March 18, 2022, 1:44pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/14 "2022-03-18T13:44:01Z")

</div>

> [@NoFate](#):
>
> is it enough if i convert this:
> 
> exten =\> s,8,GotoIf($[${DIALSTATUS} = BUSY]?10)
> 
> to  
> exten =\> s,8,GotoIf($[${DEVICE\_STATE} = BUSY]?10

Device state tells you the state of the endpoint, not the channel.

Device state can help you retry if the device is not online, but won’t help you if you declined the call.

---

<div class="post-metadata">

**Author:** ![NoFate](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/nofate/32/6511_2.png) [@NoFate](https://community.asterisk.org/u/NoFate)\
**Post date:** [March 18, 2022, 1:57pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/15 "2022-03-18T13:57:11Z")

</div>

Ah ok, any idea then how I can intercept the decline some other way?

---

<div class="post-metadata">

**Author:** ![jwilhite](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jwilhite/32/4075_2.png) [@jwilhite](https://community.asterisk.org/u/jwilhite)\
**Post date:** [March 18, 2022, 3:31pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/16 "2022-03-18T15:31:18Z")

</div>

Yes, you can use HANGUPCAUSE\_KEYS to retrieve the actual SIP response sent by the endpoint after the dial fails:

same =\> n,Set(HANGUPCAUSEKEYS=${HANGUPCAUSE\_KEYS()})  
same =\> n,GotoIf($[${LEN(${HANGUPCAUSEKEYS})}=0]?logError)  
same =\> n,Set(ARRAY(item)=${HANGUPCAUSEKEYS})  
same =\> n,Set(SIPCAUSE=${HANGUPCAUSE(${item},tech)})  
same =\> n,Set(SIPCAUSECODE=${CUT(SIPCAUSE, ,2)})  
same =\> n,GotoIf($["${SIPCAUSECODE}" != “603”]?callDeclined)  
…  
same =\> n(callDeclined),

HANGUPCAUSE will return something like “SIP 603 Decline”, so we have to use CUT to extract the 2nd item in the space-delimited string in order to get the integer response code.

BTW, you don’t have to number all the lines in your subroutine. Just use ‘exten’ on the first line, then use the “same =\> n,” syntax on all the others. If you need to jump to a specific line, you can give it a label after the “n” like I did with callDeclined there.

---

<div class="post-metadata">

**Author:** ![NoFate](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/nofate/32/6511_2.png) [@NoFate](https://community.asterisk.org/u/NoFate)\
**Post date:** [March 18, 2022, 3:43pm UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/17 "2022-03-18T15:43:49Z")

</div>

aha, thats interesting info, something for next week

thnx in advance

---

<div class="post-metadata">

**Author:** ![NoFate](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/nofate/32/6511_2.png) [@NoFate](https://community.asterisk.org/u/NoFate)\
**Post date:** [March 29, 2022, 8:20am UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/18 "2022-03-29T08:20:16Z")

</div>

hey, was working back on this one

is it maybe possible to provide your full example?

---

<div class="post-metadata">

**Author:** ![NoFate](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/nofate/32/6511_2.png) [@NoFate](https://community.asterisk.org/u/NoFate)\
**Post date:** [March 29, 2022, 8:24am UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/19 "2022-03-29T08:24:39Z")

</div>

Was just testing below, so when 6000 declines, it should redial?

is that ok?

```auto
exten => 2,1,Dial(PJSIP/6000,45)
 same => n,Set(HANGUPCAUSEKEYS=${HANGUPCAUSE_KEYS()})
 same => n,GotoIf($[${LEN(${HANGUPCAUSEKEYS})}=0]?logError)
 same => n,Set(ARRAY(item)=${HANGUPCAUSEKEYS})
 same => n,Set(SIPCAUSE=${HANGUPCAUSE(${item},tech)})
 same => n,Set(SIPCAUSECODE=${CUT(SIPCAUSE, ,2)})
 same => n,GotoIf($["${SIPCAUSECODE}" != "603"]?callDeclined)
 same => n(callDeclined)
 same => n,Wait(3)
 same => n,Dial(PJSIP/6000,45)

```

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [March 29, 2022, 10:28am UTC](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009/20 "2022-03-29T10:28:00Z")

</div>

I’m not sure you can have a priority without an action.

GotoIf only to the next priority is pretty pointless.

A true target name that implies the reverse of the actual condition is very confusing.

There may be problems with the extraction of the cause code, but I’m not familiar enough with that to check it.

[Next page](https://community.asterisk.org/t/converting-sip-to-pjsip-i-need-dialstatus-is-it-changed/92009.md?page=2)
