Questionnaire with Asterisk PBX AGI + Ruby

There are several Ruby AGI realisations, most famous is Adhearsion. I use it for most of my projects currently, its fantastic, but...
For simple projects (and prior Adhearsion) I use another one, AsteriskRuby. And Rastman to access AMI (asterisk manager interface).
What I like with them, that such libraries are not abstract framework, I love them for simplicity, you execute Asterisk commands, get events in Asterisk way.
Performance is very good, libraries are simple and flexible, possible to create both AGI and FastAGI, daemonize the whole  You may use raw ruby or extend ActiveRecord or another framework (I did it with AR and Mondoid).

And here about questionnaire. Few years ago I get an request to build it and now decided to share with VoIP community.

For now my code has no comments, feel free to ask. I will rework it when will have time. It was worked with Asterisk 1.6x, Ruby 1.8x.

How it works:

  • extensions.conf point the call to the FastAGI;
  • for new caller system play welcome message, for returned caller - welcome back message;
  • application request caller to enter a PIN;
  • upon successful authentication, system start from last unanswered question.

Amount of attempts is unlimited, answers and amount of calls are stored into DB.

You need a filename codes.txt with phone numbers and PIN codes, few voice recordings (can understand from application content about file name and phrases).

Ruby FastAGI application code:
Good luck! 

Telephony system for remote locations

Who working far away from home country. Or vice-versa, working from home for company abroad. Who relocated to another country or travel a lot, have presence in another country – such people need an good telecommunication system, in order to keep contacts with family, friends, colleagues.

Target users

  • Expats, migrants, students;
  • Remote workers;
  • Travelers, tourists;
  • Multi-country SOHO businesses;
  • Transport / logistics companies;
  • Travel agencies;
  • Other SOHO businesses...

Such category of users usually looking for

  • a local SIM card to make cheap local calls and to browse online cheaper;
  • a way to keep old phone number in home country;
  • cheap or zero cost roaming solution to minimize cost of inbound call;
  • (who wants to establish an virtual presence) - a local phone number in remote location;
  • cheap outbound call rates;
  • (optional) for voicemail service, for voice announcements (IVR), call center, PBX;
  • very simple and flexible management of such phone system.

Well and how all that could be realized?

To create a professional phone system with low-cost calls, you need such components:
  • Hosted PBX service or (much flexible!) a box with Linux and Asterisk PBX on it. This box could be an: old computer, Raspberry Pi box, OpenWRT router, VPS server;
  • Prepaid SIM card in current location with mobile internet;
  • DID phone number in home (remote for virtual presence) country. DID is a phone number you can buy from an VoIP carrier, then you can configure your SIP client (your virtual PBX) in order to receive inbound phone calls;
  • When you setup an DID in your home country, forward all calls sent to your cellphone;
  • Subscription for service from one or few VoIP operators, with good rates;
  • (optional) DID number in your local country
So, you forward calls to cellphone to a phone number in your home country - it is cheap or for free, if you have a contract;
Install an SIP client on your cellphone and point it to your PBX – and when you are online (WIFI, LTE, HSPDA) - you'll get inbound calls to your home country for free. And if you are offline, you may forward calls to voicemail box or via VoIP carrier to your cellphone – that's usually much cheaper than roaming fee;
When you online, call out via your SIP client, paying your VoIP carrier fees. When offline, call via your local DID number, you will pay extra fee for local call from your cellphone

In next articles

In next articles I will explain, how to configure Asterisk PBX and create such telephony system, how to keep it simple and light, how to manage and maintain such system. I will also show my setups for such countries: Canada, Italy, Lithuania, Russia, Spain, Sweden.

Questions?

Do you have questions, notes, do you want to discuss or something not clear – let's talk, contact me! 

Asterisk AGI sample in bash

Asterisk AGI sample in bash, very interesting. I am using Ruby for this purpose (Adhearsion or AsteriskRuby), but bash is great choice in situation when Asterisk can’t do something and external scripts must be called.