I wrote a script that generates a sound file, dials a number and should play it after picking up the phone. But instead, it just connects and I can talk to the recipient.
Through freepbx, I have set up a call to number 777 through custom distances.
Accordingly, I dial 777 from my phone.
I call the script like this:
[autodial]
exten => s,1,AGI(/var/lib/asterisk/agi-bin/Autodial.agi)
It works out, generates a sound file. The file format is correct, the rights are asterisk:asterisk
The connection is established, the recipient picks up the phone and I can talk to him, instead of playing the file and processing further script logic.
Tell me, please, what is my mistake?
(I’ve attached the part I’m having trouble with here)
with open(file_path, 'r') as file:
for line in file:
surname, lastname, name, phone_number = line.strip().split(',')
phone_number = int(phone_number)
replaced_text = f"Hello, {name} {lastname}!"
command_gen = f" '{replaced_text}' --output {temp_audio_path} && sox {temp_audio_path} -r 8000 {audio_path}"
os.system(command_gen)
...
command = 'SIP/Ed/{}'.format(phone_number)
timeout = '30'
timeout = int(timeout)
result = agi.exec_command('Dial', command, timeout)
agi.verbose('Dial result: {}'.format(result))
if agi.env['agi_channel_state'] == '6':
agi.verbose('Success')
agi.stream_file(f'/home/asterisk/sounds/{audio_path}')
agi.stream_file('/home/asterisk/sounds/autodial_message_body.wav')
...