Browse Source

initial scripts

master
rodley82 2 months ago
commit
8e4e9ba58f
  1. 28
      botbunny_starting.lua
  2. 40
      sample_files_posting.lua.example

28
botbunny_starting.lua

@ -0,0 +1,28 @@
log("inicia botbunny_inicio")
local function log_print(message)
log(message)
print(message)
end
local function log_error(message)
log(message)
error(message)
end
local err
local json = require("json")
local obj, err = json.decode(json_payload)
if err then
log_error("Decoding error" .. err)
end
log_print("Por abrir pagina de loading")
err = navigate("https://www.bot-bunny.com/loading")
if err then
log_error("navigate error" .. err)
end
log_print("durmiendo por 5 segundos")
waitSecs(5)

40
sample_files_posting.lua.example

@ -0,0 +1,40 @@
local function post_to_n8n(endpoint, json)
local http = require("http")
local client = http.client()
local request = http.request("POST", endpoint, json)
request:header_set("Content-Type", "application/json")
local result, err = client:do_request(request)
if err then
log_print("post_to_n8n error: " .. err)
error(err)
end
end
-- files_table should have the form:
-- {
-- fieldname = "file",
-- path = "./test/data/test.txt"
-- }
local function post_file_to_n8n(endpoint, files_table, form_fields_table)
local http = require("http")
local client = http.client()
local file_request = http.file_request(endpoint, files_table)
-- file_request:header_set("Content-Type", "application/json")
local result, err = client:do_request(file_request)
if err then
log_print("post_file_to_n8n error: " .. err)
error(err)
end
if result then
log_print("post_file_to_n8n result Code: " .. result.code .. " Body: " .. result.body)
end
end
-- This ends up being a POST form-encoded request will = "to_win" is a form field value
post_file_to_n8n(
"https://endpoint.sample", { {
fieldname = "file1", path = "/Users/rodo/trabajo/rodley/botbunny/bot-bunny-go/Icon.png"
}, { fieldname = "file2", path = "/Users/rodo/trabajo/rodley/botbunny/bot-bunny-go/cmd/cli/bf467f02-fa3a-4b67-981a-eaa39c56332f.pdf", filename = "custom-b.pdf" } },
{ will = "to_win" }
)
Loading…
Cancel
Save