Logic Machine Forum
Help me! Notification SMS from LM using Twilio service - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Help me! Notification SMS from LM using Twilio service (/showthread.php?tid=239)



Help me! Notification SMS from LM using Twilio service - phongvucba - 02.03.2016

in the code:
  1. value = event.getvalue()

  2.  

  3. from_nr = '+37112345679' -- put sender SIM nr here

  4. to_nr = '+37112345678' -- put recepient SIM nr here

  5. id_nr = 'ACe56f5' -- put your ID here

  6. token_nr = '598c6ff' -- put your token here

  7.  

  8. sms(id_nr, token_nr, from_nr, to_nr, 'The value for 1/1/2 has changed to'..tostring(value))
id_nr and token_nr, Where I see my account?
thank everyone. !  Heart Heart Heart


RE: Help me! Notification SMS from LM using Twilio service - admin - 02.03.2016

Have a look here:
https://www.twilio.com/help/faq/twilio-basics/what-is-the-auth-token-and-how-can-i-change-it

id_nr is your Account SID and token_nr is your Auth Token


RE: Help me! Notification SMS from LM using Twilio service - phongvucba - 04.03.2016

(02.03.2016, 12:29)admin Wrote: Have a look here:
https://www.twilio.com/help/faq/twilio-basics/what-is-the-auth-token-and-how-can-i-change-it

id_nr is your Account SID and token_nr is your Auth Token

thank admin so much!
"from_nr" and "to_nr" , what it?
thank all!  Confused Confused


RE: Help me! Notification SMS from LM using Twilio service - admin - 07.03.2016

from_nr is Twilio number that is sending the message, in your Twilio account click "Get your first Twilio Number"

to_nr is the phone number that should receive the message


RE: Help me! Notification SMS from LM using Twilio service - cuong.nguyen@vis.solutions - 11.10.2019

Hi,
I try to sent SMS by Twilio in VietNam as link:
https://openrb.com/notification-sms-from-lm-using-twilio-service/#codesyntax_2

But, it's not working. I used this code for event:

from_nr = '+19177461563' -- Twilio phone number
to_nr = '+84932414151' -- My phone number
id_nr = '...' -- ACCOUNT SID
token_nr = '...' -- AUTH TOKEN

sms(id_nr, token_nr, to_nr, from_nr, 'Test SMS by SL'..tostring(value))


RE: Help me! Notification SMS from LM using Twilio service - admin - 11.10.2019

You have swapped from/to fields. It should be:
Code:
sms(id_nr, token_nr, from_nr, to_nr, 'Test SMS by SL'..tostring(value))



RE: Help me! Notification SMS from LM using Twilio service - cuong.nguyen@vis.solutions - 15.10.2019

(11.10.2019, 06:52)admin Wrote: You have swapped from/to fields. It should be:
Code:
sms(id_nr, token_nr, from_nr, to_nr, 'Test SMS by SL'..tostring(value))

Same trouble Sad

My Common Funtions:
Code:
--SMS by Twilio
function sms(id, token, from, to, body)
  local escape = require('socket.url').escape
  local request = require('ssl.https').request
  local url = string.format('https://%s:%s@api.twilio.com/2010-04-01/Accounts/%s/Messages.json', id, token, id)
  local body = string.format('From=%s&To=%s&Body=%s', escape(from), escape(to), escape(body))

  return request(url, body)
end
My Event:
Code:
value = event.getvalue()

from_nr = '+19177461563' -- put sender SIM nr here
to_nr = '+84938354162' -- put recepient SIM nr here
id_nr = '...' -- put your ID here
token_nr = '...' -- put your token here

sms(id_nr, token_nr, from_nr, to_nr, 'Test SMS by SL'..tostring(value))



RE: Help me! Notification SMS from LM using Twilio service - admin - 15.10.2019

Replace sms function with this one:
Code:
function sms(id, token, from, to, body)
  local escape = require('socket.url').escape
  local request = require('ssl.https').request
  local url = string.format('https://%s:%s@api.twilio.com/2010-04-01/Accounts/%s/Messages.json', id, token, id)
  local body = string.format('From=%s&To=%s&Body=%s', escape(from), escape(to), escape(body))
  local resp = {}
  local stat, code, hdrs = request({
    method = 'POST',
    url = url,
    protocol = 'tlsv12',
    sink = ltn12.sink.table(resp),
    source = ltn12.source.string(body),
    headers = {
      ['content-length'] = #body,
      ['content-type'] = 'application/x-www-form-urlencoded'
    }
  })

  if stat then
    stat = table.concat(resp)
  end

  return stat, code, hdrs
end



RE: Help me! Notification SMS from LM using Twilio service - cuong.nguyen@vis.solutions - 16.10.2019

(15.10.2019, 13:53)admin Wrote: Replace sms function with this one:
Code:
function sms(id, token, from, to, body)
  local escape = require('socket.url').escape
  local request = require('ssl.https').request
  local url = string.format('https://%s:%s@api.twilio.com/2010-04-01/Accounts/%s/Messages.json', id, token, id)
  local body = string.format('From=%s&To=%s&Body=%s', escape(from), escape(to), escape(body))
  local resp = {}
  local stat, code, hdrs = request({
    method = 'POST',
    url = url,
    protocol = 'tlsv12',
    sink = ltn12.sink.table(resp),
    source = ltn12.source.string(body),
    headers = {
      ['content-length'] = #body,
      ['content-type'] = 'application/x-www-form-urlencoded'
    }
  })

  if stat then
    stat = table.concat(resp)
  end

  return stat, code, hdrs
end

It's working!! Thank you so much Smile

But it takes about 15 min for 1 SMS, too long


RE: Help me! Notification SMS from LM using Twilio service - admin - 16.10.2019

You can try contacting Twilio support or ask your local operators if they provide SMS gateway service.


RE: Help me! Notification SMS from LM using Twilio service - cuong.nguyen@vis.solutions - 18.10.2019

(16.10.2019, 10:38)admin Wrote: You can try contacting Twilio support or ask your local operators if they provide SMS gateway service.

Hi, I tried to send command with https with this code:
Code:
local http = require('ssl.https')
mime = require("mime")
res, err = ssl.https.request('https://api.speedsms.vn/index.php/sms/send?access-token=...&to=84938354162&content=hello')
log(res, err)

Log message:
Code:
* arg: 1
  * nil
* arg: 2
  * string: Try again


I can send this link from web browser. But, not working with LM5. Please check and tell me how to fix this?
Thanks


RE: Help me! Notification SMS from LM using Twilio service - admin - 18.10.2019

Try updating LuaSocket library (System config > System > Packages > Add (+) green button)
New CPU: https://dl.openrb.com/pkg/luasocket_2.0.2-20191009_imx6.ipk
Old CPU: https://dl.openrb.com/pkg/luasocket_2.0.2-20191009_mxs.ipk


RE: Help me! Notification SMS from LM using Twilio service - cuong.nguyen@vis.solutions - 21.10.2019

(18.10.2019, 12:36)admin Wrote: Try updating LuaSocket library (System config > System > Packages > Add (+) green button)
New CPU: https://dl.openrb.com/pkg/luasocket_2.0.2-20191009_imx6.ipk
Old CPU: https://dl.openrb.com/pkg/luasocket_2.0.2-20191009_mxs.ipk

Hi,

It's work on LM5. How's about the HL&SL? I don't see update packages function in System page


RE: Help me! Notification SMS from LM using Twilio service - admin - 21.10.2019

Install latest firmware


RE: Help me! Notification SMS from LM using Twilio service - cuong.nguyen@vis.solutions - 23.10.2019

(21.10.2019, 09:21)admin Wrote: Install latest firmware

Hi,
I upgraded to ver 2.4.0. Still same trouble Sad


RE: Help me! Notification SMS from LM using Twilio service - cuong.nguyen@vis.solutions - 29.10.2019

Hi,
How can I fix this trouble?? W4K and LM5 can work, SL can not Sad

Thanks


RE: Help me! Notification SMS from LM using Twilio service - Daniel - 29.10.2019

SL is using all the same libraries as W4K as long you use the same version of FW. If it doesn't work your problem is elsewhere.


RE: Help me! Notification SMS from LM using Twilio service - admin - 29.10.2019

Check that your device has correct gateway and DNS set in System config > Network > Interfaces