I’m playing with a working asterisk that I have AMI credentials for. I’m using Node-Red with an extension, so I can get event notifications and send commands. I can already see incoming calls, get caller ids, etc. I can also originate calls.
What I’d like to build is the following:
When a call for me comes in, I’ll check the caller ID against a local database of known numbers.
If the caller id is found, I’ll just transfer the call to whatever dial-out options I need (e.g., two SIP lines for h/w phones and a software gateway to Telegram).
If the caller id is not found, I’ll pick up, and tell the caller to dial the current date.
If they succeed, I’ll tell them to wait, and dial myself as above.
If they fail, I’ll just play some music for half an hour and hang up
Can anyone describe (or point out to me) a high-level flow of the above using AMI commands? Thanks!
I was using first party incorrectly, but the key difference is that AMI is manipulating the whole PABX from outside, whereas AGI and dialplan are working on behalf of the current call. Amongst other things that means that multi-threading is much less of a concern.
Even ARI would be more appropriate than AMI.
However, when you use the dialplan, a lot of the handling of numbers entered and break in dialling are handled for you, meaning you end up with what can be very clean and compact code.
If I were to write it (dialplan+AGI), it would look something like this:
[inbound]
; is it somebody we know?
exten = <your-did>,1, verbose(1,[${EXTEN}@${CONTEXT}])
same = n, agi(lookup-cid)
same = n, goto(${lookup-status},1)
same = n, hangup
; It's somebody we know
exten = valid-cid,1, verbose(1,[${EXTEN}@${CONTEXT}])
same = n, goto(call-me,s,1)
same = n, hangup
; if's somebody we don't know
exten = invalid-cid,1, verbose(1,[${EXTEN}@${CONTEXT}])
same = n, read(current-date,please-enter-current-date,8)
same = n, gotoif($["${current-date}" = "${STRFTIME(,,%F)"]?call-me,s,1)
same = n, playback(tt-monkeys)
same = n, hangup
Just typed in, syntax and logic errors are free
You have to choose where your database will live. Asterisk has a SQLite database built in, or you could use something like MySQL – which is where I’d really suggest an AGI.
I’d add something in so that if the caller passes your ‘captcha’ their CID gets added to the database.
I’d do the ‘captcha’ in a loop so they get a couple of bites at the apple.
Then I dug into it and realized there’s ARI interface that exactly fits my needs.
And voila, first try - and it works! Later I can add more crap, like google contacts integration for known numbers, collecting multi-digit numbers, etc., etc.