A person who repeatedly calls different numbers has a connection problem.

Hello, we have two different phone numbers from two companies with local SIP providers in Turkey (NetGSM And Verimor) . We use Retell to forward these numbers. However, we’re having a problem. After calling number A and hanging up, when the user calls number B, the phone just rings and then hangs up with the unreachable error message provided by the provider. I think the problem might be caused by Retell, because it still states that the number calling has a call, even though it doesn’t. Could this be the reason?

We also use Python to retrieve information such as the agent-id of the phone number, the user’s name, and meeting information :

    def transfer_to_retell(self):
        """Ana fonksiyon - aramayı Retell AI'ya yönlendirir"""
        
        # Gelen arama bilgilerini al
        caller_id = self.agi_env.get('agi_callerid', 'Unknown')
        called_number = self.agi_env.get('agi_dnid', self.agi_env.get('agi_extension', self.default_phone))
        
        self.log(f"Gelen arama: {caller_id} -> {called_number}")
        
        # Retell AI'ya kaydol ve SIP URI al
        sip_uri = self.register_call_with_retell(caller_id, called_number)
        
        if sip_uri:
            # Settings'den dial timeout'u al
            settings = self.agent_config.get('settings', {}) if self.agent_config else {}
            dial_timeout = settings.get('dial_timeout', 30)
            
            # Retell'e yönlendir - Load balancing ile
            endpoint = get_next_endpoint()
            dial_string = f"PJSIP/{endpoint}/{sip_uri}"
            self.log(f"Retell'e yonlendiriliyor: {dial_string} (Endpoint: {endpoint})")
            
            # Aramayı yönlendir - AGI EXEC komutu kullan
            result = self.agi_command(f'EXEC Dial "{dial_string},{dial_timeout},r"')
            self.log(f"Dial sonucu: {result}")
            

            
        else:
            self.log("Retell SIP URI alinamadigi icin arama sonlandiriliyor")
            self.agi_command('EXEC Playback "im-sorry"')
            self.agi_command('EXEC Hangup')

extensions.conf :

[general]
static=yes
writeprotect=no

[from-netgsm]
; NetGSM 's' extension
exten => s,1,NoOp(Incoming call to s: ${CALLERID(all)})
exten => s,n,AGI(/usr/local/bin/retell_integration.py)
exten => s,n,Hangup()

; Ana numara
exten => TEL_NO_A,1,NoOp(Call to main number: ${CALLERID(all)})
exten => TEL_NO_A,n,AGI(/usr/local/bin/retell_integration.py)
exten => TEL_NO_A,n,Hangup()

; Diğer numaralar
exten => _X.,1,NoOp(Incoming call from NetGSM: ${CALLERID(all)} to ${EXTEN})
exten => _X.,n,AGI(/usr/local/bin/retell_integration.py)
exten => _X.,n,Hangup()

[from-verimor]
; Verimor gelen aramalar - 90TEL_NO_B
exten => s,1,NoOp(Verimor: ${CALLERID(all)})
exten => s,n,AGI(/usr/local/bin/retell_integration.py)
exten => s,n,Hangup()

exten => _X.,1,Goto(s,1)
exten => 90TEL_NO_B,1,Goto(s,1)
exten => TEL_NO_B,1,Goto(s,1)

[from-retell]
; Retell AI'dan gelen çağrılar için
exten => _X.,1,NoOp(Retell AI call: ${CALLERID(all)})
exten => _X.,n,Answer()
exten => _X.,n,Wait(1)
exten => _X.,n,Hangup()

[default]
; Test
exten => 100,1,Answer()
exten => 100,n,Playback(hello-world)
exten => 100,n,Hangup()

pjsip.conf - I tried the method of selecting multiple endpoints using the random module in Python and then registering the call, but I was unsuccessful. The result is still the same :

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0:5060


[netgsm]
type=endpoint
context=from-netgsm
disallow=all
allow=ulaw
allow=alaw
direct_media=no

[netgsm-identify]
type=identify  
endpoint=netgsm
match=sip.netgsm.com.tr

; Verimor - Yeni
[verimor]
type=endpoint
context=from-verimor
disallow=all
allow=ulaw
allow=alaw
allow=g729
direct_media=no

[verimor-identify]
type=identify
endpoint=verimor
match=sip.verimor.com.tr
match=sip2.verimor.com.tr


; Retell AI Endpoints
[retell-generic-1]
type=endpoint
context=from-retell
disallow=all  
allow=ulaw
allow=alaw
direct_media=no

[retell-generic-2]
type=endpoint
context=from-retell
disallow=all  
allow=ulaw
allow=alaw
direct_media=no

[retell-generic-3]
type=endpoint
context=from-retell
disallow=all  
allow=ulaw
allow=alaw
direct_media=no

[retell-generic-4]
type=endpoint
context=from-retell
disallow=all  
allow=ulaw
allow=alaw
direct_media=no

[retell-generic-5]
type=endpoint
context=from-retell
disallow=all  
allow=ulaw
allow=alaw
direct_media=no

You need to troubleshoot and verify assumptions. Start with the most basic question: Did the call get to Asterisk? If the answer is yes then that eliminates the incoming leg. Move on to Did the call get sent to Retell? If the answer is yes then your routing logic is correct. Did Retell reject the call? If the answer is yes, then you’ve determined it is Retell.

An endpoint just defines the configuration to use for an outgoing call. It wouldn’t change anything further.

On Monday 25 August 2025 at 13:00:06, kker4m via Asterisk Community wrote:

Hello, we have two different phone numbers from two companies with local
SIP providers in Turkey (NetGSM And Verimor).

Are these inbound numbers pointing at an Asterisk server?

We use Retell to forward these numbers.

Please explain exactly what that means.

However, we’re having a problem. After calling number A

Who is doing the calling? Someone out on the public telephone network?
Someone on a SIP phone connected to your Asterisk server? Please be clear
about where calls are being made from, and where they are expected to get
answered.

and hanging up, when the user calls number B,

“User” suggests to me that this is someone inside your own network (ie:
directly connected to your Asterisk server) but I am unhappy with making
assumptions.

the phone just rings and then hangs up with the unreachable error message
provided by the provider.

Tell us exactly what is going on in SIP terms. What is the respose to the
Invite?

I think the problem might be caused by Retell, because it still states that
the number calling has a call, even though it doesn’t. Could this be the
reason?

We don’t know until you tell us how all this is connected together. You
haven’t even said where your Asterisk server is located in this setup.

Antony.


Is it venison for dinner again? Oh deer.

Don’t think the problem is retell right now, when we try from two different phone numbers, two different target phone number, and two different retell api and agent, the result is same. One can talk, the other one can’t. Can’t Asterisk handle asynchronous calls by default? I got the error “SIP/2.0 481 Call/Transaction Does Not Exist” From second call in a chronic way

The problem turned out to be the firewall. Disabling ufw and iptables fixed the problem. We must have implemented too many restrictions. Thank you all of you :+1:.

1 Like

On Monday 25 August 2025 at 23:08:03, kker4m via Asterisk Community wrote:

The problem turned out to be the firewall.

I can only say that “providing more information about the network
configuration, the actual calls involved, and the SIP communications which
resulted, could have resolved this much more efficiently”.

Please, if you need to ask a question in future, provide enough information
that we can understand what your network setup is, what your Asterisk
configuration is, and what the SIP problem is.

If we don’t have enough information to replicate your setup, we might not be
able to provide a useful answer.

Antony.


Never write it in Perl if you can do it in Awk.
Never do it in Awk if sed can handle it.
Never use sed when tr can do the job.
Never invoke tr when cat is sufficient.
Avoid using cat whenever possible.

Almost always the firewall. Glad it’s fixed and that you posted back your resolution. As @Pooh mentioned for the next question. More is good!