You can interact with Asterisk over TCP and receive PBX event notifications. The Asterisk Manager API, while sparsely documented at voip-info.org is easy enough to follow. Here's how you can connect to Asterisk with the IPPort component of IP*Works!: ipport1.SendLine("Action: Login\r\nUsername: " + user + "\r\nSecret: " + password + "\r\n");
At this point you'll start receiving PBX "events" (such as lines being picked up, lines being connected, voice mails received, etc) which you can catch in the IPPort component's DataIn event.
You'll get a NewChannel event when some action has been performed by some phone to cause a new channel to be opened on the SIP server. You'll get a NewExtension event when a particular extension (ie, a Zap line or a local SIP phone) has been connected to the channel. You'll get a NewState event when a particular extension has changed state (such as, "ringing", "up", or "down"). You'll get a Link event when two channels are linking together (conversation is beginning) or and Unlinkevent when two chanels are unlinking from each other (conversation is ending). You'll get a Voicemail event when a voicemail gets left for a particular extension.
These events let you track who is on the phone, and who they're on the phone with. You can determine if someone is calling you, and who that someone is (caller id). You can determine if there are voicemails on any extensions that you have control over.
I used this functionality to keep a list of call history, so that I can call someone back with just the click of the mouse. I can send an action command to the server to make the phone call for me. When the person I am calling picks up (if they are a SIP extension) or when the outside line is dialed (if they are an outside Zap caller), my own SIP phone will ring notifying me that the conversation is ready.
private void CallNumber(string number, bool local) { string command = ""; if (local) { command = "Action: Originate\r\nChannel: SIP/" + number + "\r\n"; command += "Context: default\r\n"; command += "Exten: " + myextension + "\r\n"; command += "Priority: 1\r\n"; command += "Callerid: \"" + myext + "\" <" + myext + ">\r\n"; } else { command = "Action: Originate\r\n"; command += "Channel: Zap/g1/" + number + "\r\n"; command += "Context: default\r\n"; command += "Exten: " + myext + "\r\n"; command += "Priority: 1\r\n"; command += "Callerid: \"" + myext + "\" <" + myext + ">\r\n"; } ipport1.SendLine(command); }
|