How to Curl for text messaging

Re: How to Curl for text messaging

Postby TimStone » Wed Jul 20, 2022 4:47 pm

I find this interesting, but I'm curious about the receiving of text messages.

It appears I would need to setup a server to receive them. I actually want my clients to send and receive them independently from me. They do not have available servers.

Is there any further work done on this topic, and especially the receiving ?

Curl is not an issue for me. I already use it for JSON interfaces.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2904
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: How to Curl for text messaging

Postby NWKL » Sat Aug 13, 2022 11:31 am

Hi, i start with twilio, this code is working or have upgrades?
very thanks
NWKL
 
Posts: 25
Joined: Thu Aug 04, 2022 12:45 pm

Re: How to Curl for text messaging

Postby NWKL » Sat Aug 13, 2022 11:32 am

Hi, i will start with twilio, this code is working? have upgrades? can you share?

very thanks

reinaldocrespo wrote:Thank you very very very much.

I hope to see you all this time around the sun.

Below is short sample on how to send text messages with Twilio using curl.

Code: Select all  Expand view

#include "hbcurl.ch"

#define ACCOUNT_SID  "XxxxxxxxXxXXXX"
#define AUTH_TOKEN   "Twilio-Acc-Token
#define TEL_FROM     "
YourTwilioNumber"
#define TEL_TO       "
555-555-5555"


function main()
   Local hCurl
   Local nError, httpcode
   Local cUrl     := "
https://api.twilio.com/2010-04-01/Accounts/" + ACCOUNT_SID + "/Messages.json"
   Local cPostFields := 'To='    + TEL_TO +;
                        "&From=" + TEL_FROM +;
                        "&Body=" + Time() + " SMS From TestTwilio.exe"

   logdata( "trace.log", Replicate( "-", 80 ) )
   logdata( "Trace.log", curl_version() )
   logdata( "Trace.log", 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 )
      logdata( "trace.log", { "nError = ", nError, ValType( nError ), "httpcode =", httpcode, ValType( httpcode ) } )

      if nError = HB_CURLE_OK

         logdata( "Trace.log", "SMS sent succesffully" )
         logdata( "Trace.log", curl_easy_dl_buff_get( hCurl ) )

      elseif httpcode != 200 .AND. httpcode != 201

         logdata( "Trace.log", { "SMS send failed, HTTP Status Code ", httpcode } )

      else

         logdata( "Trace.log", curl_easy_strerror( nError ) )

      endif

   endif

   curl_global_cleanup()

RETURN NIl
 


Twilio sends any replies as an http post web hook. So you would need to have an http server capable of receiving posts. After writing this whole project with Java, I decided I did not want to keep maintaining Java code. So I rewrote the whole thing with harbour and for the http server I was able to have it work with pure mod_harbor under Apache. With this combination you can setup a full automated text and reply responses using Twilio.

My implementation sends medical appointment reminder texts to patients cell numbers. The patient can reply 1 to confirm or 2 to cancel. The sending texts program is a harbour service. The replies receiving app is all mod_harbour running under Apache.

Hope it helps.

Reinaldo.

Reinaldo.
NWKL
 
Posts: 25
Joined: Thu Aug 04, 2022 12:45 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 82 guests