开发者

How to execute a dialplan by asterisk's AMI API?

Couldn't find a specific answer for this. I'm a newbie to asterisk and AMI. I need to auto generate calls using asterisk and pass parameters to an AGI program. Using a call file seems to generate the call first which is not wanted. So, how do I use asterisk AMI API (PHP) to execute a dialplan with AGI in it, by passing all parameters to i开发者_C百科t? So, the AGI will take over and make the call.


I think in your case, using call files would actually be simpler. Here's why:

  1. The AMI requires you to write networked code, which (if you're a beginner) will be a lot more tricky the building simple text files (Call Files).
  2. Call Files allow you to pass variables to Asterisk that you can use in your dialplan code.
  3. Call Files are extremely simple.

Below is a full example of a simple way to do it using call files. I've tried my best to explain it in the associated comments.

Firstly, let's assume you have some dialplan code that uses variables, and calls an AGI script (which is what I assume you're doing based on your question). That means you'll have code in your extensions.conf file that looks something like:

[test_stuff]
exten => s,1,NoOp(starting test!)
exten => s,n,NoOp(my variable's value is: ${somevar})
exten => s,n,NoOp(my other variable's value is: ${some_other_var})
exten => s,n,AGI(/path/to/my/script.sh,${somevar})
exten => s,n,NoOp(i just ran an AGI script and passed it a command line argument!)
exten => s,n,Hangup()

Below is a call file that will:

  1. Need to be created in some temporary directory (maybe /tmp/).

  2. Once it has been saved, you can run it by moving it to /var/spool/asterisk/outgoing/ (eg: mv /tmp/blah.call /var/spool/asterisk/outgoing/).

  3. The call file will the immediately dial outbound to the phone number 818-222-3333.

  4. Once the person at 818-222-3333 picks up the call, Asterisk will immediately start executing your [test_stuff] dialplan code, and will have the variables set in your call file available to it.

Call file:

Channel: SIP/trunkname/18182223333
Context: test_stuff
Extension: s
Priority: 1
Set: somevar=hithere
Set: some_other_var=woot

Hope that helps!


Your problem can be solved with the help of local channel for example

In call file use Local/1812222222@test_stuff as channels while using following dialplan

[test_stuff]
exten => _X.,1,NoOp(starting test!)
exten => _X.,n,Set(phone=${EXTEN})
exten => _X.,n,AGI(/path/to/my/billing,${phone},${other_variables_account_etc..})
exten => _X.,n,Dial(SIP/trunkName/${phone})

You can use this method with both interfaces AMI or .call file

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜