Xojo Plugin Requires Chilkat v11.0.0+
Xojo Plugin
Check an SMS verification code with Twilio Verify
See more Twilio Examples
After the user enters the SMS code, retrieve the VE verification SID saved when you started the verification. Send that SID and the entered code to the same Verify Service. Keep the code as text so a leading zero survives.
Mark the phone number on that pending attempt as verified only when Twilio returns status=approved. A pending check leaves the number unverified. Twilio can return HTTP 404 after expiration, approval, or exhaustion of check attempts. Keep a successful result in your application so it can be used after Twilio removes the verification.
Chilkat Xojo Plugin Downloads
Dim success As Boolean
success = False
// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Obtain these credentials from the application's private configuration.
Dim http As New Chilkat.Http
http.RequireSslCertVerify = True
http.BasicAuth = True
http.Login = "YOUR_API_KEY_SID"
http.Password = "YOUR_API_KEY_SECRET"
// Both requests use the same Verify Service SID (VA...).
Dim url As New Chilkat.StringBuilder
success = url.Append("https://verify.twilio.com/v2/Services/")
success = url.Append("YOUR_VERIFY_SERVICE_SID")
success = url.Append("/VerificationCheck")
Dim req As New Chilkat.HttpRequest
req.HttpVerb = "POST"
req.ContentType = "application/x-www-form-urlencoded"
// Load the saved SID for this user's pending attempt. Take only the code from user input.
Dim verificationSid As String
verificationSid = "SAVED_VERIFICATION_SID"
Dim enteredCode As String
enteredCode = "CODE_ENTERED_BY_USER"
req.AddParam "VerificationSid",verificationSid
req.AddParam "Code",enteredCode
Dim resp As New Chilkat.HttpResponse
success = http.HttpReq(url.GetAsString(),req,resp)
If (resp.StatusCode = 0) Then
System.DebugLog("No response from Twilio. Check connectivity and TLS settings.")
Return
End If
If (resp.StatusCode = 404) Then
System.DebugLog("No active verification found. Check the service and verification SIDs.")
Return
End If
Dim result As New Chilkat.JsonObject
Dim parsed As Boolean
parsed = result.Load(resp.BodyStr)
If ((success <> True) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
System.DebugLog("Twilio returned HTTP " + Str(resp.StatusCode))
If ((parsed = True) And (result.JsonTypeOf("code") = 2)) Then
System.DebugLog("Twilio error code: " + Str(result.IntOf("code")))
End If
Return
End If
If ((parsed <> True) Or (result.JsonTypeOf("status") <> 1)) Then
System.DebugLog("Verification status missing from the response.")
Return
End If
Dim status As String
status = result.StringOf("status")
If (status = "approved") Then
// Record success for the user and phone number associated with verificationSid.
System.DebugLog("Phone number verified.")
Else
If (status = "pending") Then
System.DebugLog("Code not accepted. Check the digits and enter the code again.")
Else
System.DebugLog("Phone number unverified. Verification status: " + status)
End If
End If