[asterisk-users] Asterisk Manager and Visual Basic

Lee Jenkins lee at datatrakpos.com
Thu Feb 14 08:49:07 CST 2008


Bill Andersen wrote:
> Has anyone tried to used VB6 to communicate with the Asterisk Manager?
> 
> If so, would you be willing to share some basic code showing your
> approach to getting connected and parsing results?
> 
> I've got a Telnet control that is allowing me to connect, authenticate
> and see the "flow" of status, etc., but I'm sure there is a better way
> to do this without using Telnet (maybe not?).  Any suggestions?
> 
> I want to write a presence monitor (a virtual "sidecar" if you will)
> 
> Bill
> 

As Razza said, you can just use the winsock control included with VB.  The 
protocol is very simple, basically just name/value pairs delimited by #13#10 
(CRLF) with an extra CRLF at the end to denote termination of the packet.

Action: Originate
Channel: local/111 at Management
Context: to_meetme
Exten: s
Priority: 1
Variable: CALLERID(num)=123432|CALLERID(name)=Automated Call
Async: true
<extra CRLF> <== extra CRLF here.

So, like this:

1. Send your properly formatted packet to AMI .

2. Read incoming response terminated by double #13#10.

3. Parse values as you are comfortable with.

I am in the process of writing a similar product for one of our customers. 
Well, a re-write to add features and make it cross platform.  Here's a 
screenshot running on Linux/GTK:
http://leebo.dreamhosters.com/images/guiApp.png

A couple of side notes from what I've learned myself and read on this mailing 
list or through the wiki:

1. Packet Volume
The volume of messages that you can get from the AMI is impressive.  I've tested 
on our Asterisk system which has only 2 pots lines and two sip trunks with 10 
desktop phones and the amount of messages can be staggering!

Use a proxy for AMI if you have any decent phone traffic.  AstManProxy is VERY 
propular.  I wrote one as well, but its still beta and I think there's another 
one out there somewhere.  Usually with these proxy servers you can filter out 
unwanted/extraneous events to reduce the amount of messages your app has to 
contend with.

2. Make good use of Observer/Mediator pattern to distribute events to different 
parts of your GUI.  Monolithic loops to write everything out on a timer's event 
or after a Sleep() for instance, is not a good way to go in my experience.

3. Check the source for manager interface for changes between Asterisk 1.2 and 
1.4 (and 1.6?) if you're using 1.2 or plan to.  I believe the latest version of 
AMI is 1.1 (someone can correct me here).  A few label names for some of the AMI 
packets have been changed and a couple events (like LINK event) have been 
changed drastically.

I originally wrote against the 1.2 Manager interface only to find that I had to 
refactor some code and write descendant classes to handle the slight differences 
between the two versions' events.  I could have saved myself some work had I 
thought to look for the changes.  I think this link is up to date:
http://svn.digium.com/view/asterisk/trunk/doc/manager_1_1.txt?revision=98152&view=markup

Happy coding.


-- 
Warm Regards,

Lee

"Everything I needed to learn in life, I learned selling encyclopedias door to 
door."



More information about the asterisk-users mailing list