Sending Text Messages From 4D

classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Sending Text Messages From 4D

4D Tech mailing list
I have a client that has asked me to add the option to send text messages to cell phones from 4D. I know this is possible via some websites or web services for a fee. Has anyone done this and can recommend a web service that you were able to use from 4D to do this?

Tim

*****************************************
Tim Nevels
Innovative Solutions
785-749-3444
[hidden email]
*****************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
I know the Bertrand Soubeyrand provide a product doing this.
https://www.soubeyrand-4d-developer.eu/



-----
Patrick EMANUEL
------------------------------------------------------------
Administrator
www.association-qualisoft.eu
(Soft1002, Simply Asso & QS_Toolbox)
--
Sent from: http://4d.1045681.n5.nabble.com/4D-Tech-f1376241.html
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Tim, we've been using Twilio with a lot of success.

https://www.twilio.com/sms

Darin

On Wed, Aug 22, 2018 at 9:04 AM Tim Nevels via 4D_Tech <[hidden email]>
wrote:

> I have a client that has asked me to add the option to send text messages
> to cell phones from 4D. I know this is possible via some websites or web
> services for a fee. Has anyone done this and can recommend a web service
> that you were able to use from 4D to do this?
>
> Tim
>
> *****************************************
> Tim Nevels
> Innovative Solutions
> 785-749-3444
> [hidden email]
> *****************************************
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
Same here.

> On Aug 22, 2018, at 10:10 AM, Darin Schroeder via 4D_Tech <[hidden email]> wrote:
>
> Tim, we've been using Twilio with a lot of success.
>
> https://www.twilio.com/sms

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
In reply to this post by 4D Tech mailing list
I have been using http://plivo.com and it has worked well. I use it for sending out PIN #s for people to use when logging in.

Dani


> On Aug 22, 2018, at 8:10 AM, Darin Schroeder via 4D_Tech <[hidden email]> wrote:
>
> Tim, we've been using Twilio with a lot of success.
>
> https://www.twilio.com/sms
>
> Darin
>
> On Wed, Aug 22, 2018 at 9:04 AM Tim Nevels via 4D_Tech <[hidden email]>
> wrote:
>
>> I have a client that has asked me to add the option to send text messages
>> to cell phones from 4D. I know this is possible via some websites or web
>> services for a fee. Has anyone done this and can recommend a web service
>> that you were able to use from 4D to do this?
>>
>> Tim
>>
>> *****************************************
>> Tim Nevels
>> Innovative Solutions
>> 785-749-3444
>> [hidden email]
>> *****************************************
>>
>> **********************************************************************
>> 4D Internet Users Group (4D iNUG)
>> Archive:  http://lists.4d.com/archives.html
>> Options: https://lists.4d.com/mailman/options/4d_tech
>> Unsub:  mailto:[hidden email]
>> **********************************************************************
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
In reply to this post by 4D Tech mailing list
This has been working for us, but we only use it occasionally.

$err:=SMTP_QuickSend ($Host;$FromAddress;$msgTo;$subject;$message;0;25;$vAuthUserName;$sequence)
where $msgTo is a text/phone# like [hidden email]

Keith - CDI

> On Aug 22, 2018, at 9:04 AM, Tim Nevels via 4D_Tech <[hidden email]> wrote:
>
> I have a client that has asked me to add the option to send text messages to cell phones from 4D. I know this is possible via some websites or web services for a fee. Has anyone done this and can recommend a web service that you were able to use from 4D to do this?
>
> Tim
>
> *****************************************
> Tim Nevels
> Innovative Solutions
> 785-749-3444
> [hidden email]
> *****************************************
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Tim,

We had a need to send texts to company employees so we have the luxury of knowing the cell phone provider.  So, we use something like this…


Case of

: ([User]Company Cell Phone Provider="AT&T")

aEmailAddress{1}:=$cellPhoneNum+"@txt.att.net"

emSEND EMAIL ("Linbeck Lean Video";<>CR+[Video]Web Address;$fromAddress;"aEmailAddress";"";"";"")



: ([User]Company Cell Phone Provider="Verizon")

aEmailAddress{1}:=$cellPhoneNum+"@vtext.com"

emSEND EMAIL ("Linbeck Lean Video";<>CR+[Video]Web Address;$fromAddress;"aEmailAddress";"";"";"")



End case

Jim Hassler

On Aug 22, 2018, at 9:04 AM, Tim Nevels via 4D_Tech <[hidden email]<mailto:[hidden email]>> wrote:
I have a client that has asked me to add the option to send text messages to cell phones from 4D. I know this is possible via some websites or web services for a fee. Has anyone done this and can recommend a web service that you were able to use from 4D to do this?
Tim
*****************************************
Tim Nevels
Innovative Solutions
785-749-3444
[hidden email]<mailto:[hidden email]>
*****************************************



**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
In reply to this post by 4D Tech mailing list
On Aug 22, 2018, at 2:00 PM, Jim Hassler wrote:

> We had a need to send texts to company employees so we have the luxury of knowing the cell phone provider.  So, we use something like this…
>
> Case of
>
>    : ([User]Company Cell Phone Provider="AT&T")
>
>       aEmailAddress{1}:=$cellPhoneNum+"@txt.att.net"
>
>       emSEND EMAIL ("Linbeck Lean Video";<>CR+[Video]Web Address;$fromAddress;"aEmailAddress";"";"";"")
>
>
>    : ([User]Company Cell Phone Provider="Verizon")
>
>       aEmailAddress{1}:=$cellPhoneNum+"@vtext.com"
>
>       emSEND EMAIL ("Linbeck Lean Video";<>CR+[Video]Web Address;$fromAddress;"aEmailAddress";"";"";"")

Thanks for the info. Several people have responded that most providers have a free email service that allows sending a text. I’d love to be able to do this, but for this client it’s just not possible to always get the person’s cell phone provider. So we will have to use a pay service.

Of all the SMS web services out there twilio.com seems to be the most popular with 4D developers. I have a few say they can provide me with some code to do the http work with Twilio’s API. So I’ll probably go that route.

It was a bit unclear to me exactly what the cost is with Twilio. Their website lists many services available for sending and receiving SMS and even MMS. From what I could gather it costs about $1.00 a month for the pay-as-you-go option, and 1 cent for each SMS sent.

It is not exactly 1 cent for every SMS because you pay Twilio $0.0075 for each SMS and they you pay another fee to the carrier of the person’s cell phone. AT&T is $0.0025 per SMS and Sprint is $0.005 per SMS. In any event the cost seems incredibly low.

If someone knows the exact pricing scheme for Twilio, I’d love to hear it. I’m not sure I completely understand it.

One other question is do you need a cell phone account to send SMS with Twilio? If so, I guess the company could get a cell phone for the business and just never use it. It would be just so you could send SMS via 4D.

Tim

*****************************************
Tim Nevels
Innovative Solutions
785-749-3444
[hidden email]
*****************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

RE: Sending Text Messages From 4D

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Tim,

I’ve integrated https://www.data24-7.com/index.php#pricing into one 4D system.

It’s fairly cheap ($12/mo + $0.005 per lookup), and the lookups are stored locally, so they are one-time.

David Ringsmuth

From: Tim Nevels via 4D_Tech
Sent: Wednesday, August 22, 2018 9:04 AM
To: [hidden email]
Cc: Tim Nevels
Subject: Sending Text Messages From 4D

I have a client that has asked me to add the option to send text messages to cell phones from 4D. I know this is possible via some websites or web services for a fee. Has anyone done this and can recommend a web service that you were able to use from 4D to do this?

Tim

*****************************************
Tim Nevels
Innovative Solutions
785-749-3444
[hidden email]
*****************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
In reply to this post by 4D Tech mailing list
I used clickatell for a 4D summit presentation a few years back.  It
allowed two way communication.

Regards,

Wayne



On Thu, 23 Aug 2018 at 00:04, Tim Nevels via 4D_Tech
<[hidden email]> wrote:

>
> I have a client that has asked me to add the option to send text messages to cell phones from 4D. I know this is possible via some websites or web services for a fee. Has anyone done this and can recommend a web service that you were able to use from 4D to do this?
>
> Tim
>
> *****************************************
> Tim Nevels
> Innovative Solutions
> 785-749-3444
> [hidden email]
> *****************************************
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Hi Tim (or anyone else that could help),

I am looking for a quick and simple SMS solution and came upon your (Tim's)
message that you possibly had gotten some HTTP code snippets to send SMS via
4D using Twilio.

I tried and was unsuccessful probably because of syntax so I gave up and
moved on. I am trying Clickatell soon.

If you have a working example for Twilio I would much appreciate looking at
it.

Thanks in advance.

Cheers

Jim - infobase

_____________________________________
Sent from http://4d.1045681.n5.nabble.com





-----
Jim Labos - infobase
--
Sent from: http://4d.1045681.n5.nabble.com/4D-Tech-f1376241.html
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
Here's what I wrote for our app ($tUserName would be unique to you, along with $tPassword and $tFromNumber). The method HTTP_Request_Build is just building a text variable like:

    "From=15555555555&To=15555555556&Body=This%20is%20the%20text"

String_FixURL is just a URL-encode method that Miyako posted awhile back (included at the end of this message).

Also note that we're hard-coding the country code at '1' for US numbers only.

  // Twilio_Send
  //
  // $1 - TEXT - SendTo phone number
  // $2 - TEXT - Message to send

C_TEXT($1;$tSendToNumber)
C_TEXT($2;$tMessage)
$tSendToNumber:=$1
$tMessage:=$2

C_TEXT($tURI;$tUserName;$tPassword;$tPlugin;$tInfo;$tFromNumber;$tRequest;$tResponse)
C_LONGINT($lJson;$lHTTPStatus;$lTimeout;$lPort)

  // Stuff unique to your Twilio account
$tUserName:="Your Twilio username"
$tPassword:="Your Twilio password"
$tFromNumber:="Your Twilio mobile account number"

$tURI:="https://api.twilio.com/2010-04-01/Accounts/"+\
  $tUserName+"/Messages.json"
$tFromNumber:="+1"+$tFromNumber
$tSendToNumber:="+1"+$tSendToNumber
               
$tRequest:=""
HTTP_Request_Build (->$tRequest;"From";String_FixURL ($tFromNumber);"*")
HTTP_Request_Build (->$tRequest;"To";String_FixURL ($tSendToNumber);"*")
HTTP_Request_Build (->$tRequest;"Body";String_FixURL ($tMessage))
               
ARRAY TEXT($atHeaderNames;0)
ARRAY TEXT($atHeaderValues;0)
APPEND TO ARRAY($atHeaderNames;"content-type")
APPEND TO ARRAY($atHeaderValues;"application/x-www-form-urlencoded")
HTTP AUTHENTICATE ($tUserName;$tPassword;HTTP basic)
$lTimeout:=10
$lHTTPStatus:=HTTP Request (HTTP POST method;$tURI;$tRequest;tResponse;$lTimeout;$atHeaderNames;$atHeaderValues)


  // String_FixURL
  //
  // Returns urlencoded string in $0 from the string passed in $1

C_TEXT($0)
C_TEXT($1)
       
C_TEXT($escaped)
C_LONGINT($i)
C_BOOLEAN($shouldEscape)
C_BLOB($data)
       
For ($i;1;Length($1))
               
  $char:=Substring($1;$i;1)
  $code:=Character code($char)
               
  $shouldEscape:=False
               
  Case of
    : ($code=45)
    : ($code=46)
    : ($code>47) & ($code<58)
    : ($code>63) & ($code<91)
    : ($code=95)
    : ($code>96) & ($code<123)
    : ($code=126)
  Else
    $shouldEscape:=True
  End case
               
  If ($shouldEscape)
    CONVERT FROM TEXT($char;"utf-8";$data)
    For ($j;0;BLOB size($data)-1)
      $hex:=String($data{$j};"&x")
      $escaped:=$escaped+"%"+Substring($hex;Length($hex)-1)
    End for
  Else
    $escaped:=$escaped+$char
  End if
               
End for
       
$0:=$escaped

> On Aug 5, 2019, at 1:00 PM, Jim Labos - infobase via 4D_Tech <[hidden email]> wrote:
>
> I tried and was unsuccessful probably because of syntax so I gave up and
> moved on. I am trying Clickatell soon.
>
> If you have a working example for Twilio I would much appreciate looking at
> it.

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
Thanks for the code example, much appreciated. I keep getting a 400 HTTP
error however.

I am not using "HTTP_Request_Build" as I don't have it but I assume the "*"
is an option to omit or include some characters for formatting.

Here is what I am using from your code less proper username (assume it is
the Account SID), password (assume it is the Authorization token) and phone
numbers. Note I left out some parameters in the "HTTP Request" method as I
am using v13.6 on this version and there is no timeout parameter.

It may be that the "tRequest" var is not being formatted properly?

I'll be trying in v15 next to see if I get better results.


  // Twilio_Send
  //
  // $1 - TEXT - SendTo phone number
  // $2 - TEXT - Message to send

C_TEXT($1;$tSendToNumber)
C_TEXT($2;$tMessage)
$tSendToNumber:="5145551212"  //$1
$tMessage:="Test SMS"  //$2

C_TEXT($tURI;$tUserName;$tPassword;$tPlugin;$tInfo;$tFromNumber;$tRequest;$tResponse;tResponse)
C_LONGINT($lJson;$lHTTPStatus;$lTimeout;$lPort)

  // Stuff unique to your Twilio account
$tUserName:="Account SID"
$tPassword:="AUTH Token"  //"Your Twilio password"
$tFromNumber:="5552221212"  //"Your Twilio mobile account number"

$tURI:="https://api.twilio.com/2010-04-01/Accounts/"+$tUserName+"/Messages.json"
$tFromNumber:="+1"+$tFromNumber
$tSendToNumber:="+1"+$tSendToNumber

$tRequest:=""

$tRequest:="FROM="+$tFromNumber  //String_FixURL ($tFromNumber)
$tRequest:=$tRequest+"&To="+$tSendToNumber  //String_FixURL ($tSendToNumber)
$tRequest:=$tRequest+"&Body="+String_FixURL ($tMessage)


ARRAY TEXT($atHeaderNames;0)
ARRAY TEXT($atHeaderValues;0)
APPEND TO ARRAY($atHeaderNames;"content-type")
APPEND TO ARRAY($atHeaderValues;"application/x-www-form-urlencoded")
HTTP AUTHENTICATE($tUserName;$tPassword;HTTP Basic)
$lTimeout:=10
$lHTTPStatus:=HTTP Request(HTTP POST Method;$tURI;$tRequest;tResponse)




-----
Jim Labos - infobase
--
Sent from: http://4d.1045681.n5.nabble.com/4D-Tech-f1376241.html
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
Hi Jim,

You're not sending the headers. You must add the arrays in HTTP Request. That might lead into an 400 'bad request' error.

$lHTTPStatus:=HTTP Request(HTTP POST Method;$tURI;$tRequest;tResponse; atHeaderNames; atHeaderValues)

HTH
Koen

> Op 5 aug. 2019, om 21:17 heeft Jim Labos - infobase via 4D_Tech <[hidden email]> het volgende geschreven:
>
> $lHTTPStatus:=HTTP Request(HTTP POST Method;$tURI;$tRequest;tResponse)



—————————————————
                Koen Van Hooreweghe
—————————————————




**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
In reply to this post by 4D Tech mailing list
On Aug 5, 2019, at 2:00 PM, Jim Labos wrote:

> Hi Tim (or anyone else that could help),
>
> I am looking for a quick and simple SMS solution and came upon your (Tim's)
> message that you possibly had gotten some HTTP code snippets to send SMS via
> 4D using Twilio.
>
> I tried and was unsuccessful probably because of syntax so I gave up and
> moved on. I am trying Clickatell soon.
>
> If you have a working example for Twilio I would much appreciate looking at
> it.
>
> Thanks in advance.

Hi Jim,

I got some code from Justin Leavens that David Adams had created using NTK long before we had 4D’s HTTP Request command. I modified and adapted it to use HTTP Request since my project did not use NTK.

There are 2 utility methods. StripBadCharacters makes sure the message text has not “bad” characters. Twilio_ConvertDateToDTS converts the human readable date time to a normally formatted DTS.

  // ===========================================
  // PROJECT METHOD: Twilio_SendSMS

  // PARAMETERS: $0 = object with results
  // $1 = to phone number
  // $2 = message text

  // DESCRIPTION: Send an SMS via the Twilio service.

  // https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxx1ee6776/SMS/Messages.json

  // CREATED BY: David Adams (provided to me by Justin Leavens)
  // DATE: Unknown
  // LAST MODIFIED: 8/31/18 changed it from using NTK to 4D HTTP Request
  // made it conform to my programming style
  // ============================================

C_OBJECT($0;$result_o)
C_TEXT($1;$toPhoneNumber_t)
C_TEXT($2;$message_t)
$toPhoneNumber_t:=$1
$message_t:=$2

  // declare local variables
C_TEXT($errorMessage_t;$fromPhoneNumber_t;$toPhoneNumber_t;$message_t;$toPhoneDialingCode_t)
C_TEXT($twilioAccountSID_t;$twilioAuthToken_t;$requestURL_t;$content_t;$fromPhoneNumber_t)
C_LONGINT($statusCode_l)
C_OBJECT($response_o)
ARRAY TEXT($headerName_at;0)
ARRAY TEXT($headerValue_at;0)

  // remove any bad characters from the message
StripBadCharacters (->$message_t)  // Control characters can mess up Twilio as it likes things XML safe.

  // Encode & characters (all the other special URL characters seem to be OK with Twilio)
$message_t:=Replace string($message_t;"&";"%26")

  // use basic authentication
$fromPhoneNumber_t:=<>twilioPhoneNumber_t
$twilioAccountSID_t:=<>twilioAccountSID_t
$twilioAuthToken_t:=<>twilioAuthToken_t
HTTP AUTHENTICATE($twilioAccountSID_t;$twilioAuthToken_t;HTTP basic)

  // strip any phone number formatting
$toPhoneNumber_t:=Replace string($toPhoneNumber_t;"(";"")  // strip "("
$toPhoneNumber_t:=Replace string($toPhoneNumber_t;")";"")  // strip ")"
$toPhoneNumber_t:=Replace string($toPhoneNumber_t;"-";"")  // strip "-"
$toPhoneNumber_t:=Replace string($toPhoneNumber_t;" ";"")  // no spaces

  // build URL
$requestURL_t:="https://api.twilio.com/2010-04-01/Accounts/"+$twilioAccountSID_t+"/SMS/Messages.json"

  // build headers (content won't parse correctly on the Twilio side without this)
APPEND TO ARRAY($headerName_at;"Content-Type")
APPEND TO ARRAY($headerValue_at;"application/x-www-form-urlencoded")

  // build content
$content_t:="From="+$fromPhoneNumber_t+"&"
$content_t:=$content_t+"To="+$toPhoneNumber_t+"&"
$content_t:=$content_t+"Body="+$message_t

  // send the message
$statusCode_l:=HTTP Request(HTTP post method;$requestURL_t;$content_t;$response_o;$headerName_at;$headerValue_at)

  // seup response object
Case of
   : ($statusCode_l=201)  // successful sent SMS
      OB SET($result_o;"error";False)
      OB SET($result_o;"sid";OB Get($response_o;"sid"))
        // can't use "date_sent" because it could be queued
      OB SET($result_o;"sentDTS";Twilio_ConvertDateToDTS (OB Get($response_o;"date_created")))

   Else   // problem
      $errorMessage_t:="ERROR in sending SMS Message"+<>CR+<>CR+\
         "Status = "+String($statusCode_l)+<>CR+<>CR+\
         JSON Stringify($response_o;*)
      OB SET($result_o;"error";True)
      OB SET($result_o;"errorMessage";$errorMessage_t)
End case

  // return any error message
$0:=$result_o


  // ===========================================
  // PROJECT METHOD: StripBadCharacters

  // PARAMETERS: $1 = pointer to text
  // $2 = flag to allow carriage returns (optional)

  // DESCRIPTION: Checks a text variable or alpha field or text field
  // for any characters that are "invisible" an removes them. These
  // are generally low ASCII value characters like Char(0) and Char(1).

  // This should eliminate the problem of doing a copy/paste from an
  // email or from a Word document that later causes problems when
  // trying to do an Outlook email.

  // Line Feed and Tab characters are stripped in all cases.

  // It strips Carriage Returns unless you want to allow them, like for
  // text fields.

  // CREATED BY: Tim Nevels, Innovative Solutions ©2018
  // DATE: 2/22/18
  // LAST MODIFIED:
  // ============================================

C_POINTER($1;$theText_p)
C_TEXT($2)
$theText_p:=$1
If (Count parameters>=2)
   $allowCR_b:=True
End if

C_BOOLEAN($allowCR_b)
C_TEXT($theText_t;$newText_t)
C_LONGINT($i;$characterCode;$theTextLength_l)

  // copy text to local variable
$theText_t:=$theText_p->
$theTextLength_l:=Length($theText_t)

  // check each character for problems
For ($i;1;$theTextLength_l)
   $characterCode:=Character code($theText_t[[$i]])
   Case of
      : (($characterCode=Carriage return) & $allowCR_b)  // 13 Carriage Return, allow
         $newText_t:=$newText_t+$theText_t[[$i]]
      : ($characterCode=DEL ASCII code)  // 127 DEL is invalid, delete
      : ($characterCode<Space)  // below 32, invalid low value
      Else   // OK value, allow
         $newText_t:=$newText_t+$theText_t[[$i]]
   End case
End for

  // update the field if it changed
If ($theTextLength_l#Length($newText_t))  // something was stripped
     // return the updated value
   $theText_p->:=$newText_t
End if


  // ===========================================
  // PROJECT METHOD: Twilio_ConvertDateToDTS

  // PARAMETERS: $0 = DTS
  // $1 = Twilio Date

  // DESCRIPTION: Converts a date from Twilio to a normal DTS at GMT.
  // All Twilio are dates are in GMT, so we can ignore the "+0000" offset

  // Example: Sat, 06 Oct 2018 23:20:04 +0000

  // CREATED BY: Tim Nevels, Innovative Solutions ©2018
  // DATE: 10/12/18
  // LAST MODIFIED:
  // ============================================

C_TEXT($0)
C_TEXT($1;$twilioDate_t)
$twilioDate_t:=$1

  // declare local variables
C_TEXT($day_t;$monthName_t;$year_t;$time_t;$month_t)

  // get date and time parts
$day_t:=Substring($twilioDate_t;6;2)
$monthName_t:=Substring($twilioDate_t;9;3)
$year_t:=Substring($twilioDate_t;13;4)
$time_t:=Substring($twilioDate_t;18;8)

  // convert month name to month number
Case of
   : ($monthName_t="Jan")
      $month_t:="01"
   : ($monthName_t="Feb")
      $month_t:="02"
   : ($monthName_t="Mar")
      $month_t:="03"
   : ($monthName_t="Apr")
      $month_t:="04"
   : ($monthName_t="May")
      $month_t:="05"
   : ($monthName_t="Jun")
      $month_t:="06"
   : ($monthName_t="Jul")
      $month_t:="07"
   : ($monthName_t="Aug")
      $month_t:="08"
   : ($monthName_t="Sep")
      $month_t:="09"
   : ($monthName_t="Oct")
      $month_t:="10"
   : ($monthName_t="Nov")
      $month_t:="11"
   : ($monthName_t="Dec")
      $month_t:="12"
End case

  // returne DTS
$0:=$year_t+"-"+$month_t+"-"+$day_t+"T"+$time_t+"Z"


Tim

*****************************************
Tim Nevels
Innovative Solutions
785-749-3444
[hidden email]
*****************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Thanks Koen, but with the headers I get a 404. Not sure but I believe the
headers are optional. My guess is that the "$tRequest" var is not formatted
correctly.

I'm going to ask Twilio if they can help here.

Cheers

Jim Labos - infobase



-----
Jim Labos - infobase
--
Sent from: http://4d.1045681.n5.nabble.com/4D-Tech-f1376241.html
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
Jim,

Have you tried using the PostMan application (https://www.getpostman.com/postman <https://www.getpostman.com/postman>) to work out the proper form of sending these requests?

I found it helped a lot in trying to figure out how to build the request to a couple REST APIs a last year.

It lets you build up the command string and see what you’re sending and what you’re getting back. From there it’s then easy to translate into the appropriate commands and variables to build the HTTP Request call you need in 4D.

It may or may not help in this case, but it did make it faster and easier to see things when I was working on this stuff.

HTH,
Randy

----------------------------------------------------------------------
Randy Jaynes
Senior Programmer and Customer Support

http://printpoint.com • 845.687.3741 • PrintPoint, Inc • 57 Ludlow Lane • Palisades, NY 10964
Please send all email contacts to [hidden email]



> On Aug 5, 2019, at 3:42 PM, Jim Labos - infobase via 4D_Tech <[hidden email]> wrote:
>
> Thanks Koen, but with the headers I get a 404. Not sure but I believe the
> headers are optional. My guess is that the "$tRequest" var is not formatted
> correctly.
>
> I'm going to ask Twilio if they can help here.
>
> Cheers
>
> Jim Labos - infobase
>
>
>
> -----
> Jim Labos - infobase
> --
> Sent from: http://4d.1045681.n5.nabble.com/4D-Tech-f1376241.html
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Are you URLEncoding the body of the text message?

Also, We have the country code with every phone number including the sending phone number (1 for US).  Did you try that?

> On Aug 5, 2019, at 2:06 PM, Jeffrey Kain <[hidden email]> wrote:
>
> Here's what I wrote for our app ($tUserName would be unique to you, along with $tPassword and $tFromNumber). The method HTTP_Request_Build is just building a text variable like:
>
>    "From=15555555555&To=15555555556&Body=This%20is%20the%20text"
>
> String_FixURL is just a URL-encode method that Miyako posted awhile back (included at the end of this message).
>
> Also note that we're hard-coding the country code at '1' for US numbers only.
>
>  // Twilio_Send
>  //
>  // $1 - TEXT - SendTo phone number
>  // $2 - TEXT - Message to send
>
> C_TEXT($1;$tSendToNumber)
> C_TEXT($2;$tMessage)
> $tSendToNumber:=$1
> $tMessage:=$2
>
> C_TEXT($tURI;$tUserName;$tPassword;$tPlugin;$tInfo;$tFromNumber;$tRequest;$tResponse)
> C_LONGINT($lJson;$lHTTPStatus;$lTimeout;$lPort)
>
>  // Stuff unique to your Twilio account
> $tUserName:="Your Twilio username"
> $tPassword:="Your Twilio password"
> $tFromNumber:="Your Twilio mobile account number"
>
> $tURI:="https://api.twilio.com/2010-04-01/Accounts/"+\
>  $tUserName+"/Messages.json"
> $tFromNumber:="+1"+$tFromNumber
> $tSendToNumber:="+1"+$tSendToNumber
>
> $tRequest:=""
> HTTP_Request_Build (->$tRequest;"From";String_FixURL ($tFromNumber);"*")
> HTTP_Request_Build (->$tRequest;"To";String_FixURL ($tSendToNumber);"*")
> HTTP_Request_Build (->$tRequest;"Body";String_FixURL ($tMessage))
>
> ARRAY TEXT($atHeaderNames;0)
> ARRAY TEXT($atHeaderValues;0)
> APPEND TO ARRAY($atHeaderNames;"content-type")
> APPEND TO ARRAY($atHeaderValues;"application/x-www-form-urlencoded")
> HTTP AUTHENTICATE ($tUserName;$tPassword;HTTP basic)
> $lTimeout:=10
> $lHTTPStatus:=HTTP Request (HTTP POST method;$tURI;$tRequest;tResponse;$lTimeout;$atHeaderNames;$atHeaderValues)
>
>
>  // String_FixURL
>  //
>  // Returns urlencoded string in $0 from the string passed in $1
>
> C_TEXT($0)
> C_TEXT($1)
>
> C_TEXT($escaped)
> C_LONGINT($i)
> C_BOOLEAN($shouldEscape)
> C_BLOB($data)
>
> For ($i;1;Length($1))
>
>  $char:=Substring($1;$i;1)
>  $code:=Character code($char)
>
>  $shouldEscape:=False
>
>  Case of
>    : ($code=45)
>    : ($code=46)
>    : ($code>47) & ($code<58)
>    : ($code>63) & ($code<91)
>    : ($code=95)
>    : ($code>96) & ($code<123)
>    : ($code=126)
>  Else
>    $shouldEscape:=True
>  End case
>
>  If ($shouldEscape)
>    CONVERT FROM TEXT($char;"utf-8";$data)
>    For ($j;0;BLOB size($data)-1)
>      $hex:=String($data{$j};"&x")
>      $escaped:=$escaped+"%"+Substring($hex;Length($hex)-1)
>    End for
>  Else
>    $escaped:=$escaped+$char
>  End if
>
> End for
>
> $0:=$escaped
>
>> On Aug 5, 2019, at 1:00 PM, Jim Labos - infobase via 4D_Tech <[hidden email]> wrote:
>>
>> I tried and was unsuccessful probably because of syntax so I gave up and
>> moved on. I am trying Clickatell soon.
>>
>> If you have a working example for Twilio I would much appreciate looking at
>> it.
>

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Here are what the HTTP_REQUEST parameters look like.

$lHTTPStatus:=HTTP Request(HTTP POST Method;$tURI;$tRequest;tResponse)

$tURI="https://api.twilio.com/2010-04-01/Accounts/account SID goes
here/Messages.json"

$tRequest="FROM=%2B15551234537&To=%2B15551212&Body=Test%20SMS"

tResponse= "{"code": 21602, "message": "Message body is required.",
"more_info": "https://www.twilio.com/docs/errors/21602", "status": 400}"

So it looks like loging in goes well but the formatting of "$tRequest"
doesn't jive with Trilio.

Anyone see what it could be? I'm new to direct HTTP requests like this.

Thanks

Jim



-----
Jim Labos - infobase
--
Sent from: http://4d.1045681.n5.nabble.com/4D-Tech-f1376241.html
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Sending Text Messages From 4D

4D Tech mailing list
Hi Randy,

I just tried PostMan! Fantastic tool! A million thanks for suggesting that.

However I am still getting the same 400 error. It's great to be able to see
the complete request sent to Twilio.

The formatting looks good. This is teh problem I was having on my own and
that is why I asked for help.

I'll put in a request for some support from Twilio to see what's going on.

Jim



-----
Jim Labos - infobase
--
Sent from: http://4d.1045681.n5.nabble.com/4D-Tech-f1376241.html
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
12