How to record a Call originated by AMI that goes to a context

Friends, good morning!
I have a client who is a medical clinic, and they needed an automatic confirmation solution (where the PBX pulls the doctor’s schedule, saves it in a database, calls the patients, informs them of the appointment via Azure Voice AI and gives options to confirm, cancel, reschedule, among others).

We managed to achieve this goal with the help of some Python scripts and the creation of some ODBC functions, the scheme is as follows:

Scripts location: /opt/medical

agenda.py (script that pulls the agenda from their system endpoint and saves it in a database, runs every day at a specific time getting the next day’s agenda)

dialer.py - calls patients (originating a call via AMI), and when they answer, forwards to the ivr-medical context

confirmation.py - script that runs in a loop, whenever a new entry is detected in the confirmations table (when a client confirms a appointment via ivr), sends this to their system endpoint

see the context here: Context - AMI AI Calls - Pastebin.com
and the python script who initiate the calls: Context AI Calls - Pastebin.com

In general, this scheme has been working well, and there are a few more scripts (like the one that calls the Microsoft Azure API and generates the audio that the context plays) but one difficulty that I haven’t been able to solve yet is getting these calls to be recorded correctly .

I even managed to get the audio to be generated through context, but it remains silent and only lasts for a second. Is it something I got wrong in the context? or in the script? Is there an easier way to do what these scripts are doing? If someone can help me with this I would be very happy.

ps: some things were translated from pt-br (original language where everything was written, like the comments) to English, so if something was confusing I can clarify… also, if anyone is interested in some of the scripts (start call, pull agenda to save in the database, script that generates audio with azure) I can send or publish on pastebin.

Not sure I understand the failure, but perhaps this is what you’re looking for

The failure is that calls made by this script are not being recorded

Currently I have the Call Record Option marked with “No”, this way the calls are recorded completely from the beginning

I do not use a virtual extension to originate these calls, but rather “s” in the AMI command

originate_cmd = f’‘‘Action:Originate
CallerID:<71XXXXXXXX> (censored)
Channel:PJSIP/{celular}@Algar
Context:{context}
Exten:s
Priority:1
Variable: TARGETNUM={celular}
\r\n\r\n’’’

By the way… would using a virtual extension make it easier for me to execute these scripts? One of the difficulties I encounter using the s extension is that in the cdr the callerid is defined only with the main number, but I wanted it to be easier to find the record of these calls made via script (even to create some reports). … maybe putting something in the userfield

If you originate the call to the channel:

Channel:Local/{celular}@from-internal

then the call will follow your outbound routes/trunks and use the recording options set in the GUI.

1 Like

Thank you very much, you are a lifesaver!
After making this change, the script started to follow the outbound and recording rules perfectly, which made many things easier (even handling dialing for long distance numbers)… thank you very much!!

1 Like

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