M4rk
M4rk

Reputation: 2272

Asterisk, get number/SIP to dial from external python application

I would like to dial a custom number fetched from my DB by a python script when a user calls. I need to pass a couple parameters like the extension or the number that is calling to python. Is it achievable in Asterisk?

exten => 1001, 1, Dial(cmd("python myScript.py {extension} {didNumber}") 
same => n, Hangup()

Edit I saw that there are a couple of Python libraries for asterisk, but it seems an overcomplicated way to just get a phone number (and I can't come up with an easy solution with those libraries easily) and it would require the python script to have much more knowledge of the asterisk system.

Upvotes: 0

Views: 1027

Answers (1)

brownian
brownian

Reputation: 435

Yes, it's possible like this:

exten => 1001,1,Set(LOCAL(numtodial)=${SHELL(${GETNUM_SCRIPT} ${extension} ${didNumber})})
same => n,Dial(${TECHNOLOGY}/${numtodial})

Here GETNUM_SCRIPT is a global variable because I like global variables for things like this (you can redefine it on-the-fly, without dialplan reload, or define it on per-peer basics).

I would also suggest to split getting number and dialing into two lines --- possibly you'll want to perform some sanity checks.

Upvotes: 1

Related Questions