FoxPro Programming
How to send SMS with West Wind Internet and client tools for Visual FoxPro?
Gravatar is a globally recognized avatar based on your email address. How to send SMS with West Wind Internet and client tools for Visual FoxPro?
  Denis Chassé
  All
  Feb 3, 2022 @ 07:21am

This is curl code that comes from the Twilio web site

curl -X POST https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json
! --data-urlencode "Body=Hi there"
! --data-urlencode "From=+15017122661"
! --data-urlencode "To=+15558675310"
! -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

I downloaded the shareware version of "West Wind Internet and client tools for Visual FoxPro. I want to be able to sens SMS.

Here's what I tried so far.

DO c:\outilsvfp\westwind\wwClient

*** POST Request TEXT TO lcJson NOSHOW { "Account": "MyAccountInformation", "AuthToken": "MyTokenInformation", "Body": "Simple test ", "From": "+MyTwilioPhoneNumber", "To": " "+PhoneNumberIWantToCall" } ENDTEXT loHttp = CREATEOBJECT("wwHttp") loHttp.cContentType = "application/json" lcResult = loHttp.Post("https://api.twilio.com/2010-04-01/",lcJson)

IF loHttp.nError # 0 MESSAGEBOX( loHttp.cErrorMsg) ENDIF IF loHttp.cResultcode # "200" MESSAGEBOX( "Invalid HTTP response code: " + loHttp.cResultCode) ENDIF MESSAGEBOX( lcResult)

That doesn't work

the result to MESSAGEBOX( loHttp.cErrorMsg) is Method not allowed

The result to MESSAGEBOX( "Invalid HTTP response code: " + loHttp.cResultCode) is Invalid HTTP response code 405"

The result to MESSAGEBOX( lcResult) is

20004Method not allowedhttps://www.twilio.com/docs/errors/20004405"

html UPGRADE

I thought that something like this could help

loHttp.AddProperty( "Body", "Simple test")

instead of all the TEXT TO lcJson. No same errors 😦

Can you helo me?

Gravatar is a globally recognized avatar based on your email address. re: How to send SMS with West Wind Internet and client tools for Visual FoxPro?
  Rick Strahl
  Denis Chassé
  Feb 3, 2022 @ 11:38am

Please edit your post and format the code you posted so we can more easily read your traces and code.

READ THE NOTICE AT THE BOTTOM OF THE EDIT BOX PLEASE.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: How to send SMS with West Wind Internet and client tools for Visual FoxPro?
  Denis Chassé
  Rick Strahl
  Feb 3, 2022 @ 12:16pm

This is curl code that comes from the Twilio web site

curl -X POST https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json \
*!*	--data-urlencode "Body=Hi there" \
*!*	--data-urlencode "From=+15017122661" \
*!*	--data-urlencode "To=+15558675310" \
*!*	-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

I downloaded the shareware version of WestWind. I want to be able to sens SMS with your tools.

Here's what I tried so far.

DO c:\outilsvfp\westwind\wwClient

*** POST Request
TEXT TO lcJson NOSHOW
{
"Account": "MyAccountInformation",
"AuthToken": "MyTokenInformation",
"Body": "Simple test ",
"From": "+MyTwilioPhoneNumber",
"To": " "+PhoneNumberIWantToCall"
}
ENDTEXT

loHttp = CREATEOBJECT("wwHttp")
loHttp.cContentType = "application/json"
lcResult = loHttp.Post("https://api.twilio.com/2010-04-01/",lcJson)

IF loHttp.nError # 0
   MESSAGEBOX( loHttp.cErrorMsg)
ENDIF
IF loHttp.cResultcode # "200"
   MESSAGEBOX( "Invalid HTTP response code: " + loHttp.cResultCode)
ENDIF
MESSAGEBOX( lcResult)

That doesn't work

the result to MESSAGEBOX( loHttp.cErrorMsg) is "Method not allowed"

The result to MESSAGEBOX( "Invalid HTTP response code: " + loHttp.cResultCode) is Invalid HTTP response code 405"

The result to MESSAGEBOX( lcResult) is the following 20004Method not allowedhttps://www.twilio.com/docs/errors/20004405"

Gravatar is a globally recognized avatar based on your email address. re: How to send SMS with West Wind Internet and client tools for Visual FoxPro?
  Rick Strahl
  Denis Chassé
  Feb 3, 2022 @ 02:05pm

Denis,

The CURL trace asks for URL Encoded values not JSON. If you're going to match what the CURL trace has you need to use AddPostKey("key", "value") to add the data not JSON. The method not found is likely because you're sending a content type of application/json when it's expecting application/x-www-form-urlencoded.

This:

curl -X POST https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json \
*!*	--data-urlencode "Body=Hi there" \
*!*	--data-urlencode "From=+15017122661" \
*!*	--data-urlencode "To=+15558675310" \
*!*	-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

translates to:

loHttp = CREATEOBJECT("wwHttp")

*** This should do the BASIC auth that is requested above
loHttp.cUsername = "TWILLIO_ACCOUNT_SID"
loHttp.cPassword = "TWILIO_AUTH_TOKEN"

* Alternately add the AUTH Header explicitly
* loHttp.AddHeader("Authorization", "Basic " + STRCONV("TWILIO_ACCOUNT_SID:TWILIO_AUTH_TOKEN",13))

*** Form post vars
loHttp.AddPostKey("Body","Hi there")
loHttp.AddPostKey("From","+15017122661")
loHttp.AddPostKey("To","+15017122661")

lcJson = loHttp.Post("https://api.twilio.com/2010-04-01/Accounts/TWILIO_ACCOUNT_SID/Messages.json")

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: How to send SMS with West Wind Internet and client tools for Visual FoxPro?
  Bob Roenigk
  Denis Chassé
  Feb 3, 2022 @ 07:54pm

Denis,

The Twilio documentation is rather confusing. I use the following code for Twilio SMS messages.

~bob

    * Send message via Twilio
    oHTTP    = CREATEOBJECT("wwHttp")
    oHTTP.nconnecttimeout    = 2
    oHTTP.AddPostKey("ACCOUNT_SID","ACd02xxxxxxxxxxxxxxxxxxxxxxxxxxx")
    oHTTP.AddPostKey("AUTH_TOKEN","e527f9xxxxxxxxxxxxxxxxxxxxxxxxxxx")
    oHTTP.AddPostKey("To",lcPhone)
    oHTTP.AddPostKey("From","+12125551212")
    oHTTP.AddPostKey("Body",lcName + ", " + lcMessage)

    * Call Twilio API
    lcStatus    = oHTTP.HTTPGet("https://api.twilio.com/2010-04-01/Accounts/ACd02xxxxxxxxxxxxxxxxxxxxxxxxxxxx/Messages.json","ACd02xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","e527f9xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","")
    IF oHTTP.cResultCode <> "201"
        * Query Error.
    ENDIF

    oHTTP = .NULL.

Gravatar is a globally recognized avatar based on your email address. re: How to send SMS with West Wind Internet and client tools for Visual FoxPro?
  Denis Chassé
  Bob Roenigk
  Feb 4, 2022 @ 10:32am

Thank you very much Rick and Bob!

Gravatar is a globally recognized avatar based on your email address. re: How to send SMS with West Wind Internet and client tools for Visual FoxPro?
  Robert Jacobs
  Bob Roenigk
  Jan 17, 2023 @ 01:54pm

Hello

I am longtime VFP developer reviewing WW Internet & Client Tools with a need to use Twilio to both send and receive SMS. We are looking to expand our VFP scheduling solution to send a SMS (i.e. offer a shift to work) to employees one at a time and wait xx seconds for an acceptance reply. Currently this is being done by phone using text-to-speech over a VOIP line. Would anyone have sample code to share showing how to send and receive SMS to help get us started. I beleive the bigger challenge is receiving an acceptance linked to an identifer for the shift offered. Thank you.

Gravatar is a globally recognized avatar based on your email address. re: How to send SMS with West Wind Internet and client tools for Visual FoxPro?
  Robert Jacobs
  Robert Jacobs
  Jan 25, 2023 @ 04:57am

Just a courtesy follow up to let you know that I got Twilio send and receive SMS working using CURL examples. None of this would have been possible without wwHTTP and wwJsonSerializer classes. Going to now purchase the WW Internet & Client Tools. Will also be using SMTP and FTP features along with the DotNetBridge class. Thank you Rick for making this available.

Gravatar is a globally recognized avatar based on your email address. re: How to send SMS with West Wind Internet and client tools for Visual FoxPro?
  Rick Strahl
  Robert Jacobs
  Jan 25, 2023 @ 12:57pm

Good to hear, Robert.

Using these tools you should be able to call just about any JSON based service. The hard part isn't the FoxPro bits - usually it's figuring out what exactly you have to send and using a tool like Postman or West Wind WebSurge to check API behavior before jumping into code is a good idea.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: How to send SMS with West Wind Internet and client tools for Visual FoxPro?
  Harvey Mushman
  Robert Jacobs
  Apr 14, 2024 @ 05:48am

Can you post your solution, a working example will save time for others (like me) rather than having to recreate the wheel... so to speak.

Gravatar is a globally recognized avatar based on your email address. re: How to send SMS with West Wind Internet and client tools for Visual FoxPro?
  Rick Strahl
  Harvey Mushman
  Apr 14, 2024 @ 11:31am

Uh, there's code in this thread...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: How to send SMS with West Wind Internet and client tools for Visual FoxPro?
  Robert Jacobs
  Rick Strahl
  Apr 15, 2024 @ 01:48am

Yes the code to send SMS via Twilio is shown in this thread. Our solution sends SMS and then fetches replies over a fixed interval based on a timestamp range (no webhooks). I have attached a picture to demonstrate messages sent/received/replied.

© 1996-2024