AutoIt Requires Chilkat v11.0.0+
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
; Obtain these credentials from the application's private configuration.
$oHttp = ObjCreate("Chilkat.Http")
$oHttp.RequireSslCertVerify = True
$oHttp.BasicAuth = True
$oHttp.Login = "YOUR_API_KEY_SID"
$oHttp.Password = "YOUR_API_KEY_SECRET"
; Both requests use the same Verify Service SID (VA...).
$oUrl = ObjCreate("Chilkat.StringBuilder")
$oUrl.Append("https://verify.twilio.com/v2/Services/")
$oUrl.Append("YOUR_VERIFY_SERVICE_SID")
$oUrl.Append("/VerificationCheck")
$oReq = ObjCreate("Chilkat.HttpRequest")
$oReq.HttpVerb = "POST"
$oReq.ContentType = "application/x-www-form-urlencoded"
; Load the saved SID for this user's pending attempt. Take only the code from user input.
Local $sVerificationSid = "SAVED_VERIFICATION_SID"
Local $sEnteredCode = "CODE_ENTERED_BY_USER"
$oReq.AddParam "VerificationSid",$sVerificationSid
$oReq.AddParam "Code",$sEnteredCode
$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpReq($oUrl.GetAsString(),$oReq,$oResp)
If ($oResp.StatusCode = 0) Then
ConsoleWrite("No response from Twilio. Check connectivity and TLS settings." & @CRLF)
Exit
EndIf
If ($oResp.StatusCode = 404) Then
ConsoleWrite("No active verification found. Check the service and verification SIDs." & @CRLF)
Exit
EndIf
$oResult = ObjCreate("Chilkat.JsonObject")
Local $bParsed = $oResult.Load($oResp.BodyStr)
If (($bSuccess <> True) Or ($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
ConsoleWrite("Twilio returned HTTP " & $oResp.StatusCode & @CRLF)
If (($bParsed = True) And ($oResult.JsonTypeOf("code") = 2)) Then
ConsoleWrite("Twilio error code: " & $oResult.IntOf("code") & @CRLF)
EndIf
Exit
EndIf
If (($bParsed <> True) Or ($oResult.JsonTypeOf("status") <> 1)) Then
ConsoleWrite("Verification status missing from the response." & @CRLF)
Exit
EndIf
Local $status = $oResult.StringOf("status")
If ($status = "approved") Then
; Record success for the user and phone number associated with verificationSid.
ConsoleWrite("Phone number verified." & @CRLF)
Else
If ($status = "pending") Then
ConsoleWrite("Code not accepted. Check the digits and enter the code again." & @CRLF)
Else
ConsoleWrite("Phone number unverified. Verification status: " & $status & @CRLF)
EndIf
EndIf