Outgoing pjsip line for Twilio won't work

I have a Twillo account I need to call out on from PJSIP. It works fine with my sip.conf but I’m failing with PJSIP. Any help would be appreciated.

Working sip.conf:

[general]
bindaddr = 0.0.0.0   ; Address to bind to (all addresses on machine)
bindaddr = 192.168.2.2   ; Address to bind to (all addresses on machine)
bindport=5060
port=5060
disallow=all
allow=ulaw
context=mystery_sip  ; Send unknown SIP callers to this context
pickupgroup=1
group=1
allowguest=no
dtmfmode=auto ; rfc2833
localnet=192.168.2.0/255.255.255.0
externrefresh=600
alwaysauthreject=yes
srvlookup=yes
preferred_codec_only=yes
useragent=MyPBX
notifyhold=yes
directmedia=yes
session-timers=originate
session-expires=2400
session-minse=300
session-refresher=uas
sendrpid=yes
trustrpid=yes
callcounter=yes
nat=force_rport,comedia
autocreatepeer=no
callevents=yes
    


[Twilio]
host=pbx.pstn.twilio.com
remotesecret=password
defaultuser=name
type=friend
secret=password
bindport=5060
port=5060
udpenable=yes
tcpenable=yes
preffered_codec_only=yes
fromdomain=pbx.pstn.twilio.com
context=Twilio
insecure=port,invite ; very
disallow=all
allow=ulaw ;,g729
dtmfmode=rfc2833 ; auto
qualify=55000
canreinvite=no
limitonpeers=yes
call-limit=23

And my failing pjsip.conf:

[simpletrans]
type=transport
protocol=udp
bind=0.0.0.0
allow_reload=no
tos=cs3
cos=3
local_net=192.168.2.0/24
external_media_address=myip.no-ip.biz
external_signaling_address=myio.no-ip.biz

[tcptrans]
type=transport
protocol=tcp
bind=0.0.0.0
allow_reload=no
tos=cs3
cos=3
local_net=192.168.233.0/24
local_net=192.168.211.0/24
external_media_address=extrasensory.no-ip.biz
external_signaling_address=extrasensory.no-ip.biz

;===============TRUNK
[simpletrans]
type=transport
protocol=udp
bind=0.0.0.0
allow_reload=no
tos=cs3
cos=3
local_net=192.168.2.0/24
local_net=192.168.2.0/24
external_media_address=myip.no-ip.biz
external_signaling_address=myip.no-ip.biz

[TwilioOut]
type=endpoint
transport=simpletrans
allow=!all,ulaw
auth=TwilioOutAuth
aors=TwilioOut

[TwilioOutAuth]
type=auth
auth_type=userpass
password=password
username=name

[TwilioOut]
type=aor
contact=sip:name@pbx.pstn.twilio.com
contact=sip:pbx.pstn.twilio.com

The dial line is:

  same => n(normalcall),dial(PJSIP/TwilioOut/+13101234567,,g)
From the log:
[s@x:5]Dial("PJSIP/174-00000002", "PJSIP/TwilioOut/+1310123567) in new stack

Error messages:

[2023-09-17 11:56:56] ERROR[102420] res_pjsip.c: Endpoint 'TwilioOut': Could not create dialog to invalid URI '+13101234567'.  Is endpoint registered and reachable?
[2023-09-17 11:56:56] ERROR[102420] chan_pjsip.c: Failed to create outgoing session to endpoint 'TwilioOut'

[2023-09-17 11:56:56] NOTICE[102447][C-00000001] app_dial.c: Unable to create channel of type 'PJSIP' (cause 3 - No route to destination)
[2023-09-17 11:56:57] NOTICE[102447][C-00000001] Ext. h: "****** Call from 1 to (13101234567) Sun Sep 17 11:56:57 2023   CHANUNAVAIL  02PJSIP/TwilioOut/+  3"

The dial string format is:

PJSIP/+13101234567@TwilioOut

This is an inbound authentication, but remotesecret is an outbound one. This won’t hit you until you fix the first one.

Specifying all of remotesecret, secret, and insecure=invite does not make sense. Either you are authenticating inbound calls, in which case youi must not make them insecure, or you are not, in which case secret is redundant with respect to remoteseceret.

Most people don’t need to make the port insecure, when using UDP.

defaultuser does nothing without host=dynamic

type=friend is a bad idea except in certain special cases.

(I think the very setting was intended to discourage people from using that value, but it didn’t work; everyone uses it blindly. I think removing it was supposed to make people think which of the values were actually needed, but it didn’t work, because providers blindly translated very to both, and users blindly follow the provider’s example.)

Thankyou so much. The corrected dial string and “remotesecret” were the clues I needed, though for pjsip it seems to be remote_auth and it took a bit of searching to find that, but now pjsip finally works. All that stuff in sip.conf will no longer be used. I started that sip.conf for Asterisk V 1.4 and as long as it worked I was happy. I really like using Asterisk, but I’ve always struggled with understanding all the options for SIP and it’s been an on and off quest, but I’ve been attempting the switch to pjsip for longer than I care to admit. I would think that Twilio would want to provide sample configurations, especially since they’ve announced that sip will stop working soon, but they seem to have no interest. I don’t remember seeing any example configurations with outbound_auth and I’ve searched as best as I can to try and solve the problem.

My current working outbound Twilio configuration:


;===============TRUNK
[simpletrans]
type=transport
protocol=udp
bind=0.0.0.0
allow_reload=no
tos=cs3
cos=3
local_net=192.168.2.0/24
local_net=192.168.2.0/24
external_media_address=myip.no-ip.biz
external_signaling_address=myip.no-ip.biz

[TwilioOut]
type=endpoint
transport=simpletrans
allow=!all,ulaw
outbound_auth=TwilioOutAuth
aors=TwilioOut

[TwilioOutAuth]
type=outbound_auth
auth_type=userpass
password=password
username=name

[TwilioOut]
type=aor
contact=sip:name@pbx.pstn.twilio.com
contact=sip:pbx.pstn.twilio.com

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