kpcyrd/whatsapp
function run(arg)
local phonenumber = arg['value']:gsub('%W', '')
local session = http_mksession()
local url = 'https://api.whatsapp.com/send/?phone=' .. phonenumber .. '&text&app_absent=0'
local req = http_request(session, 'GET', url, {})
local r = http_fetch(req)
if last_err() then return end
local html = r['text']
local main_block = html_select(html, '#main_block')
local name_block = html_select(main_block['html'], 'h1')
local name = name_block['text']
debug('Main block h1 text: ' .. json_encode(name))
if str_find(name:gsub('%W', ''), phonenumber) == nil then
db_update('phonenumber', arg, {
caller_name=name,
})
end
end