Hello
I am fairly new to asterisk.
I want to change the number in the TO field of the SIP packet with a python script before I send the call to the gateway.
How can I achieve that
PS: The calls are being sent from another SIP platform.
I tried this but it did not work. however, the outbound20,s,1 context gets into new stack but the script does not execute:
[outbound20,s,1]
exten => _X.,1,NoOp(Entering custom script extension)
same => n,System(/usr/bin/python3 /custom/script.py ${EXTEN})
same => n,Dial(PJSIP/trunk-name/${EXTEN})
PS: python3 is running on the environment and the script has necessary permissions
Before calling Dial() the To value is not known, so you cannot change it. You could do that possibly with a pre-dial hook, but I don’t know whether all of this makes any sense.
Why can’t you write the PJSIP configuration such that you get the correct To field? That said, Asterisk does not allow to manipulate the SIP headers the way a SIP Proxy like Kamailio can do.
I never had any problems with the Asterisk Wiki. It may also help to have FreePBX on a VM for learning and testing. My experience is that the default configurations on FreePBX are useful for a various scenarios. If you click something together and it works, you’d know where to look for the underlying PJSIP configuration.
chan_pjsip only supports the sand RFC 3261 behaviour of setting the To header the same as the request URI.
However, maybe you mean change the request URI.
EXTEN is not a normal channel variable, and cannot be set explicitly, but only by using GoTo or GoSub. Changing EXTEN changes your place in the dialplan.
You are passing it by value to the Python script (and there are no ways of passing variables by name or reference using System.
If you want to modify the request URI, it is probably better to use a normal channel variable, and set it using the SHELL function or by running the Python as an AGI script.