Lua
Lua
WaTrend Send WhatsApp Text
See more WaTrend Examples
Send a WhatsApp text.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- Use your actual access token instead of 555555555555555555555555555555
local req = chilkat.HttpRequest.new()
req:add_param("number", "84933313xxx")
req:add_param("type", "text")
req:add_param("message", "This is a test message")
req:add_param("instance_id", "609ACF283XXXX")
req:add_param("access_token", "555555555555555555555555555555")
-- Note: The WaTrend online documentation indicate a POST should be used.
-- However, it seems you might actually need to send a GET request.
-- It is unclear.
-- If a GET is neeed, you would just send to the URL w/ query params like this:
local sbUrl = chilkat.StringBuilder.new()
sbUrl:append("https://app.watrend.com/api/send.php?")
sbUrl:append(req:get_url_encoded_params())
local responseBodyStr = http:quick_get_str(sbUrl:get_as_string())
-- The responseBodyStr contains the JSON response from the server..
req.http_verb = "POST"
req.content_type = "application/x-www-form-urlencoded"
local resp = chilkat.HttpResponse.new()
local success = http:http_req("https://app.watrend.com/api/send.php", req, resp)
if not success then
print(http.last_error_text)
return
end
local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(resp.header)
print("Failed.")
return
end
print(resp.body_str)
-- Both success and failed responses use 200 status code.
-- A success response contains this JSON in the response body:
-- {"status":"success", ... }
-- A failed response will contain something like this:
-- {"status":"error","message":"License Invalidated"}
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
local status = jResp:string_of("status")
print("status: " .. status)