Reputation: 95
I looked everywhere for a VB.NET example for Twilio SMS and MMS messages, after coming up empty I put one together myself. Here is the complete code. It uses a config file to store SID, Token and Caller. It is setup to take 4 parameters at run time. It is a Console app created in Visual Studio 2012.
Upvotes: 1
Views: 2510
Reputation: 3
looks like you were spanked for not instantiating your object prior to use? Post = New Post(Question) Post.Answer = MyAnswer.text Thus the error message for accessing a nul object. :-)
Upvotes: 0
Reputation: 95
Imports System.Configuration
Imports System.Collections.Specialized
Imports System
Imports RestSharp
Imports Twilio
Module Module1
' Twilio REST API version
Const API_VERSION As String = "2010-04-01"
Sub Main(ByVal CmdArgs() As String)
Dim account As Twilio.TwilioRestClient
Dim TwiGetInfo As Twilio.TwilioRestClient
'Dim recList As Twilio.MessageListRequest
Dim message As Twilio.Message
Dim to1 As String
Dim strBody As String
Dim SID As String
Dim Token As String
Dim Caller As String
Dim PostBackURL As String
Dim strFriendlyName As String
Dim strEventID As String
Dim SendID As String
If CmdArgs.Length < 1 Then
Console.WriteLine("Both a phone number and message variable are needed")
Console.WriteLine("Press any key to exit")
Console.ReadKey()
Exit Sub
End If
strFriendlyName = CmdArgs(0)
to1 = CmdArgs(1)
strEventID = CmdArgs(2)
strBody = CmdArgs(3)
SID = ConfigurationManager.AppSettings("Key0")
Token = ConfigurationManager.AppSettings("Key1")
Caller = ConfigurationManager.AppSettings("Key2")
PostBackURL = "http://173.111.111.110:8001/XMLResponse.aspx"
' Create Twilio REST account object using Twilio account ID and token
account = New Twilio.TwilioRestClient(SID, Token)
message = New Twilio.Message
Dim ArrMedia(0) As String
ArrMedia(0) = Nothing
Try
'Overload 1
Console.WriteLine(account.SendSmsMessage(Caller, to1, strBody, PostBackURL))
'Overload 1 - Sends with an Image
'Console.WriteLine(account.SendMessage(Caller, to1, strBody, ArrMedia, PostBackURL))
Catch e As Exception
Console.WriteLine("An error occurred: {0}", e.Message)
End Try
Console.WriteLine("Press any key to continue")
Console.ReadKey()
End Sub
End Module
Upvotes: 3