FreePBX | Register | Issues | Wiki | Portal | Support

Async AGI - How to do in with SNG 7


#1

Hello,

Asterisk/FreePBX 14

I have a call treatment that ultimately kicks off an AGI that sends a sms, then comes back to the dialplan to finish with a than you message and hangup.

There is a new requirement to wait 300 seconds prior to sending the text. I can make the agi script (python) wait 300 seconds no problem, but I do not want to have the channel up. Instead I want the 300 seconds to kick off, while the thank you and hang up happen.

I think I need:
AGISIGHUP=no to ensure the agi continues to run (wait the 300 seconds then send sms) when the call/channel hangs up.

I also think I need to call my agi as Async AGI so that the wait timer can kick off, but the dial plan can continue to the thank you and hang up.

Questions:

  • Is that right?
  • How do I enable Async AGI for my SNG distro? I read I need an AMI entry?
  • Alternative recommendations?

#2

Is it enough to amend the permissions of admin on /etc/asterisk/manager.conf?

Currently:
[admin]
secret = *****
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
read = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate,message
write = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate,message
writetimeout = 5000

To:
[admin]
secret = *****
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
read = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate,message,agi
write = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate,message,agi
writetimeout = 5000

Not sure how to do that as there is not an override file.


#3

@claloano it sounds like you may have solved this already? Can you give any more detail on how you provisioned async agi on FreePBX?


(Lorne Gaetz) #4

Two stray thoughts:

  1. have your AGI write a .call file that sends the SMS. The .call file would be timestamped to the future so you can add whatever delay you want

  2. Add a hangup handler to the channel, and have the AGI be called after the channel hangs up. You could then introduce the delay directly in the AGI before the SMS is sent.


#5
  1. How can I create a call file that doesn’t “call” before executing the SMS code?

2.Can you point me in the direction of the hangup handler. Haven’t done that before, I think.


(Lorne Gaetz) #6

If you change the call file timestamp to the future, it will execute at the time of the time stamp. There is an example in this post of how to use a hangup handler.


#7

I use that bit of functionality with call files today, but my (limited) understanding is that for a call file to execute dialplan there first has to be a call + connection. IS there a way to execute a call file without having to call and connect to a number? That would be helpful for other projects I have.

For the hangup handler it looks like I just need add the following line to my dial plan:
exten => s,n,Set(CHANNEL(hangup_handler_push)=send-sms-agi,s,1)

Then in extensions_custom.conf I would add a context to call my AGI:
[send-sms-agi]
;SMS script
exten => s,1,AGI(/var/lib/asterisk/agi-bin/sms_yes.py)
exten => s,n,Hangup()

Does that sound right?

Since the AGI is waiting 300 seconds then invoking the SMS command, should I run the deadsgi command?
[send-sms-agi]
;SMS script
exten => s,1,Set(AGISIGHUP=no)
exten => s,n,AGI(/var/lib/asterisk/agi-bin/sms_yes.py)
exten => s,n,Hangup()

Thanks for the help here @lgaetz, I really appreciate and needed it!


(Itzik) #8

Not completely following here. But wouldn’t it need to be a Return?


(Dave Burgess) #9

I wouldn’t think so - it’s asynch, so there’s no place to return to.


(Lorne Gaetz) #10

@PitzKey is correct, a hangup handler should end with a Return. This will allow for multiple hangup handlers to be run on the channel.


#11

So for anyone looking in the future, I went with @lgaetz recommendation of using
CHANNEL(hangup_handler_push)
This lets me run my AGI script that sends an SMS 5 minutes after I hang-up the channel. I am not sure on the overhead this causes (leaving the AGI running), but I will keep an eye on it.

I think @lgaetz suggestion of using the call file might be more efficient, but I am not sure how to get the call file to advance to the return context without making an outbound call and connecting it first. If I figure that out I may try the call file approach.

Thanks all!


#12

You can use ‘local’ channels with call.files to connect to ‘applications’ or any ‘context’

http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/DeeperDialplan_id324598.html

https://wiki.asterisk.org/wiki/display/AST/Local+Channel

after creating call.file and before moving it to /var/spool/asterisk/outgoing

touch -d "$(date) +5minutes" call.file


(system) closed #13

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