Skip to content

Instantly share code, notes, and snippets.

@grokify
Last active Oct 23, 2018
Embed
What would you like to do?
Using RingCentral .NET SDK with VB.NET for SMS and Presence Notifications
' VB.NET Demo using C# SDK 1.0.0 at:
' GitHub: https://github.com/ringcentral/ringcentral-csharp
' Nuget: https://www.nuget.org/packages/RingCentralSDK/
' Use by adding RingCentralSDK Nuget package
Imports RingCentral
Imports RingCentral.Http
Module Module1
Sub handleConnectEvent(sender, args)
Console.WriteLine("connect:")
Console.WriteLine(args.Message)
End Sub
Sub handleNotificationEvent(sender, args)
Console.WriteLine("notification:")
Console.WriteLine(args.Message)
End Sub
Sub handleErrorEvent(sender, args)
Console.WriteLine("error:")
Console.WriteLine(args.Message)
End Sub
Sub Main()
Dim appKey = "myAppKey"
Dim appSecret = "myAppSecret"
Dim serverUrl = "https://platform.devtest.ringcentral.com"
Dim username = "12223334444"
Dim extension = "101"
Dim password = "myPassword"
Dim smsFrom = "12223334444"
Dim smsTo = "19998887777"
Dim sdk = New SDK(appKey, appSecret, serverUrl, "VB.NET Demo", "1.0.0")
sdk.Platform.Login(username, extension, password, True)
Dim jsonSmsString As [String] = "{""from"":{""phoneNumber"":""" & smsFrom & """},""to"":[{""phoneNumber"":""" & smsTo & """}],""text"":""Hello VB.NET""}"
Dim request As New Request("/restapi/v1.0/account/~/extension/~/sms", jsonSmsString)
Dim response As ApiResponse = sdk.Platform.Post(request)
Console.WriteLine(response.Body)
Dim subscription = sdk.CreateSubscription()
subscription.EventFilters.Add("/restapi/v1.0/account/~/extension/~/message-store")
subscription.EventFilters.Add("/restapi/v1.0/account/~/extension/~/presence")
' Using Anonymous Functions
AddHandler subscription.ConnectEvent, Function(sender, args)
Console.WriteLine("connect:")
Console.WriteLine(args.Message)
End Function
AddHandler subscription.NotificationEvent, Function(sender, args)
Console.WriteLine("notification:")
Console.WriteLine(args.Message)
End Function
AddHandler subscription.ErrorEvent, Function(sender, args)
Console.WriteLine("error:")
Console.WriteLine(args.Message)
End Function
' Using Named Functions
' AddHandler subscription.ConnectEvent, AddressOf handleConnectEvent
' AddHandler subscription.NotificationEvent, AddressOf handleNotificationEvent
' AddHandler subscription.ErrorEvent, AddressOf handleErrorEvent
subscription.Register()
Dim wait = Console.ReadLine()
Console.WriteLine("DONE")
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment