Friday, May 1, 2009

IPY as AMI client thru AMIConnector

One of the thing I like about IPY or python programming. If a class is professionally crafted, the info on how to use methods is readily available. On this post I explore the library AMIConnector.
An access to AMI(Asterisk Manager Interface) is needed to run a script that uses this library. But since I have no Asterisk access whatsoever, I will be contended exploring the methods use to originate a call.


>>> import clr
>>> clr.AddReferenceToFileAndPath("C:\IronPython 2.0.1\Lib\site-packages\AMI.Con
nector.14.dll")
>>> import AMI_Connector_14.AMI_Connector as Ami14
>>> dir(Ami14)
['ActionResponse_ExtensionState', 'ActionResponse_ExtensionStateEventHandler', '
Action_AgentCallBackLogin', 'Action_AgentLogoff', 'Action_ExtensionState', 'Acti
on_HangUp', 'Action_Originate', 'Action_ParkedCalls', 'Action_QueueAdd', 'Action
_QueuePause', 'Action_QueueRemove', 'Action_QueueStatus', 'Action_Redirect', 'Ag
ents', 'AsteriskVersion', 'CanRaiseEvents', 'Connect', 'Connected', 'Container',
'CreateObjRef', 'DesignMode', 'Disconnect', 'Disconnected', 'DisconnectedEventH
andler', 'Dispose', 'Disposed', 'Equals', 'Evaluation', 'Event_Agents', 'Event_A
gentsComplete', 'Event_AgentsCompleteEventHandler', 'Event_AgentsEventHandler',
'Event_Cdr', 'Event_CdrEventHandler', 'Event_Dial', 'Event_DialEventHandler', 'E
vent_ExtensionStatus', 'Event_ExtensionStatusEventHandler', 'Event_HangUp', 'Eve
nt_HangUpEventHandler', 'Event_Join', 'Event_JoinEventHandler', 'Event_Leave', '
Event_LeaveEventHandler', 'Event_Link', 'Event_LinkEventHandler', 'Event_Login',
'Event_LoginEventHandler', 'Event_MeetmeJoin', 'Event_MeetmeJoinEventHandler',
'Event_MeetmeLeave', 'Event_MeetmeLeaveEventHandler', 'Event_MeetmeStopTalking',
'Event_MeetmeStopTalkingEventHandler', 'Event_MeetmeTalking', 'Event_MeetmeTalk
ingEventHandler', 'Event_MusicOnHold', 'Event_MusicOnHoldEventHandler', 'Event_N
ewChannel', 'Event_NewChannelEventHandler', 'Event_NewState', 'Event_NewStateEve
ntHandler', 'Event_Newcallerid', 'Event_NewcalleridEventHandler', 'Event_Newexte
n', 'Event_NewextenEventHandler', 'Event_ParkedCall', 'Event_ParkedCallEventHand
ler', 'Event_PeerStatus', 'Event_PeerStatusEventHandler', 'Event_QueueMember', '
Event_QueueMemberAdded', 'Event_QueueMemberAddedEventHandler', 'Event_QueueMembe
rEventHandler', 'Event_QueueMemberPaused', 'Event_QueueMemberPausedEventHandler'
, 'Event_QueueMemberRemoved', 'Event_QueueMemberRemovedEventHandler', 'Event_Que
ueMemberStatus', 'Event_QueueMemberStatusEventHandler', 'Event_QueueParams', 'Ev
ent_QueueParamsEventHandler', 'Event_QueueStatusComplete', 'Event_QueueStatusCom
pleteEventHandler', 'Event_Registry', 'Event_RegistryEventHandler', 'Event_Renam
e', 'Event_RenameEventHandler', 'Event_UnParkedCall', 'Event_UnParkedCallEventHa
ndler', 'Event_Unlink', 'Event_UnlinkEventHandler', 'Events', 'GetHashCode', 'Ge
tLifetimeService', 'GetService', 'GetType', 'HostIP', 'HostPort', 'InitializeLif
etimeService', 'LicenceAmi', 'MemberwiseClone', 'ReferenceEquals', 'SearchInBloc
k', 'SendInformation', 'Site', 'ToString', 'User', '__class__', '__delattr__', '
__doc__', '__enter__', '__exit__', '__getattribute__', '__hash__', '__init__', '
__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__']
>>> dir(Ami14.Connect)
['Equals', 'GetHashCode', 'GetType', 'MemberwiseClone', 'ReferenceEquals', 'ToSt
ring', '__call__', '__class__', '__cmp__', '__delattr__', '__delete__', '__doc__
', '__get__', '__getattribute__', '__hash__', '__init__', '__name__', '__new__',
'__objclass__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__st
r__']

Of course it will be really difficult if you have no API documents (no examples) or knowledge what's the library all about. In my case, I'm an Asterisk fan way back 2003. So its pretty easy for me how to make this script connect and place(originate) a call.

>>> Ami14.HostIP.__doc__
'Get: str HostIP(self)\r\nSet: HostIP(self) = value\r\n'
>>> Ami14.HostPort.__doc__
'Get: str HostPort(self)\r\nSet: HostPort(self) = value\r\n'
>>> Ami14.Connect.__doc__
'Connect(self, str UserAMI, str PasswordAMI)'
>>>

The above code is straightforward its use to connect to the AMI. While the two method below places the call and ultimately disconnect the script from AMI.


>>> Ami14.Action_Originate.__doc__
'Action_Originate(self, str Channel, str Context, str Exten, str CallerID)'
>>>
>>> Ami14.Disconnect.__doc__
'Disconnect(self)'

On the next post I will do form and actual codes that uses AMIConnector library.

No comments:

Post a Comment

Followers

About Me

An underrated techie. With great interest in digital electronics, photography(minus photoshop and others stuff) and audio-video engineering. With more than 10 years of IT working experience ranging from systems and network administration, programming and Voice-Over-IP engineering.