Book Review: Asterisk AGI Programming with Packt

[Please Note: If you follow the book links from this site to Packt’s and decide to buy *any* book from their site, we will get a small commission that we’ll use towards the upkeep of our servers etc.]

Asterisk Gateway Interface ProgrammingAs you may have read previously, I was approached by Packt Publishing to see if I would like to review their new book on AGI Programming by Nir Simionovich. Time has conspired against me to actually use it for a real project so instead I resorted to choosing it as my bedtime reading for a few days.

I’ve now read the book and first off I’d like to thank Packt for asking me. I have enjoyed it far more than I thought I would. As for how to review it, I thought I’d give my overall impression and then just go through it chapter by chapter.

It isn’t a long book – about 190 pages – which to my mind is no bad thing. It managed to concentrate on the subject and had little in the way of superfluous text and language (Apart from chapter 1 that is). The author knows his subject well and writes in a fairly informal and easy-to-read style which I personally quite liked. The meat of the book concentrates on – as you would probably guess – programming with AGI and focusses almost exclusively on using PHP. As much as I am happy around PHP, I would have liked to see some examples with alternative languages such as Python perhaps. The subtitle of the book is “Design and Develop Asterisk-based VoIP telephony platforms and services using PHP and PHPAGI” so I guess that’s why other languages don’t get much of a look in. They are mentioned here and there and there are some good links to various other libraries and open source projects. I did like the fact that he mentioned throughout the book – where necessary – the functional difference between the main versions of Asterisk (1.2, 1.4 and 1.6) and ways to deal with those differences when you come up against them.

OK – so here is my chapter-by-chapter review:

Sorry, but I didn’t really get the first chapter at all. This is a book aimed at programmers and developers and yet the first chapter was a repetitive cut-and-paste of how to build the various asterisk components from source, including lots of screen shots showing the output of things like ./configure which personally I found a bit trivial and uninteresting. I was a bit concerned that the rest of the book was going to follow suit but thankfully I was mistaken.

Chapter 2 is really good. It explains the workings of Asterisk’s dialplan and applications – the infamous extension.conf – in a very clear and understandable way. I recall when I first started to look at Asterisk and was delving into as much information on-line as I could get, the Asterisk TFOT book [pdf download] and whatever else I could find, that it was several days before the penny finally dropped. It isn’t difficult really but it isn’t quite the same as “normal” programming or scripting concepts and the language itself is far from obvious (e.g. an extension is not the phone on your desk in Asterisk’s configuration files). But then this is telephony we are talking about. Using the example of a basic IVR or AA the author examines the diaplan syntax and construction.

So I got quite a lot out of chapter 2. I thought it was well written and clear and useful. Chapter 3 develops the IVR theme further, introduces other features of the Asterisk application pool and covers the scripting language in more detail examining branching, expressions, operators and flow control. It’s a fairly short chapter but covers a good deal of ground if you are unfamiliar with Asterisk programming.

Your level of knowledge and familiarity with Asterisk will dictate what you get from this first section (Chapters 1-3). Although I have used Asterisk for a couple of years now and have felt quite comfortable with the platform’s configuration and use, I got quite a lot of new information and ideas from this early part of the book. For me, this initial part has been very useful and will be a good reference for the future. I think, though, if you are very familiar with Asterisk then you might find it a bit slow going. The book hasn’t examined AGI whatsoever up to this point and we are about a third of the way through already! The author does suggest that a coffee is a good before starting on Chapter 4 as “the journey becomes more and more complicated”…

Chapter 4 introduces the reader to AGI in a fairly gentle way and also offers 10 “rules” to help make your AGI programming more successful – they all make sense to me and will I’m sure prove to be a very useful monitoring/checking tool. Packt sent me an extract from this chapter which you are free to read here if you want to get a flavour of it.

The following chapter introduces us to some real code (PHP) and we build our first, simple AGI application. Nothing to hard, but a useful introduction into how to actually get the conversation happening between Asterisk and your script. There are couple of nice flow charts which are helpful for visualising the traffic flow back and forth between Asterisk and your script too. Again not too complicated but helpful in getting the novice AGI programmer, i.e. me, thinking about things the right way.

In chapter 6 Nir examines and recommends the use of a set of PHP classes (library) called PHPAGI. Being completely new to AGI programming I am in no position to contradict the author’s recommendation, but looking on the Sourceforge site for this library, it is quite old and has not been updated for 3 years or more. Of course that may be because it is perfect and needs no further development, or there might be other reasons but I would have really liked to have had some more discussion regarding this choice of library before continuing – just for my own piece of mind more than anything else. Perhaps if Nir reads this he could leave a comment about this? My own assumptions after reading the rest of the chapter are that the AGI interface itself is fairly simple and so – perhaps – the need for a more dynamic or complex library is just not there and this one does the job just fine. Anyway, the rest of the chapter we look at a new AGI application using the class library above and also we discover the main – and what seems to me to be a first-class – concept for building AGI applications: Atomic AGI or Particle Programming. Sounds great doesn’t it? It really does make a lot of sense. Basically it’s a bit like the traditional ideals behind Unix/Linux command line applications; write small applications that do one thing and do it well. To summarise then, in chapter 6 we are shown the author’s recommended path to AGI Nirvana through adopting some rules, and practices. It is hard for me to draw any solid conclusions from his approach as I am a novice with AGI and so have nothing by way of comparison, but it certainly seems to make a great deal of sense and is clear and well explained. Good stuff.

The remainder of the book goes a bit wider than just pure AGI. Chapters 7 and 8, examine some of the closely related applications and facilities of Asterisk. We get an overview of FastAGI (AGI over TCP) and Nir shows us some further PHP libraries that are available to assist with producing FastAGI applications. Chapter 8 offers an overview of the AMI (Asterisk Manager Interface) and some example code to get you started.

In the penultimate chapter, the reader is given a challenge: to create an application that is used in the real world – an Asterisk Call Recording Gateway. There is no code in this chapter – that’s for you to do. But Nir provides some useful guidance about the way to think about the development and plan the project itself.

And finally, chapter 10 discusses how to make sure your Asterisk applications can scale and offers several ideas and techniques to improve performance such as database query caching and using web services.

As I said at the beginning – I enjoyed reading this book much more than I thought I would. It is not overly technical and Nir has an engaging style of writing. The book is a great introduction into Asterisk programming. It is not “The Bible of Asterisk Programming” and does not set out to be. It is clearly aimed at developers who have not had much to do with Asterisk before but are familiar with traditional programming methods. I really liked the fact that it is quite short. You can read the whole book in a couple of evenings and being laid out the way it is it will become a very useful reference document for me in the future.

Nir Simionovich has a blog.

Tags: , , , ,

13 Comments

  • randulo says:

    I agree with you Alan, this book is a good read. Those interested in the subject of AGI should definitely check it out.

    I think it’s quite valuable for those venturing into AGI programming. As a major spaghetti-code, kludge-happy and basically awful php programmer, I can tell you that every line of this book recommends doing the opposite of what I’ve done, and this is a Good Thing 🙂

    Kudos to Nir for the book, which is an easy read and has a casual feel, and to his publishers Packt for getting it out for review to people who care.

    /r

  • Moises Silva says:

    Any discussion about Async AGI?

  • Hi Guys,

    First off, thanks for the kind words – it’s nice to know that I managed to hit the spot, as what I was aiming for is writing a very simple, to-the-point AGI book, without the need to go over and over and over the various aspects that are so boring about Asterisk. Sure, chapter 1 has nothing to do with AGI programming in itself, but I thought to myself: “some beginners, that have no idea about Asterisk, may purchase the book – this one is for them”.

    The choice of PHPAGI for the book was very simple, it’s very much wide spread around the Asterisk world, especially if you’re using a tool like FreePBX or trixbox, which install it by default. The idea was to establish a common base knowledge, with a de-facto Asterisk development library for AGI – which is simple, fast, reliable and most of all – stable and tested.

    I didn’t include Asynch AGI in the book for a simple reason: the book introduces AGI and AMI, Async AGI is more or less a combo of these too. Asynch AGI requires a certain finesse that the beginner developer still doesn’t have from this book, thus, over complicating it with Asynch AGI would have confused people. However, I’ll take that into account in the next edition.

    To be honest, the book isn’t only an AGI tutorial, as it can also serve as a wonderful source for preparing for Digium dCAP certification exam. While many regard certifications as just a piece of paper, I believe that certification in the Open Source world is very important, and having yourself dCAP certified as an Asterisk developer gives you a big plus.

    As some of you may know, I’m a freelance Asterisk developer and evangelist – operating from Israel. One of the subjects that had been thrown around the Asterisk mailing list is How to be a successful Asterisk consultant. I surely hope that the many consultants out there read this book. I don’t believe that I know everything, however, after spending almost 7 years promoting Asterisk and advocating it, this book is somewhat a climax for this, as it teaches some of the methodologies I use in my work – enabling me to render a better service to my customers. I surely hope that if you’re a freelance developer like myself, you’ll practice some of the methodologies in this book – and promote a more unified, better, smarter methodology of using and developing applications with Asterisk.

    Kind Regards,
    Nir Simionovich
    http://www.simionovich.com
    http://blog.greenfieldtech.net
    http://www.greenfieldtech.net

  • Alan Lord says:

    @Nir,

    Thanks for your comments. I hope your book is a success.

  • randulo says:

    Cheers Nir, this is yet another example of why the Internet is great, you get to “meet” people you’ve read.

    You should join us soon on the VoIP Users Conference – though I know from others that Friday night good for Israel. Maybe we can record an interview some other day.

    Best,

    randy

  • Hi Randy,

    Being located in Israel doesn’t immediately mean that Fridays are gone foe me, and I’m what you would call a secular Jew, not an Orthodox 😉

    Actually, as I’m a freelance consultant and render services to various customers world wide, my availability time is usually 20 hours per day – yes, I sleep about 4 hours a night. Actually, the last 3 chapters of the book, were written in a writing frenzy that lasted about 72 hours.

    My contact information is available through my business website at http://www.greenfieldtech.net/contact, so feel free to contact me at your leisure.

    If any of you guys are attending the Amoocon convention in Rostock, Germany – I’ll be over there talking about Asterisk Virtualization with Amazon EC2 and also an in depth session about Atomic-AGI/Particle Programming with Asterisk and its application with highly scalable Asterisk systems.

    Kind Regards,
    Nir Simionovich
    http://www.simionovich.com
    http://blog.greenfieldtech.net
    http://www.greenfieldtech.net

  • randulo says:

    I’ll see you at AMOOCON then! Save time for an interview with me too.

  • Hi Guys,

    No problem, just send me an email so I can update exactly where and when we can meet.

    Kind Regards,
    Nir Simionovich

    http://www.simionovich.com
    http://blog.greenfieldtech.net
    http://www.greenfieldtech.net

  • […] Book Review: Asterisk AGI Programming with Packt […]

  • […] on the heels of the Asterisk AGI Programming book review, Packt asked me to take a look at this […]

  • […] which I like. There is minimal waffle or superfluous language – something I’ve noticed with other Packt books in the past. Perhaps this is part of their editorial design? It certainly […]

Leave a Reply to randulo

XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>