sipsorcery's blog

Occassional posts about VoIP, SIP, WebRTC and Bitcoin. response times SIP Sorcery Last 3 Hours
daily weekly status

Asterisk, AGI and Cloudvox

Along with playing around with Tropo to test out VoIP applications where sipsorcery’s signalling only design is insufficient I have also occasionally fired up an Asterisk EC2 instance (thanks to Voxilla for bundling up an Asterisk EC2 AMI to make things easy). Each time I would customise the Asterisk dialplan to test out whatever it was and then take the instance down a few hours later. The great thing about sipsorcery is that it saves me having to configure SIP accounts or providers on the Asterisk system. I’d always thought it would be great if someone else did all the grunt work for me and offered Pay As You Go hosted Asterisk instances and saved me even the small amount of time I spent bringing my own instance up. There are lots of hosting companies out there that will host Asterisk instances but the key for me is the Pay As You Go piece, I might only want to test something out once every three months and I’m not interested in paying a monthly charge.

That’s why I’ve been somewhat interested in Cloudvox’s offering. It’s the first time I’ve seen hosted cheap hosted Asterisk instances. It’s great that they provide free “Hacker” accounts so you can at least make sure it’s not a snake oil product. Above that the cheapest plan is $6/month and calls at $0.06 per minute. Even though I’m not a fan of the monthly charge $6 is pretty cheap and it looks like you can switch back to the Hacker account easily if you know your account is not going to be in use for a while. The $0.06 per minute is not so appealing and it’s still a little bit fuzzy to me whether SIP-to-SIP calls are billable or not, apparently they are but I found that it depends on how they are dialled as to whether they show up on my account as billable or not (note I’m not trying to find ways around the cloudvox billing rather I’m trying to work out if SIP-to-SIP calls are free).

Cloudvox have two APIs for building applications although for some reason they have included SIP+RTP in the HTTP vs AGI comparison which doesn’t really make any sense and must be awfully confusing to developer new to VoIP. The HTTP API is very basic but is the easiest to get up and running with. I found it counterintuitive to begin with but that’s because I was so used to the concept of dialplans, VoiceXML and Asterisk that I was thinking of it as a way of simply loading the Asterisk dialplan whereas the approach is for the Cloudvox Asterisk servers to receive a call, send a HTTP request for a small number of Asterisk commands to a web server somewhere, execute those commands and return the result via another HTTP request, it makes perfect sense to me now. An example of an ideal task for the HTTP API is one the same I mentioned in the Tropo Transfer post about a user dialling into sipsorcery, somehow entering a number and then dialling that number out through one of their providers. The HTTP API would be perfect for getting Asterisk to play a prompt, collect some digits and then return them to sipsorcery via a HTTP request.

The second API revolves around the Asterisk Gateway Interface. Again I got somewhat confused this time by the fact that the emphasis is put on some pre-canned AGI servers like Adhearsion or the Asterisk::AGI Perl module. My confusion arose from thinking I needed to somehow connect to an AGI server Cloudvox had somewhere or that there was some special configuration on Cloudvox’s end that only allowed it to work with specific AGI servers. In the end the situation was again a lot simpler and Cloudvox don’t care what the AGI server is and all the examples and configuration guides are targetted at the common ones on the assumption, most likely correct as well, that most people will use one of them. Once that light bulb went off for me I dusted off my own C# AGI server, written many years ago, and had calls coming into it from the Cloudvox Asterisk servers in no time at all.

I’ve checked the very rudimentary C# AGI code into the sipsorcery code base, I had to strip out all the business logic so it’s really bare bones, it’s called SIPSorcery.Asterisk.FastAGI and is in the sipsorcery-servers directory. I don’t know when the next time I’ll get fired up to do anything else with it but it’s there as a reference should any other C# developers be interested. Generally I get all excited about integrating with new VoIP platforms but once i can play the monkey sounds or equivalent I consider the integration proven until something else crops up.