Home
RECOMMENDED FOR YOU:
SMS Gateway software
Ozeki brings you outstanding
SMS Gateway technology. Use our SMS Server products on Windows,Linux, or Android

C# SMS API
Developers can use our C# SMS API to send SMS from C#.Net. The C# SMS API comes with full source code

PHP SMS API
The ozeki PHP SMS gateway software can be used to send SMS from PHP and to receive SMS usig PHP on your website

SMPP SMS Gateway
SMS service providers use our SMPP gateway solution, that offers a high performance SMPP server and SMPP client gateway with amazing routing capabilities

Visual Basic .NET VoIP developers 101

Part 1: VB example on sending SMS, making VoIP calls

Read this short guide and learn how to do basic tasks with the Ozeki Phone System, from your VB .NET application. This guide explains how to receive and make voice calls, how to receive and send SMS messages and helps you get started to build more advanced projects.

Download

VB example on sending SMS, making VoIP calls
  1. OPS_SimpleExamples_Visual_Basic_Source.zip (23.2 MB)
  2. OPS_SimpleExamples_Visual_Basic_Exedemo.zip (12 KB)
  3. http://www.ozekiphone.com/examples/doc/

Part 2: Visual Basic example on recording VoIP calls, call routing

1. What you need

2. Get started

  • Create an API extension with the Ozeki Phone System
  • Create a Visual Basic project and add OzekiXE.dll
  • Grab OPSSDK.dll (You can find OPSSDK.dll at
    C:\Program Files\Ozeki\Ozeki Phone System\Examples.NET API\OPSSDK.dll).
  • You need to add it as a reference to your Visual Basic project

First you need to add the OPSSDK.dll reference to the project. This can be done on the 'Browse' tab of the 'Project' menu 'Add Reference' menu pointű (Figure 1).

how to add reference microsoft visual studio
Figure 1 - Browse tab

How to connect to the Ozeki Phone System

To connect to the Ozeki Phone System first you need to create an instance of an OpsClient class. By calling the 'Login' function of this instance, you can login to the Ozeki Phone System. The 'Login' function has 3 parameters, the first is the IP address of the OPS server, the second is the username and the third is the password belonging to the username. The return value of the 'Login' function shows if the login was successfull or not. By default you can login to the Ozeki Phone System with the 'admin' username. You can add new users by clicking on the 'Connections' menu 'Office users' menu point and clicking on the 'Add user' button. Whether a user can login to the Ozeki Phone System through the API, depends on the value of the 'User access profile'. It is possible to create multiple user access profiles. This can be done on the Security form of the Ozeki Phone System's 'Features' menu, 'Preferences' menu point. You can allow the user access to the Ozeki Phone System through the API by clicking on the 'Allow this user to configure the PBX through the API' option.

After successfully signing in you need find out the number of the API extension, this can be done by calling the 'GetAPIExtension' function. The input parameter of this function is the extension ID. If there is no extension with the given ID, then the 'nothing' value will be the output value of the function. With the API extension the calls and messages can be handled. You can add an API extension through the 'Connections' menu, 'Extensions' menupoint. There are three kind of available API extensions: SQL, HTML and .NET API. When adding an API extensions you need assign an extension ID to it. The route of a call is determined by the Dial Plan rules. One rule can determine that from which extension to which extension should a call be transfered, it is also possible to give it a prefix. From the prefix the extension can be identified, which will handle the communication. These rules can be handled from the 'Connections' menu, 'Dial plan' menu point. Rules like this can be given on outgoing, incoming or unsuccessful calls, and also for messages.

3. Receive incoming voice calls

To accept a call you need to subscribe to the 'IncomingCall' event of the API extension, which happens when a call comes in. In the event handler the incoming call is in the 'VoIPEventArgs(Of <ICall>)' item's attribute. It is possible to accept the call, refuse or route it.

Sub Initialize()
	Dim opsClient = New OpsClient()
	Dim result = client.Login("ozekixepbx.ip", "admin", "abc12345")
	Dim apiExtension = client.GetAPIExtension("4324")
	AddHandler apiExtension.IncomingCall, AddressOf IncomingCall
End Sub

Sub IncomingCall(ByVal sender As Object, ByVal e As VoIPEventArgs(Of ICall))
	Dim phoneCall = e.item

	phoneCall.Accept()
	'phoneCall.Reject()
	'phoneCall.Forward("432432")
End Sub
	

Code 1 - Visual Basic code to accept calls

4. Make outgoing voice calls

To start a call you need to call the 'CreateCall' method of the extension, and you also need to subscribe to the 'CallStateChanged' and the 'CallErrorOccured' events of the call. The 'CallStateChanged' event occurs when the state of the call changes. The 'CallErrorOccured' event occurs when there is an error during the call. You can connect a speaker to the call with the 'ConnectAudioReciever' method and a microphone with the 'ConnectAudioSender' method. It is possible to connect different type of media handlers, for example a Microphone, MP3StreamPlayback, MP3StreaRecorder, Speaker, SpeachToText, TextToSpeech, WaveStreamPlayback, WaveStreamRecorder. With the help of these the call can be recorded, a text can be converted to speach and a text can be made from the call. You can start the call with the 'Start()' method.

Sub Initalize()
    Dim opsClient As OpsClient = New OpsClient()
    Dim result = opsClient.Login("ozekixepbx.ip", "admin", "abc12345")
    Dim apiExtension = opsClient.GetAPIExtension("4324")
    Dim phoneCall = apiExtension.CreateCall("2343242")
    AddHandler phoneCall.CallStateChanged, AddressOf call_CallStateChanged
    AddHandler phoneCall.CallErrorOccurred, AddressOf call_CallErrorOccured

    phoneCall.ConnectAudioReceiver(Speaker.GetDefaultDevice())
	phoneCall.ConnectAudioSender(Microphone.GetDefaultDevice())

	phoneCall.Start()
	End Sub

Sub call_CallStateChanged(ByVal sender As Object, ByVal e As VoIPEventArgs(Of CallState))
	Console.WriteLine("Call state changed: {0}", e.Item)
End Sub

Private Sub call_CallErrorOccured(ByVal sender As Object, ByVal e VoIPEventArgs(Of CallError))
    Console.WriteLine("Call error occurred: {0}", e.Item)
End Sub
	

Code 2 - Visual Basic code to make a call

Make a call and read a text using text to speach

To start a call you need to call the 'CreateCall' method of the extension, and also subscribe to the 'CallStateChanged' and the 'CallErrorOccured' events of the call. The 'CallStateChanged' event occurs when the state of the call changes. The 'CallErrorOccured' event occurs when there is an error during the call. To read a text you need to create an instance of the TextToSpeech class, then subscribe to the 'Stopped' and 'CallStateChanged' events. When a 'CallStateChanged' event occurs, we can connect the TextToSpeach object to the call, then we start the reading with the 'AddAndStartText' method. You can start the call with the 'Start()' method.

Sub Initialize()
	Dim opsClient As OpsClient = New OpsClient()
	Dim result = opsClient.Login("ozekixepbx.ip", "admin", "abc12345")
	Dim apiExtension = opsClient.GetAPIExtension("4324")
	Dim phoneCall = apiExtension.CreateCall("2343242")

	AddHandler phoneCall.CallStateChanged, AddressOf call_CallStateChanged
	AddHandler phoneCall.CallErrorOccurred, AddressOf call_CallErrorOccured

	phoneCall.ConnectAudioReceiver(Speaker.GetDefaultDevice())
	phoneCall.ConnectAudioSender(Microphone.GetDefaultDevice())

	Dim textToSpeech = New TextToSpeech()

	AddHandler textToSpeech.Stopped, Sub(sender As Object, e As Ozeki.VoIP.VoIPEventArgs(Of OPSSDKCommon.Model.Call.CallState))
										HangupCall()
									End Sub
	AddHandler phoneCall.CallStateChanged, Sub(sender As Object, e As Ozeki.VoIP.VoIPEventArgs(Of OPSSDKCommon.Model.Call.CallState))
												If (e.Item.IsInCall()) Then
													phoneCall.ConnectAudioSender(textToSpeech)
													textToSpeech.AddAndStartText("Hello")
												End If
											End Sub
	phoneCall.Start()
End Sub

Private Sub HangupCall()
	If (Not IsNothing(phoneCall)) Then
		phoneCall.HangUp()
		phoneCall = Nothing
	End If
End Sub
	

Code 3 - Visual Basic code for calling and texting functions

5. Receive SMS message

To handle SMS messages you need to add an SMPP connection or an SMS Modem outside line to the Ozeki Phone System, this can be done in the 'Connections' menu, 'Outside lines' menu point. After this you need to add a new rule in the Dial Plan, so the SMS messages need to be forwarded through the correct outside lines.

To receive SMS messages you need to subscribe to the 'MessageReceived' event of the extension, this occurs when a new message arrives. The content and sender of the message are in the 'Content' and 'Sender' properties of the 'Message' parameter type.

Sub Initialize()
	Dim opsClient = New OpsClient()
	Dim result = client.Login("ozekixepbx.ip", "admin", "abc12345")
	Dim apiExtension = client.GetAPIExtension("4324")
	AddHandler apiExtension.MessageReceived, AddressOf MessageReceived
End Sub

Sub MessageReceived(ByVal sender As Object, ByVal e As Message)
	Console.WriteLine("Message received from: {0}, content: {1}", e.Sender, e.Content)
End Sub
	

Code 4 - Visual Basic code to receive SMS with MessageReceived

6. Send SMS message

To send an SMS you need to subscribe to the 'MessageDelivered' and the 'MessageSubmitted' events. 'MessageDelivered' event occurs when the recipient has read the content of the message. 'MessageSubmitted' event occurs, when the message has been received by the provider. After this you need to create an instance of the 'SMSMessage' class, the first parameter of it is the phone number of the recipient, the second parameter is the message. The message can be sent by the extension's 'SendMessage' method.

Sub Initialize()
	Dim opsClient As OpsClient = New OpsClient()

	Dim result = opsClient.Login("ozekixepbx.ip", "admin", "abc12345")
	Dim apiExtension = opsClient.GetAPIExtension("4234"
	AddHandler apiExtension.MessageDelivered, AddressOf apiExtension_MessageDelivered
	AddHandler apiExtension.MessageSubmitted, AddressOf apiExtension_MessageSubmitted

	Dim sms = New SMSMessage("+363023424", "Hello")
	apiExtension.SendMessage(sms)
End Sub

Private Sub apiExtension_MessageDelivered(ByVal sender As Object, ByVal e As OPSSDKCommon.Model.Message.MessageResultEventArgs)
	Console.WriteLine("Delivery result: {0}", e.Result)
End Sub

Private Sub apiExtension_MessageSubmitted(ByVal sender As Object, ByVal e As OPSSDKCommon.Model.Message.MessageResultEventArgs)
	Console.WriteLine("Submit result: {0}", e.Result)
End Sub
	

Code 5 - Visual Basic code to send SMS messages

7. Create a more advanced project

The Ozeki Phone System offers much more options for C#.net developers. You can interact with existing calls, control and configure the PBX, you can introduce new communication techniques and media formats.
For a complete list of .NET API commands, check out: http://www.ozekiphone.com/examples/doc/

Part 2: Visual Basic example on recording VoIP calls, call routing

If you have any questions or need assistance, please contact us at  info@ozekiphone.com

Dig deeper!
People who read this also read...

More information