AutoIt Requires Chilkat v11.0.0+
AutoIt
Send an SMS verification code with Twilio Verify
See more Twilio Examples
Live SMS. When a user requests a code, pass their phone number in E.164 format (for example, +12025550123) and select the SMS channel. Create a Verify Service in the Twilio Console first. Supply its VA service SID and an API key with access to that service. For a live test, use a phone you control. Messaging and verification charges may apply.
Twilio generates the code and sends it to the phone. A pending response means the application can prompt for the code. Save the returned VE verification SID with the user and phone number that initiated the request, then use it to check the code entered by the user.
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("/Verifications")
$oReq = ObjCreate("Chilkat.HttpRequest")
$oReq.HttpVerb = "POST"
$oReq.ContentType = "application/x-www-form-urlencoded"
; Supply the number the user asked to verify. AddParam encodes the leading plus sign.
$oReq.AddParam "To","PHONE_NUMBER_IN_E164_FORMAT"
$oReq.AddParam "Channel","sms"
$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
$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 <> "pending") Then
ConsoleWrite("Verification status: " & $status & @CRLF)
Exit
EndIf
If (($oResult.JsonTypeOf("sid") <> 1) Or ($oResult.StringOf("sid") = "")) Then
ConsoleWrite("The pending response did not include a verification SID." & @CRLF)
Exit
EndIf
; Save this SID with the pending attempt before prompting the user for the code.
ConsoleWrite("Pending verification SID: " & $oResult.StringOf("sid") & @CRLF)