From 8e4e9ba58f9760f36a035ee58b241ccdc5f16715 Mon Sep 17 00:00:00 2001 From: rodley82 Date: Sat, 6 Dec 2025 20:35:17 -0300 Subject: [PATCH] initial scripts --- botbunny_starting.lua | 28 ++++++++++++++++++++++ sample_files_posting.lua.example | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 botbunny_starting.lua create mode 100644 sample_files_posting.lua.example diff --git a/botbunny_starting.lua b/botbunny_starting.lua new file mode 100644 index 0000000..9ba9328 --- /dev/null +++ b/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) + diff --git a/sample_files_posting.lua.example b/sample_files_posting.lua.example new file mode 100644 index 0000000..d17cdb2 --- /dev/null +++ b/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" } +)