Visual Basic VoIP developers 101
Part 2: Visual Basic example on recording VoIP calls, call routing
Learn how to do more advanced tasks using Visual Basic. This guide shows you how to log, record and finally route calls. At the end of this task, you can use the Ozeki Phone System XE to a whole new level.
On the previous page the first part of VB.NET VoIP developers 101 could be read. That guide presented the prerequisites of doing basic tasks, such as SMS sending/receiving or making/receiving a call using your own Visual Basic application. This article focuses on far more advanced features, like call logging, call recording and call routing.
Connecting to PBX
At the beginning, make an OpsClient department. You can login, if you import the Login function. It has three parameters: first the IP address of the server, the second is the username and the third one is the password. The successful login depends on the return value of the Login function. You can login to the PBX, using your default admin user data. You can extend the database by adding new users at Connections menu, Office users menu item, selecting the Add user option. Whether a user is able to sign in through API, depends on the value of his user profile. You are able to set up more user profile. Select Security form at PBX features menu, Preferences menu item to do this. Enabling is possible by using the Allow this user to configure the PBX through the API option.
To start log calls, you need to successfully login, then subscribe to the SessionCreated event, which changes call receiving. VoIPEventArgs type parameter contains the active calls. Through the Item attribute of this parameter you can access the call, that created the event. So, you can query the information about the call or connect AudioSender and AudioReceiver. As a result, you can talk to clients separately at the same time, log calls and play an audio file.
Sub Initialized() Dim opsClient As OpsClient = New OpsClient() Dim result = opsClient.Login("ozekixepbx.ip", "admin", "abc12345") AddHandler opsClient.SessionCreated, AddressOf SessionCreated End Sub Private Sub SessionCreated(ByVal sender As Object, ByVal e As Ozeki.VoIP.VoIPEventArgs(Of ISession)) Console.Clear() Console.WriteLine("SessionID: " + e.Item.SessionID) Console.WriteLine("Call direction: " + e.Item.CallDirection) Console.WriteLine("Caller: " + e.Item.Caller) Console.WriteLine("Callee: " + e.Item.Callee) Console.WriteLine("Ring duration: " + e.Item.RingDuration.ToString()) Console.WriteLine("State: " + e.Item.State) Console.WriteLine("State duration: " + e.Item.StateDuration.ToString()) Console.WriteLine("Start time: " + e.Item.StartTime) Console.WriteLine("Talk duration: " + e.Item.TalkDuration.ToString()) End Sub
Call recording is happening with SessionCreated and SessionsCompleted events. SessionCreated events occur when you answer a call. Therefore, you attach an AudioReceiver to the call, which you can verify by importing ConnectAudioReceiver function. With the first parameter, you can choose which voice you would like to record; and the second parameter is a Recorder object. Either MP3StreamRecorder (calls created in an MP3 file) or WaveStreamRecorder (calls created in a wav file). The constructor of both classes is waiting the path of the file. Start your recording by applying StartStreaming method. When you hang up your call, SessionCompleted event starts. You need to finish the earlier started Streaming at SessionCreated. Use the Dispose() method of the recorder object to do this.
Module CallRecording Public mp3StreamRecorder As MP3StreamRecorder 'Public waveStreamRecorder As WaveStreamRecorder Sub Initialized() Dim opsClient As OpsClient = New OpsClient() Dim result = opsClient.Login("ozekixepbx.ip", "admin", "abc12345") AddHandler opsClient.SessionCreated, AddressOf SessionCreated AddHandler opsClient.SessionCompleted, AddressOf SessionCompleted End Sub Private Sub SessionCreated(ByVal sender As Object, ByVal e As Ozeki.VoIP.VoIPEventArgs(Of ISession)) mp3StreamRecoder = New MP3StreamRecorder("Record.mp3") 'waveStreamRecorder = New WaveStreamPlayback("Record.wav") e.Item.ConnectAudioReceiver(OPSSDKCommon.Model.Call.CallParty.All, mp3StreamRecoder) 'e.Item.ConnectAudioReceiver(OPSSDKCommon.Model.Call.CallParty.All, waveStreamRecorder) mp3StreamRecoder.StartStreaming() 'waveStreamRecorder.StartStreaming() End Sub Private Sub SessionCompleted(ByVal sender As Object, ByVal e As Ozeki.VoIP.VoIPEventArgs(Of ISession)) mp3StreamRecorder.Dispose() 'waveStreamRecorder.Dispose() End Sub End Module
PBX provides not just dial plan, but also another opportunity to froward calls. Import SetCallRoutingInterceptor() method of OpsClient departement. It has one parameter, that implements the IcallRoutingInterceptor interface but first you have to create a definition. This is the GetDestination() method. The function gets the data of the call in a function. The return value is a Destination object, which contains the parameters of the call forward. While creating, Destination class waits for the identity of the call, the target number, identity of the target extension and the number of times the call was dialled. Call will be declined, if the parameters of dialedNumber and the extensonId are null. If *90 is dialed, the sample program sets "do not disturb" state and declines every call. To change it, dial *91. If you do not want to forward the call, you can give back the null value and the call will be handeled by the rules of dial plan.
Sub Initialized() Dim opsClient As OpsClient = New OpsClient() Dim result = opsClient.Login("ozekixepbx.ip", "admin", "abc12345") opsClient.SetCallRoutingInterceptor(New MyCallRoutingInterceptor()) End Sub Public Class MyCallRoutingInterceptor Implements ICallRoutingInterceptor Private DnDExtensions As List(Of String) = New List(Of String) Private sync As Object = New Object() Public Function GetDestination(ByVal routeParams As OPSSDKCommon.Model.Route.RouteParams) As OPSSDKCommon.Model.Route.Destination Implements OPSSDK.ICallRoutingInterceptor.GetDestination SyncLock (sync) If (DnDExtensions.Contains(routeParams.Destination.DialedNumber)) Then Return New Destination(routeParams.CallerInfo.Owner, Nothing, Nothing, 10) ElseIf (routeParams.Destination.DialedNumber = "*90" And Not DnDExtensions.Contains(routeParams.CallerInfo.Owner)) Then DnDExtensions.Add(routeParams.CallerInfo.Owner) ElseIf (routeParams.Destination.DialedNumber = "*91" And DnDExtensions.Contains(routeParams.CallerInfo.Owner)) Then DnDExtensions.Remove(routeParams.CallerInfo.Owner) End If End SyncLock Return Nothing End Function End Class
If you have any questions or need assistance, please contact us at firstname.lastname@example.org
People who read this also read...
Cookies are enabled You are browsing the optimized version of this website. For more information read this website.