VB.Net SMS Script
In Ozeki SMS Gateway You can write a script, that allows you to run Visual Basic .NET code when an SMS message arrives. This script can implement any logic to do various tasks with the incoming messages, and optionally send response SMS messages.
How to run .NET code when an SMS arrives (Rapid steps)
To run .NET code when an SMS arrives:
- Launch Ozeki SMS Gateway
- Select Add new user or application
- Install Visual Basic script service
- Name the connection
- Provide the source of the script
- Enable connection
- Receive test SMS
- Check the logs
Step 1 - Add new user/application...
You can simply install the Visual Basic script User on the 'Management' console by clicking 'Add new user/application...' in the 'Users/Applications' panel (Figure 1).
Step 2 - Add Visual Basic script
An interface will open consisting of two panels. The left side panel contains the already installed users and applications. The right-side panel contains the users and applications you can install with a brief description next to them. Search the Visual Basic script User and click the blue 'install' button next to it (Figure 2).
Step 3 - Provide the script
The 'Configuration' panel has a 'General' tab which contains the basic settings. First please provide a unique Name. In the Script section of tab page contains the source of the script you wish to execute (Figure 3).
Step 4 - Enable user
Please enable to user with the Connection switch and in the Events tab view that the Script is compiled, and the user is initialized successfully (Figure 4).
Step 5 - Message received
Finally, you can see if a message is received by this user the script will run and as this example works the response SMS message is sent to the Original sender (Figure 5).
Visual Basic programming guide
Create a class named 'Program' in the 'Ozeki' namespace. You may also include the necessary using directives.
Imports System Namespace Ozeki Public Class Program End Class End Namespace
Implement the 'Receive' function inside the 'Program' class. This function will be called when your connection receives a message. The parameter of the 'Receive' function will be an object with the type of 'Message'.
Imports System Namespace Ozeki Public Class Program Public Sub Receive(ByVal msg As Message) End Sub End Class End Namespace
Send a reply message
When receiving a message, you may send a reply to notify your sender of successful delivery. To achieve this, you may use the built-in 'Reply' function.
Imports System Namespace Ozeki Public Class Program Public Sub Receive(ByVal msg As Message) Reply(msg, "Thank you for the message!") End Sub End Class End Namespace
Message forwarding
You may also forward your received message to another connection by using the 'Send' function.
Imports System Namespace Ozeki Public Class Program Public Sub Receive(ByVal msg As Message) Send("admin@localhost", msg.Text) End Sub End Class End Namespace
Compose your message
Composing a message is easier, than you think. You just need to use the built-in 'Message' type to create a new message object. In the following example, when a message was received, we will create and send a new message to the admin connection.
Imports System Namespace Ozeki Public Class Program Public Sub Receive(ByVal msg As Message) Dim message = New Message() message.Text = "Hello World!" message.ToAddress = "+4412345678910" message.ToConnection = "admin@localhost" message.FromAddress = "+448888999910" Send(message) End Sub End Class End Namespace
Logging
Using log messages will make debugging your script much easier. By calling the 'Log' function you may implement proper logging in your script if needed.
Imports System Namespace Ozeki Public Class Program Public Sub Receive(ByVal msg As Message) Log("Message received: " & msg.Text) End Sub End Class End Namespace
Summary
By reading this guide, you have learned how to write a script in the Ozeki SMS Gateway that allows you to run VB.NET code when an SMS message arrives. This way you can make it do tasks with the incoming messages, organize your message storage constantly and send response SMS messages if it is needed. If you have followed the instructions above, you have taken momentous steps in becoming a better Visual Basic software developer.
Learn more about the Visual Basic programming language and developing your messaging system on the Ozeki website. Study the VB.NET database SMS example in the next tutorial.
Let's put into practice what you have learned. Download the Ozeki SMS Gateway now!
More information
- How to run .NET code when an SMS arrives
- VB.NET database SMS example guide
- VB.NET HTTP SMS example