15.10.2019, 13:53
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