For the HandleTwilioSMS use a URL like: http://MyWebsite.com/MyApi.asmx/HandleTwilioSMS
For HandleTwiliPhone use a URL like: http://MyWebsite.com/TwilioPhoneHandler.aspx
For Decide use “widgets.HandleTwilioPhoneCallAPI.parsed.Status” then set your conditions returned.
Aannnnnnddd your welcome!

1 2 3 4 5 6 7 8 9 10 11 12 |
Public Shared MyTwilio As New List(Of TwilioEndPoint) Public Class TwilioEndPoint Public PhoneNumber As String Public AutoReply As Boolean Public AutoReplyMessage As String Public LastAutoReplyTimestamp As DateTime Public Block As Boolean Public BlockMessage As String Public Forward As Boolean Public ForwardNumber As String End Class |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
Imports Newtonsoft.Json Public Class TwilioPhoneHandler Inherits System.Web.UI.Page Public Class PhoneHandlerResponse Public Property Status As String Public Property Argument1 As String End Class Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Response.Clear() Dim FromNumber = Request.QueryString("FromNumber") Dim MyPhoneHandlerResponse As New PhoneHandlerResponse If Not IsNothing(FromNumber) Then FromNumber = FromNumber.Trim.Replace("+", "") FromNumber = "+" & FromNumber 'Readd '+' sign that was filtered by HTTP Dim MyClient As Global_asax.TwilioEndPoint = GetTwilioItem(FromNumber) If Not IsNothing(MyClient) Then If MyClient.Forward Then MyPhoneHandlerResponse.Status = "forward" MyPhoneHandlerResponse.Argument1 = MyClient.ForwardNumber End If If MyClient.Block Then MyPhoneHandlerResponse.Status = "blocked" End If Else MyPhoneHandlerResponse.Status = "default" 'Goes to Twilio NoCondition, Application call End If Else MyPhoneHandlerResponse.Status = "default" End If If IsNothing(MyPhoneHandlerResponse.Status) Then MyPhoneHandlerResponse.Status = "default" End If Dim StringToReturn = JsonConvert.SerializeObject(MyPhoneHandlerResponse) Response.StatusCode = 200 Response.ContentType = "application/json" Response.Write(StringToReturn) Response.Flush() Response.Close() End Sub End Class |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
<WebMethod()> Public Sub HandleTwilioSMS(ByVal FromNumber As String, ByVal ToNumber As String, ByVal Message As String) If IsNothing(GetTwilioItem(FromNumber)) Then Dim DefaultMessage As String = "Put your default message here" AddTwilioToList(FromNumber, True, DefaultMessage, False, "") End If For Each TwilioClient As Global_asax.TwilioEndPoint In Global_asax.MyTwilio If TwilioClient.PhoneNumber = FromNumber Then If TwilioClient.Block Then If Not IsNothing(TwilioClient.BlockMessage) Then PublicModule.SendSMSWithTwilio(FromNumber, ToNumber, TwilioClient.BlockMessage) Else Throw New Exception("Blocked") End If Return End If If Message = "1" Then PublicModule.SendSMSWithTwilio(FromNumber, ToNumber, "User Sent back Number 1") Return End If If TwilioClient.AutoReply Then If Not IsNothing(TwilioClient.AutoReplyMessage) Then PublicModule.SendSMSWithTwilio(FromNumber, ToNumber, TwilioClient.AutoReplyMessage) End If End If End If Next Try Catch ex As Exception Return End Try End Sub Public Function SendSMSWithTwilio(ByVal FromNumber As String, ByVal ToNumber As String, ByVal Body As String) As Boolean Try Net.ServicePointManager.SecurityProtocol = 3072 Dim accountSid As String = "PutAccountSidHere" Dim accountToken As String = "PutTokenHere" Twilio.TwilioClient.Init(accountSid, accountToken) 'From = Dest 'ToNumber = Should be your registered Twilio Number Dim CreateMessageOptions As New CreateMessageOptions(New Twilio.Types.PhoneNumber(FromNumber)) CreateMessageOptions.Body = Body CreateMessageOptions.From = New Twilio.Types.PhoneNumber(ToNumber) Dim res = MessageResource.Create(CreateMessageOptions) Debug.WriteLine("Message SID: " & res.Sid) Catch ex As Exception Debug.WriteLine(ex.Message) Return False End Try Return True End Function |