I have created a script in extensions_custom.conf which on incoming calls is making a query to a remote web server based on the incoming CallerId Number, then the web server return the corresponding Name.
I want to write the corresponding Name in a temp file, then set the Name
as the CallerID Name in such a way to appear on the screen of the endpoints.
The challenge is to write, read and delete the temp file.
Here is the script:
[temp-file]
exten => s,1,NoOp(Entering user defined context [temp-file] in extensions_custom.conf)
exten => s,2,System(tmpfile=$(mktemp /tmp/abc-script.XXXXXX))
exten => s,3,NoOp(tmpfile=${tmpfile})
exten => s,4,System(/etc/asterisk/modulix2)
exten => s,5,Set(CALLERID(name)=${tmpfile})
exten => s,5,Dial(SIP/202)
In “modulix2”, which is an exe file, I have a curl -X Get command which returns the Name of the caller.
I can send the result of “modulix2” in a already created file, but not in a “/tmp/abc-script.XXXXXX” file and then to read and delete /tmp/abc-script.XXXXXX file.
Why are you making a file that has this information and then deleting the file? Why not use AGI so you can make the db call and just return and set the CallerID Name? You could also do direct SQL calls or cURL calls from the dialplan and get this information returned.
Hello,
Thanks to everybody for reply.
I have tried with CID superfecta but it didn’t worked.
This is the curl command in “modulix2” and this suppose to be addapted to CID Superfecta, but I did not succeded. maybe you can have an idea:
Because you’re using cURL wrong in Asterisk. There are actual cURL functions in Asterisk to set the URL, auth and payload along with setting the various cURL options like content-type, etc. You just can’t call curl like you would from the CLI.
System() is going to execute the script at the system level. There you can make your standard cURL calls and do what you where doing. You now need to get that information back into Asterisk and the dialplan.
AGI() will let you jump out of dialplan, execute the script and let you inject or manipulate the dialplan variables, commands, functions.
The cURL functions will let you make that same cURL from the dialplan and get the results to process.
I know I’m using cURL in a wrong way, but, till now, the remote website is reacting only on system level commands as showed above.
I have tried with CID superfecta, but I couldn’t adapt this cURL command to any of the existing schemes. (PBXact)
About, AGI, I’m new in this field, so it will take a little time to better understand how it works.
Meanwhile I have succeeded to make it work somehow, creating 4 different
exe files which are creating the new file, input the result of the query (caller name) in the new file, reading and setting the caller’s name from the new file and then erasing the new file.
I have to call each exe file at the right step. It’s a primitive way but
it’s a start.
On the other way I’m expecting to have a mess when I will receive two or more simultaneous calls, because that new file will be written with more and different caller names in the same time. So, we will roll the dice to see who is who.
Is it possible to adapt this script on channel level!? I mean I will create
as many different files as available channels (8 on sip trunk).