NetTalk Central

Author Topic: Here is the code to send SMS messages using TELNYX's SMS platform  (Read 2659 times)

hectorp

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Hi All,

I did a test application for sending SMS using the TELNYX platform. Share it in case is of use for someone.

TELNYX CURL API;

curl -X POST \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer YOUR_API_KEY" \
  --data '{
    "from": "+13115552368",
    "to": "+13115552367",
    "text": "Hello, world!"
  }' \
  https://api.telnyx.com/v2/messages



I created a window process and place a post button. The following is the code in the post button;

net.SetAllHeadersDefault()
do options
net.SetValue('Testdata', '{{ "from": "+18660000000", "to": "+10000000000", "text": "Hello, world!" }',net:NoUrlEncode,'','')
Testdata.SetValue('{{ "from": "+18660000000", "to": "+10000000000", "text": "TELNYX TEST " }' )
net.Authorization = 'Bearer KEY01...'
Net.Post('https://api.telnyx.com/v2/messages',Testdata.GetValue())

This is the code in the options routine;

 Net.HTTPVersion ='HTTP/1.0'
 net.ContentType ='application/json'
 Net.Accept_ ='image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*'
 Net.CanUseProxy =0
 Net.ProxyServer =''
 Net.ProxyPort =0
 Net.OptionsDontUseSSLOverHTTPProxy =0
 Net.ProxyAuthorization =''
 Net.Pragma_ =''
 Net.CacheControl =''
 Net.Cookie =''
 Net.CustomHeader =''
 Net.AsyncOpenTimeOut =1200
 Net.InActiveTimeout =9000
 Net.HeaderOnly =0
 Net.Referer =''
 Net.OptionDontRedirect =0
 Net.OptionAutoCookie =0
 Net.OptionDontSetCookieOnRedirect =0
 Net.Authorization ='Bearer KEY01...'
 Net.SSLCertificateOptions.CertificateFile =''
 Net.SSLCertificateOptions.PrivateKeyFile =''
 Net.SSLCertificateOptions.DontVerifyRemoteCertificateCommonName =1
 Net.SSLCertificateOptions.DontVerifyRemoteCertificateWithCARoot =1
 Net.SSLCertificateOptions.CARootFile =''
 Net.SSLCertificateOptions.ServerName =''
 Net.SSLCertificateOptions.CiphersAllowed =''
 Net.SSLMethod ='-5'

Probably there must be an option to set to include spanish characters as I placed various (?,?) and the messages wasn't delivered.

I hope this code help others interested in using the TELNYX SMS platform.

Cheers.
« Last Edit: January 23, 2024, 09:43:22 AM by hectorp »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Here is the code to send SMS messages using TELNYX's SMS platform
« Reply #1 on: January 23, 2024, 10:38:27 PM »
Hi Hector, this code is "wrong" in a number of ways.
Firstly the options; all you should have is

 net.ContentType ='application/json'
 Net.Authorization ='Bearer KEY01...'

Secondly, the call;

net.SetAllHeadersDefault()
do options
net.SetValue('Testdata', '{{ "from": "+18660000000", "to": "+10000000000", "text": "Hello, world!" }',net:NoUrlEncode,'','')
Net.Post('https://api.telnyx.com/v2/messages')

since there are only 2 options to set, this can be reduced to

net.SetAllHeadersDefault()
 net.ContentType ='application/json'
 Net.Authorization ='Bearer KEY01...'
net.SetValue('Testdata', '{{ "from": "+18660000000", "to": "+10000000000", "text": "Hello, world!" }',net:NoUrlEncode,'','')
Net.Post('https://api.telnyx.com/v2/messages')


the code generated by capesoft.com/curlcode from your curl example suggests;

  net.Start()
  net.SetValue('', '{{    "from": "+13115552368",    "to": "+13115552367",    "text": "Hello, world!"  }',net:NoUrlEncode,'','')
  net.ContentType = 'application/json'
  net.Authorization = 'Bearer YOUR_API_KEY'
  net.Post('https://api.telnyx.com/v2/messages')

which is pretty much the same thing. You added "testdata" to the SetValue,. and I don't think that's required - you should test it both ways.

Cheers
Bruce

hectorp

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Here is the code to send SMS messages using TELNYX's SMS platform
« Reply #2 on: January 24, 2024, 07:10:36 AM »
Hi Bruce,

I attached an APP with the code that is working for me, as well as an image from my mobile phone with the test messages I sent.

The bearer key is not included for security reasons.