Getting up on Twilio

Doug Easterbrook doug at artsman.com
Tue Mar 7 15:32:59 UTC 2023


hi Das:

the OW# http worker is a wrapper around curl.   so if you see that you can do something in CURL, you can likely use the OW3 http worker to get it done


this is a FOR EXAMPLE where I use the HTTP oW2 worker to check for the website supporting and forcing use of TLS 1.2. There are a couple of lines there that define the CURLOPTIONS.       Those, I had to look up and the URL in the comment gives where I found them (in curl’s github)


other than that, you have a HEADERLIST that is defined as HeaderName and HeaderValue).   I didn't need any in my CURL request, but you have certain mime types that you need, add them there

your user id and password are likely NOT curlOptions and NOT part of the headerlist.  In my http worker, I see that there is an auth type, userid and password that has been abstracted out for you.

Do $cinst.$init(iURI,iCurlAction,iHeaderList,kOW3httpMultiPartFormData,iAuthType,iUser,iPassword) Returns lFlag

my advice.. go and check the oW2 worker sample test library and make it work with that.  then you can copy out what you need and make your own worker






————— Detecting if a web site supports only TLS1.2 — working code VERY USEFUL FOR PCI and CREDIT CARD TESTING of merchants ----------------------

Do $objects.oHTTPWorker.$newref($cinst().$ref) Returns HttpWorker
Calculate HttpWorker.$followredirects as kTrue

# # Add "cURL Options" which allows custom options to be set from cURL "easy" constants
# # Ref: https://github.com/curl/curl/blob/master/include/curl/curl.h#L963
Do CurlOptions.$define(CurlOption,CurlValue)
Do CurlOptions.$add(32,"6") ## CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2
Calculate HttpWorker.$curloptions as CurlOptions

Do HeaderList.$define(HeaderName,HeaderValue)

Calculate Content as ''

# ask for the http header to see if we get a response.  if not, we couldn't communicate with TLS 1.2 or later
Do HttpWorker.$init(pURL,kOW3httpMethodHead,HeaderList,Content)
Do HttpWorker.$run() Returns OK
If not(OK)|HttpWorker.$isCanceled
# TODO: Check HttpWorker.$errortext or HttpWorker.$errrocode
Quit method kFalse
End If

Calculate TLSFailCode as 35
Calculate TLSFailMessage as 'Could not negotiate an SSL cipher suite'
Calculate Response as HttpWorker.$response

Calculate pErrorCode as Response.errorCode
Calculate pErrorMessage as Response.errorInfo

# Determine if this is a failure for TLS reasons.  It's confusing, but a non-failure is a success for TLS, even if it's𯿾non-200 errors.
Calculate TLSFail as Response.errorCode=TLSFailCode&pos(low(TLSFailMessage),low(pErrorMessage))>0
Quit method not(TLSFail)





Doug Easterbrook
Arts Management Systems Ltd.
mailto:doug at artsman.com
http://www.artsman.com
Phone (403) 650-1978

> On Mar 6, 2023, at 8:38 AM, Das Goravani <goravanis at gmail.com> wrote:
> 
> 
> As an aside, you can use CURL to talk to Twilio. Here is an example of CURL that addresses the Twilio API.
> 
> How can I adapt this to work with Omnis?
> 
> curl -X POST https://api.twilio.com/2010-04-01/Accounts/{{ACCOUNT_SID}}/Messages.json \
> --data-urlencode "From=+<TWILIO_PHONE_NUMBER>" \
> --data-urlencode "Body=body" \
> --data-urlencode "To=+<YOUR PHONE_NUMBER>" \
> -u your_account_sid:your_auth_token
> 
> I just don’t know what to type into the HTTP Post command. I see the above, and wonder if it’s literal.. could I just type the above into the Post command?
> 
> There is only your account SID, a string, and auth_token, another string they give you. I have mine from them.
> 
> Then there is To, From and Body.. of the text message. 
> 
> Developer Support is trying to help me. They looked it up and they feel the HTTP Post command would work. They further think it could be done with Node.js.  I am not familiar with either. I see the Post command, just don’t know what to type into it so that it works. I’m wondering if the above gives it away. Perhaps someone more experienced could tell me how to adapt it to Omnis. 
> 
> I asked for the formatting of the HTTP Post statement, and they gave me a link to how to do it in Postman. It gives this CURL example as what it is going to replace.
> 
> I have heard you can do CURL with Omnis, is that right? 
> 
> Das
> 
>> On Mar 6, 2023, at 2:43 AM, Paul Mulroney <pmulroney at logicaldevelopments.com.au> wrote:
>> 
>> Hi Das,
>> 
>> You used to be able to do x-www-form-urlencoded in Omnis by creating a list with two columns: key and value.  If you were using the HTTPSend commands, this was one of the parameters you could pass in.  Not sure how that translates into the worker object.
>> 
>> I'll see if I can find an example.
>> 
>> Regards,
>> Paul.
>> 
>> 
>>> On 6 Mar 2023, at 5:01 am, Das Goravani <goravanis at gmail.com> wrote:
>>> 
>>> 
>>> Everyone,
>>> 
>>> I am trying to get onto Twilio to send text messages.
>>> 
>>> I was going to use the HTTP Client Worker object.  
>>> 
>>> But it always binary encodes the contents field. Usually it’s in JSON too.
>>> 
>>> I told this to Twilio tech support and asked if it’s OK. 
>>> 
>>> They said NO. Here is their response:
>>> 
>>>> Short answer is no. The body and format of the requests must be exactly in the format that the documentation specify. Using binary bodies in JSON format will result in an exception.
>>>> 
>>>> Usually, most of our services accept x-www-form-urlencoded format.
>>> 
>>> 
>>> What does that last line mean practically.. what do you do to be URLencoded like that?
>>> 
>>> Can I use the worker object?  If it always makes the contents field binary it seems I cannot use it with Twilio.
>>> 
>>> Some of you are on Twilio.. how do you do it?
>>> 
>>> Anticipating:
>>> 
>>> Das Goravani
>>> 
>>> 
>>> _____________________________________________________________
>>> Manage your list subscriptions at https://lists.omnis-dev.com
>>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 
>> 
>> 
>> My friend asked me to help him round up his 37 sheep. I said “40”
>> -- 
>> Paul W. Mulroney                                            We Don't Do Simple Pty Ltd 
>> pmulroney at logicaldevelopments.com.au       Trading as Logical Developments
>> www.logicaldevelopments.com.au                   ACN 161 009 374 
>> Ph: +61 8 9458 3889                                       86 Coolgardie Street
>>                                                                        BENTLEY  WA  6102
>> 
>> 
>> 
>> _____________________________________________________________
>> Manage your list subscriptions at https://lists.omnis-dev.com
>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 



More information about the omnisdev-en mailing list