Setting CALLERID(num) when placing calls to a list of channels

I am running: Asterisk 20.7.0 built by pi @ raspberrypi on aarch64 running Linux built on 2024-04-02 16:50:39 UT. I am constructing a “domestic” digital exchange using two sip channels (not trunks) and perhaps 20 endpoints including mobiles and SIP softphones. By definition I do not have DID numbers.

I wish to ring a number of endpoints, the first to pick up answers.

Just using something like: same => n,Dial(PJSIP/70&PJIP/63&PJSIP/84)

But, the callees are a mixture:
simple internal extensions as above
some will be pstn numbers 01234567890-
some will be sip: addresses i.e. firstname.lastname@sip.linphone.com

Mostly the callee numbers are harvested from the contact = of some AOR entries
My exchange is not visible for inbound connections from the internet. For a sip return call it is necessary to use sip:id at my sip service provider e.g. 12345678@sip.aql.com.
In order to place outbound calls destined for PSTN my sip service provider needs the CALLERID(num) to be my sip id. They replace that with the appropriate PSTN number.

Asterisk seems to contact firstname.lastname@sip.linphone.org directly, not passing through the sip service provider.

I am trying to find a way of changing the CALLERID(num) of the caller depending on called number.

I have tried pre dial subroutines. If I use the “caller” subroutine it changes it once to the 12345678 of my sip provider id which works well for PSTN numbers. It is then used in the From line for all dials.
Not so good for either internal extensions or for firstname.lastname@sip.linphone.org receivers.

If I use the callee subroutine, it would appear to be too late to change the callerid in the “from” header so PSTN numbers fail and firstname.lastname@sip.linphone.org recipients get an internal number like 93@sip.myinternalserver.com which cannot be called.

So, the ring group sort-of works in that all the phones ring out, but the callerid means nothing to most of them.

Can anyone help in suggesting a method of changing the outbound header “From” depending on the destination channel to be used i.e. internal, sipservice or directly on the internet when using dial() list of callees?

Any pre-dial handler would need to be on the callee channel. If that doesn’t work, you would need to use local channels, although simply setting from user on endpoint for the PSTN connection would handle that case.

SIP and Asterisk do not have a concept of a trunk. The FreePBX world uses trunk to mean any endpoint on another switch, in particular an ITSP, but does not require that it supports multiple simultaneous calls.

DID is another term that I consider misuse, and which is not defined by Asterisk or SIP, but, in your description, 12345678 is what the FreePBX world would consider to be your DID.

I’m not aware of any service provide that would allow it to do anything else, so I’m not sure of the relevance of the above.

1 Like

Thanks David551 - I appreciate that you spent time to answer. I will investigate how to do “setting from user on the endpoint”.
The only reason I even mentioned trunk was that the large example that I installed with Asterisk goes on at length about trunks and DIDs - by which it seems to mean "a block of (sequential??) numbers allocated by the service provider (say 20 numbers). Those twenty can then be used as the internal numbers, the external ones being made by prefixing more digits. As you can tell, I am an Asterisk virgin so to speak.
The only reason that I wrote about firstname.lastname@sip.linphone.org not passing the service provider was that I am behind a NAT firewall (on a fixed IP address) and have ports opened only to the service provider. Nowhere had I read that the “Dial” application, even when given the service provider endpoint, would go directly to the callee sip address (and it worked despite NAT and firewall) - just my confusion, sorry. Anyway, today I will be experimenting how to change the user on the service provider endpoint so that it appears in the “From” line of the sip message. Thanks once again for your clarity.

This is the true meaning of DID, but the VoIP community uses it to simply mean a PSTN number allocated to you (it is probably part of a direct in dialling group at the ITSP’s interface with the PSTN.

A trunk really means a connection that can handle multiple simultaneous calls. With simple analogue, this would have been multiple copper pairs, and particularly, where there are physical limits, where it is possible for all the calls to have the same local number. Even before VoIP, it came to mean a connection to another switch, typically one that was not very close, but in VoIP terms, it is particularly used to refer to an account with a VoIP to PSTN service provider.

I presume that the firewall is generating a temporary rule for reciprocal routing to your outbound requests. If you sent that linphone URI to your normal ITSP, they would either refuse it completely , or would ignore the doman name and try to interpret the user part as a PSTN number. They would not proxy, or otherwise forward, it to the domain you provided. SIP is designed for such direct connections, but almost everybody refuses to accept them, for security, and because they want to emulate being part of the PSTN.

Thanks very much for your advice again. Your suggestion to use “from_user” in the endpoint worked just fine; I had spent two days trying to fix it with CALLERID changes!

I think I now “get” the confusion around “trunk”. I have two single call accounts, both bound to pstn numbers. Both send in external calls - that is working just fine. I use “match_header” on “contact_user” to distinguish.

Regarding calls to sip addresses as opposed to pstn, for test purposes I use a crude dial thus:

exten = 95,1,Verbose(1, "User ${CALLERID(num)} dialed ${EXTEN}.")
 same = n,Dial(PJSIP/aql-endpoint/sip:firstlast@sip.linphone.org)
 same = n,Goto(dialed-${DIALSTATUS},1)

But, it strikes me that, although I give it the endpoint of the SIP service provider, it uses almost nothing from it. Should I not construct another endpoint specially for sip calls? It sounds like the correct thing to do.

The only reason I am using sip addresses is to redirect inbound calls to my house to the sip phone over the internet if possible on the grounds of cheapness. I get a lot of spam calls so I am unwilling to pay for them to be directed to mobile phones

I am much in your debt for your assistance. Regards, Ray

That would be better and, if you were doing this for business use, would cause less confusion for the next maintainer.