AMI: intrerrogate caller and connect

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:

  1. When a call for me comes in, I’ll check the caller ID against a local database of known numbers.
  2. 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).
  3. If the caller id is not found, I’ll pick up, and tell the caller to dial the current date.
  4. If they succeed, I’ll tell them to wait, and dial myself as above.
  5. If they fail, I’ll just play some music for half an hour and hang up :slight_smile:

Can anyone describe (or point out to me) a high-level flow of the above using AMI commands? Thanks!

Is using AMI a requirement?

This looks like a dialplan thing to me with maybe an AGI for the database stuff, but database cruft in AGI may just be me :slight_smile:

1 Like

That seems rather mild. See for example:

You might also want to note that there is a TORTURE return status from pre-answer subroutines, intended to direct telemarketers to appropriate places.

The tt in files like tt_weasel stands for telemarketer torture.

This is a first part control application, so not appropriate for AMI, which is third party control.

Yes, I’d like to use node-red (hence AMI) and not bother with a dial plan.

Can you elaborate? I don’t understand.

You can mix AMI and AGI with Async AGI; listen for relevant events with AMI, then send the appropriate AGI command to that channel.

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:

; 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
  1. Just typed in, syntax and logic errors are free :slight_smile:
  2. 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.
  3. I’d add something in so that if the caller passes your ‘captcha’ their CID gets added to the database.
  4. I’d do the ‘captcha’ in a loop so they get a couple of bites at the apple.
1 Like

Thanks for all the replies!

  1. I really wanted to avoid doing it in a dial-plan.

  2. AGI was all I knew at the time.

  3. 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.

Hope this helps someone :slight_smile: here’s the flow.

Finally, added importing of my Google contacts twice a day, and that’s a win for me.

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