Hello
I have an Asterisk (Asterisk 16.28.0~dfsg-0+deb11u10) set up for connecting my phone provider (O2) to ElevenLabs using SIP trunk.
The problem I’m facing is that whether I get REFER message from Elevenlabs, the Asterisk responds with error 400 Bad request and I’ve been unable to further diagnose the issue (I’ve tried looking up forums and discussing with large language models for days at this point).
I’m using TLS, have my domain verified and certificate done by the Certbot. I can normally talk to the Elevenlabs, even the BYE message gets interpreted fine, but I’m still struggling with the REFER message ending up with 400.
My dialplan:
[from-elevenlabs-trunk]
; Match any refer, regardless of the URI scheme
exten => _.,1,NoOp(— REFER RECEIVED: URI=${REFER_TO} —)
same => n,Set(TARGET=${FILTER(0-9,${EXTEN})})
same => n,NoOp(— CLEANED TARGET: ${TARGET} —)
same => n,Dial(PJSIP/${TARGET}@o2-trunk)
same => n,Hangup()
[from-o2]
exten => +420371585438,1,NoOp(ElevenLabs test inbound)
same => n,Answer()
; Add ‘t’ and ‘T’ flags to allow transfers
; ‘t’ allows the CALLED party (you) to transfer
; ‘T’ allows the CALLING party (original caller) to transfer
same => n,Dial(PJSIP/+420371585438@elevenlabs,120,tgT)
same => n,Hangup()
**
My PJSIP configuration:**
[global]
type=global
[o2-endpoint]
type=endpoint
transport=transport-udp
context=from-o2
disallow=all
allow=alaw
outbound_auth=o2-auth
aors=o2-aor
from_user=[PHONE_NUMBER]
from_domain=voipmenu.cz
rtp_symmetric=yes
force_rport=yes
rewrite_contact=yes
direct_media=no
[o2-aor]
type=aor
max_contacts=1
remove_existing=yes
[o2-auth]
type=auth
auth_type=userpass
username=+[PHONE_NUMBER]@voipmenu.cz
password=[PASSWORD]
realm=voipmenu.cz
[o2-registration]
type=registration
transport=transport-udp
outbound_auth=o2-auth
server_uri=sip:88.103.241.62
client_uri=sip:+[PHONE_NUMBER]@voipmenu.cz
contact_user=[PHONE_NUMBER]
retry_interval=30
forbidden_retry_interval=300
expiration=3600
auth_rejection_permanent=no
[o2-identify]
type=identify
endpoint=o2-endpoint
match=88.103.241.62
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0:5060
external_signaling_address=[MY_PUBLIC_IP]
external_media_address=[MY_PUBLIC_IP]
local_net=10.0.1.0/24
[transport-tcp]
type=transport
protocol=tcp
bind=0.0.0.0:5060
external_signaling_address=[MY_PUBLIC_IP]
external_media_address=[MY_PUBLIC_IP]
local_net=10.0.1.0/24
[transport-tls]
type=transport
protocol=tls
bind=0.0.0.0:5061
method=tlsv1_2
; Allow a broader range of compatible ciphers
verify_server=no
cert_file=[PATH]/fullchain.pem
priv_key_file=[PATH]/privkey.pem
external_media_address=[MY_PUBLIC_IP]
external_signaling_address=[MY_PUBLIC_IP]
local_net=10.0.0.0/8
verify_server=no
verify_client=no
[elevenlabs]
type=endpoint
transport=transport-tls
context=from-elevenlabs-trunk
disallow=all
allow=ulaw
from_domain=sip.rtc.elevenlabs.io
aors=elevenlabs-aor
outbound_auth=elevenlabs-auth
rtp_symmetric=yes
force_rport=yes
rewrite_contact=yes
direct_media=no
asymmetric_rtp_codec=yes
allow_transfer=yes
refer_blind_progress=yes
refer_context=from-elevenlabs-trunk
transfer_prohibit_multi_party=yes
[elevenlabs-aor]
type=aor
max_contacts=1
contact=sip:sip.rtc.elevenlabs.io:5061\;transport=tls
context=from-elevenlabs-trunk
[elevenlabs-auth]
type=auth
auth_type=userpass
username=asterisk
password=[PASSWORD]
Here’s probably the most relevant bit from the logs I’ve got displaing the error 400. The call just hangs right after that, probably as a consequence of that error happening. Elevenlabs sees this too and marks the call as unsuccesfull:
**--** PJSIP/elevenlabs-00000017 answered PJSIP/o2-endpoint-00000016
**--** Channel PJSIP/elevenlabs-00000017 joined 'simple_bridge' basic-bridge <4d35215b-5fe1-41ea-9c6f-39976efa6748>
**--** Channel PJSIP/o2-endpoint-00000016 joined 'simple_bridge' basic-bridge <4d35215b-5fe1-41ea-9c6f-39976efa6748>
<— Received SIP request (662 bytes) from TLS:136.114.67.172:54000 —>
REFER sip:asterisk@90.178.237.94:5061;transport=TLS SIP/2.0
Via: SIP/2.0/TLS 136.114.67.172:5060;branch=z9hG4bK.jjecNNRzqiUatNAv;alias
Max-Forwards: 70
Call-ID: 5f0bd47d-0fba-4ddc-a736-9e895230b0e3
Contact: sip:ip-136-114-67-172.host.rtc.elevenlabs.io:5061;transport=tls
Refer-To: tel:+420721605869
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
X-Conversation-ID: conv_5901kvtb0ghgf99s5nmjf68xh5k5
X-Caller-ID: 721605869
Content-Length: 0
CSeq: 26778 REFER
From: sip:+420371585438@sip.rtc.elevenlabs.io;tag=SCL_yFKYaV33QnWG
To: sip:721605869@sip.rtc.elevenlabs.io;tag=61db6ef1-43d9-444e-922d-acea8e7b4c84
<— Transmitting SIP response (425 bytes) to TLS:136.114.67.172:54000 —>
SIP/2.0 400 Bad Request
Via: SIP/2.0/TLS 136.114.67.172:5060;rport=54000;received=136.114.67.172;branch=z9hG4bK.jjecNNRzqiUatNAv;alias
Call-ID: 5f0bd47d-0fba-4ddc-a736-9e895230b0e3
From: sip:+420371585438@sip.rtc.elevenlabs.io;tag=SCL_yFKYaV33QnWG
To: sip:721605869@sip.rtc.elevenlabs.io;tag=61db6ef1-43d9-444e-922d-acea8e7b4c84
CSeq: 26778 REFER
Server: Asterisk PBX 16.28.0~dfsg-0+deb11u10
Content-Length: 0
<— Received SIP request (393 bytes) from TLS:136.114.67.172:54000 —>
BYE sip:asterisk@90.178.237.94:5061;transport=TLS SIP/2.0
Via: SIP/2.0/TLS 136.114.67.172:54000;branch=z9hG4bK.lJdWErOGpCy88Seh;alias
Max-Forwards: 70
Call-ID: 5f0bd47d-0fba-4ddc-a736-9e895230b0e3
Content-Length: 0
CSeq: 26779 BYE
From: sip:+420371585438@sip.rtc.elevenlabs.io;tag=SCL_yFKYaV33QnWG
To: sip:721605869@sip.rtc.elevenlabs.io;tag=61db6ef1-43d9-444e-922d-acea8e7b4c84
Any help or suggestion is highly appreciated. Thank you ![]()