I want to call two numbers and fuse the channels but Invite isn't set as expected

Hi everyone,
I’m trying to set a kamailio in front of my asterisk infrastructure to secure it and allow HA.

I’m having problems making calls from console/AMI to two different phone numbers because the second call sets “To” header as the first phone number (this explanaition is very poor, i’ll attach a few images to popperly explain it)[1]
I’m making this calls using a small python script[2], i’m not sure if there’s something missing or if i need to change something on my kamailio config to handle this scenario. Our phone provider seems to have no problem with us sending the INVITE like this instead of setting “From” header with their phone number

Thank you in advance for your help

[1] Check “From” and “To” headers
First call from 911XXXXXX (number our SIP provider gave us) to 590XXXXXX (one of our phone numbers)

Second call instead of calling from 911XXXXXX (number our SIP provider gave us) to 606XXXXXX (one of our phone numbers). It calls from 590XXXXXX to 606XXXXXX

[2]Python script

import socket
import time

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((IpAmi, PortAmi))
AmiLogin(User, Password)
time.sleep(1) # Dar tiempo para que el login surta efecto
ChannelOriginate_dial(‘590XXXXXXXXX’,‘606XXXXXX’)
while True:
bus=s.recv(1024)
events=bus.decode(“utf-8”)
print(events)
time.sleep(10)
AmiLogoff()
s.close()

def AmiLogin(user, password):
s.send(“Action: Login\nUsername: {}\nSecret: {}\nEvents: on\n\n”.format(user, password).encode())

def ChannelOriginate_dial(destino,destino2):
s.send(“Action: Originate\n”.encode())
s.send(“ActionID: \n”.encode())
cchannel = “Channel: Local/”+destino+“@ctx-from_sip\n”
s.send(cchannel.encode())
cexten = “Exten:”+destino+“\n”
s.send(cexten.encode())
s.send(“Context: ctx-from_sip\n”.encode())
s.send(‘Priority: 1\n’.encode())
s.send(“Application: Dial\n”.encode())
cchannel2 = “Data: Local/”+destino2+“@ctx-from_sip\n”
s.send(cchannel2.encode())
s.send(“\n”.encode())

What it is doing sounds sensible to me, even though it conflicts with recent anti-abuse developments. I think you will need to set the caller ID in the local channel, or set from user in the endpoint definition.

Hi David,
Thank you for your reply. I’m not sure if i understood what you are saying, but this is not related with anything ilegal. We do this in order to check if our devices works propperly.
Our devices only receive calls and to manually check them we use this script to call the phone number on the device and the phone number of our technician.

Apart from that, how can i set the caller ID in the channel? Is there any parameter to set it?
I cannot change it in our endpoint because our service provider gives us multiple phone numbers on the same trunk.

Again, thank you for your reply.

I don’t understand how the from user got set on the A side. Normally that would either come from the caller ID parameter to Originate, or the From user in the endpoint definition. If you are allowed more than one caller ID on the endpoint, the correct one has to be set, somewhere.

To set the caller ID for the B side, I believe you will need to use Set(CALLEREDID(num)=…) in the local channel.

I wasn’t suggesting anything illegal. I was just pointing out that the default behaviour of passing the caller ID through would cause the call to fail with many providers.

Sending sip URIs over a TLS transport looks wrong.

Hi David,

Thank you for your reply. I’ll try to set the calleredid(num)

I will also talk to our provider to see if the can throw some light on this. I’m sorry about the confusion, english is not my main language and i misundertood

Hi again David,

I tried to make a call using this command on asterisk CLI “channel originate Local/606XXXXXX@ctx-from_sip extension 648XXXXXX@ctx-from_sip”

This references to this part of the dialplan
[ctx-from_sip]
exten => _[6-9]XXXXXXXX,1,NoOp(LLAMADA SALIENTE CON ${UNIQUEID} desde la extesion ${CALLERID(num)} hacia ${EXTEN})
exten => _[6-9]XXXXXXXX,n,Answer()
exten => _[6-9]XXXXXXXX,n,Set(CALLERID(num)=${NUM_SALIENTE})
exten => _[6-9]XXXXXXXX,n,DIAL(PJSIP/kamailio/sip:${EXTEN}@${KAMAILIO},U(get-id^${CALLERID(num)}^${EXTEN}))
exten => _[6-9]XXXXXXXX,n,Hangup()

Asterisk CLI shows that it executes Set(CALLERID(num)=${NUM_SALIENTE}) on both calls

– Executing [648XXX@ctx-from_sip:3] Set(“Local/606XXXXXX@ctx-from_sip-00000000;1”, “CALLERID(num)=911XXXXXX”) in new stack
– Executing [606XXXXXX@ctx-from_sip:3] Set(“Local/606XXXXXX@ctx-from_sip-00000000;2”, “CALLERID(num)=911XXXXXX”) in new stack

But asterisk CLI pjsip show history shows that on the second call it doesn’t change the CALLERID(num)


I’m not sure if I’m doing something wrong or if there’s something i’m missing.

What does context getcallerid do?

I’m sorry David.

There was a typo in my dialplan and that was causing all the problems

Thank you very much for all your help. You were right i just needed to set CALLERID(num)

I’ll mark it as solved

Again thank you for your help

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