Compare commits

...

3 Commits

Author SHA1 Message Date
rodley82 f6a9446e32 ahora ingresa los datos 2 weeks ago
rodley82 d7fd5eacc0 logging to backend 2 weeks ago
rodley82 a73b161413 added readme 2 weeks ago
  1. 15
      README.md
  2. 89
      afip_ingresar_datos_operacion.lua
  3. 94
      afip_login.lua

15
README.md

@ -0,0 +1,15 @@
# AFIP Lua Scripts
These Lua scripts are intended to be used by the **bot-bunny** project.
They provide AFIP-related functionality that is consumed by bot-bunny services and tools. This repository is not meant to be used standalone; instead, it should be included or referenced from the main bot-bunny project.
## Usage
- **Include in bot-bunny:** Add this repository as a dependency or submodule of your main **bot-bunny** project.
- **Load scripts:** Configure your bot-bunny services to load and execute the relevant Lua scripts as needed.
- **Develop here, test there:** Any changes or additions to these scripts should be tested within the context of the bot-bunny project.
## Related Project
- **bot-bunny** – main project that uses these scripts.

89
afip_ingresar_datos_operacion.lua

@ -0,0 +1,89 @@
--[[
{
"uid": "53935f27-5cf0-4281-9a29-a68f100ee981",
"execution_status": "Borrador",
"tipo_comprobante": "factura c",
"fecha_comprobante": "13/11/2025",
"tipo_concepto": "servicios",
"servicio_fecha_desde": "01/10/2025",
"servicio_fecha_hasta": "01/10/2025",
"servicio_fecha_vencimiento_pago": "13/11/2025",
"referencia": "",
"tipo_iva_receptor": "consumidor final",
"cuit_receptor": "",
"forma_pago": "contado",
"monto_unitario": "10000",
"cantidad": "1",
"descripcion": "Clase de apoyo"
}
--]]
log("Inicio afip_ingresar_datos_operacion from LUA!!")
local err
print("BEFORE JSON LOADING payload: " .. json_payload)
local json = require("json")
print("AFTER JSON LOADING")
-- Parse the JSON string
local obj, err = json.decode(json_payload)
if err then
message = "Error parsing JSON: " .. err
log(message)
error(message)
end
local error_on_page
descripcion = obj["descripcion"]
monto_unitario = obj["monto_unitario"]
tipo_comprobante = obj["tipo_comprobante"]
--[[
if string.match(tipo_comprobante, "factura") then
log("Setting tipo_comprobante to factura")
tipo_comprobante = "factura"
else
log("Setting tipo_comprobante to ")
tipo_comprobante = "recibo"
end
--]]
-- TODO: handle factura AND recibo!
log("Descripcion: " .. descripcion .. " Monto: " .. monto_unitario .. " Tipo: " .. tipo_comprobante)
descripcion_selector = "#detalle_descripcion1"
precio_selector = "#detalle_precio1"
err = waitVisibleByQuerySelector(descripcion_selector)
if err then
message = "Error waiting for detalle_descripcion1: " .. err
log(message)
error(message)
end
err = setTextFieldByQuerySelector(descripcion_selector, descripcion)
if err then
message = "Error setting detalle_descripcion1: " .. err
log(message)
error(message)
end
waitSecs(1)
err = waitVisibleByQuerySelector(precio_selector)
if err then
message = "Error waiting for detalle_precio1: " .. err
log(message)
error(message)
end
err = setTextFieldByQuerySelector(precio_selector, monto_unitario)
if err then
message = "Error setting detalle_precio1: " .. err
log(message)
error(message)
end
waitSecs(1)
log("Finishing afip_ingresar_datos_operacion from LUA!!")

94
afip_login.lua

@ -1,49 +1,51 @@
local err local err
print("BEFORE JSON LOADING payload: " .. json_payload)
local json = require("json") local json = require("json")
print("AFTER JSON LOADING")
-- Parse the JSON string -- Parse the JSON string
local obj, err = json.decode(json_payload) local obj, err = json.decode(json_payload)
print("Cuit:" .. obj["cuit"]) log("Cuit:" .. obj["cuit"])
print("Password:" .. obj["password"])
cuit = obj["cuit"] cuit = obj["cuit"]
password = obj["password"] password = obj["password"]
print("Iniciando login AFIP") log("Iniciando login AFIP")
err = navigate("https://auth.afip.gob.ar/contribuyente_/login.xhtml") err = navigate("https://auth.afip.gob.ar/contribuyente_/login.xhtml")
if err then if err then
print(err) message = "Error navigating to login page: " .. err
return log(message)
error(message)
end end
err = waitVisibleByQuerySelector("input[name='F1:username']") err = waitVisibleByQuerySelector("input[name='F1:username']")
if err then if err then
print(err) message = "Error waiting for username field: " .. err
return log(message)
error(message)
end end
err = setTextFieldByQuerySelector("input[name='F1:username']", "") err = setTextFieldByQuerySelector("input[name='F1:username']", "")
if err then if err then
print(err) message = "Error setting username field: " .. err
return log(message)
error(message)
end end
waitSecs(2) waitSecs(2)
err = inputTextFieldByQuerySelector("input[name='F1:username']", cuit) err = inputTextFieldByQuerySelector("input[name='F1:username']", cuit)
if err then if err then
print(err) message = "Error inputting username: " .. err
return log(message)
error(message)
end end
waitSecs(2) waitSecs(2)
err = clickElementByQuerySelector("input[id=\"F1:btnSiguiente\"]") err = clickElementByQuerySelector("input[id=\"F1:btnSiguiente\"]")
if err then if err then
print(err) message = "Error clicking next button: " .. err
return log(message)
error(message)
end end
local error_on_page local error_on_page
@ -55,12 +57,15 @@ js_script = [[
error_on_page, err = evaluateJsWithStringOutput(js_script) error_on_page, err = evaluateJsWithStringOutput(js_script)
if err then if err then
print(err) message = "Error evaluating JS: " .. err
return log(message)
error(message)
end end
if error_on_page ~= "" then if error_on_page ~= "" then
print("Error on page:" .. error_on_page) message = "Error on page: " .. error_on_page
log(message)
error(message)
return return
end end
@ -68,44 +73,65 @@ waitSecs(2)
err = waitVisibleByQuerySelector("input[name='F1:password']") err = waitVisibleByQuerySelector("input[name='F1:password']")
if err then if err then
print(err) message = "Error waiting for password field: " .. err
return log(message)
error(message)
end end
err = inputTextFieldByQuerySelector("input[name='F1:password']", password) err = inputTextFieldByQuerySelector("input[name='F1:password']", password)
if err then if err then
print(err) message = "Error inputting password: " .. err
return log(message)
error(message)
end end
err = clickElementByQuerySelector("input[id=\"F1:btnIngresar\"]") err = clickElementByQuerySelector("input[id=\"F1:btnIngresar\"]")
if err then if err then
print(err) message = "Error clicking login button: " .. err
return log(message)
error(message)
end end
waitSecs(2) waitSecs(2)
error_on_page, err = evaluateJsWithStringOutput(js_script) error_on_page, err = evaluateJsWithStringOutput(js_script)
if err then if err then
print(err) message = "Error evaluating JS: " .. err
return log(message)
error(message)
end end
print("Error on page:" .. error_on_page) if error_on_page ~= "" then
if error_on_page:match("^%s*(.-)%s*$") ~= "" then message = "Error on page: " .. error_on_page
print("Error on page:" .. error_on_page) log(message)
return error(message)
end end
current_url, err = getCurrentUrl() current_url, err = getCurrentUrl()
if err then if err then
print(err) message = "Error getting current URL: " .. err
return log(message)
error(message)
end end
if string.match(current_url, "^https://auth%.afip%.gob%.ar/contribuyente_/login%.xhtml") then if string.match(current_url, "^https://auth%.afip%.gob%.ar/contribuyente_/login%.xhtml") then
print("Unexpected URL after login: " .. current_url) message = "Unexpected URL after login: " .. current_url
return log(message)
error(message)
end
log("Login successful!")
current_url, err = getCurrentUrl()
if err then
message = "Error getting current URL: " .. err
log(message)
error(message)
end
if string.match(current_url, "^https://auth%.afip%.gob%.ar/contribuyente_/login%.xhtml") then
message = "Unexpected URL after login: " .. current_url
log(message)
error(message)
end end
print("Login successful desde LUA!!") print("Login successful desde LUA!!")

Loading…
Cancel
Save