by byron.hopp » Tue Jul 16, 2024 8:07 pm
Here is my code, modified yours a little. Had to use my logging function. Using the Twilio API seems to work great, it the crashing of the program I can't figure out. Thanks, in advance. Line number in the hb_out.log file leads me to the "Return nil" statement. Error 6005: Exception error:
Function TwilioText( cTel_To,cBody )
Local cLogFile := "TraceLog.txt"
Local hCurl
Local nError
Local Httpcode
Local cUrl := "https:" + "/" + "/" + "api.twilio.com/2010-04-01/Accounts/" + ACCOUNT_SID + "/Messages.json"
Local cPostFields := 'To=' + cTel_To + chr(38) + "From=" + TEL_FROM + chr(38) + "Body=" + Time() + " " + cBody
Logit( cLogFile, Replicate( "-", 80 ) )
Logit( cLogFile, curl_version() )
Logit( cLogFile, cPostFields )
curl_global_init()
if ! empty( hCurl := curl_easy_init() )
curl_easy_setopt( hCurl, HB_CURLOPT_POST, 1 )
curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )
curl_easy_setopt( hcurl, HB_CURLOPT_POSTFIELDS, cPostFields )
curl_easy_setopt( hCurl, HB_CURLOPT_USERPWD, ACCOUNT_SID + ':' + AUTH_TOKEN )
curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
curl_easy_setopt( hCurl, HB_CURLOPT_VERBOSE, 1 )
curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
nError := curl_easy_perform( hCurl )
curl_easy_getinfo( hCurl, HB_CURLINFO_RESPONSE_CODE, @Httpcode )
Logit( cLogFile, "HttpCode =", nAllTrim( HttpCode ) )
if nError = HB_CURLE_OK
Logit( cLogFile, "SMS sent succesffully" )
Logit( cLogFile, curl_easy_dl_buff_get( hCurl ) )
elseif Httpcode != 200 .AND. Httpcode != 201
Logit( cLogFile, { "SMS send failed, HTTP Status Code ", Httpcode } )
else
Logit( cLogFile, curl_easy_strerror( nError ) )
endif
endif
curl_global_cleanup()
Return nil
Thanks,
Byron Hopp
Matrix Computer Services