import { ShutdownHandler } from "../index.js"; import { BotInstanceConfiguration, BotTypeConfiguration } from "../configuration/index.js"; import { BoticaClient, OrderListener } from "../protocol/index.js"; /** * A bot instance in a Botica environment. * * @author Alberto Mimbrero */ export declare class Bot { private readonly boticaClient; private readonly botTypeConfiguration; private readonly botConfiguration; private running; private proactiveTask?; private proactiveTaskInterval; readonly shutdownHandler: ShutdownHandler; constructor(boticaClient: BoticaClient, botTypeConfiguration: BotTypeConfiguration, botConfiguration: BotInstanceConfiguration); proactive: (task: () => void | Promise) => void; /** * Sets the proactive task for this bot. The task will be executed * periodically based on the bot's configuration. * * @param task The asynchronous or synchronous function to execute. * @throws Error if the bot is not configured as 'proactive'. */ setProactiveTask(task: () => void | Promise): void; on: (action: string, listener: OrderListener) => void; registerOrderListener: (action: string, listener: OrderListener) => void; /** * Registers a listener for an order with a specific action. * * @param action The action to listen for. * @param listener A callback function that receives the payload. */ onOrder(action: string, listener: OrderListener): void; registerDefaultOrderListener: (listener: OrderListener) => void; /** * Registers a listener for an order with the default action defined in the configuration. * * @param listener A callback function that receives the payload. * @throws Error if no default action is specified in the configuration. */ onDefaultOrder(listener: OrderListener): void; publish: (key: string, action: string, payload: any) => Promise; /** * Publishes an order with the given key and action. * * @param key The key to publish the order with. * @param action The action of the order. * @param payload The payload of the order. If not a string, it will be * stringified using JSON.stringify(). */ publishOrder(key: string, action: string, payload: any): Promise; /** * Publishes an order using the default key and action from the configuration. * * @param payload The payload of the order. If not a string, it will be * stringified using JSON.stringify(). */ publishDefaultOrder(payload: any): Promise; /** * Returns the unique ID of this bot instance. * This ID is assigned by the Botica Director and is unique within the environment. */ get id(): string; /** * Returns the bot type this instance belongs to. * A bot type groups multiple instances that share the same Docker image and general configuration. */ get type(): string; /** * Returns the hostname of this bot's container. */ get hostname(): string; /** * Returns the hostname of the given bot's container. * * @param botId the ID of the bot instance */ getBotHostname(botId: string): string; /** * Starts the bot and connects to the message broker. */ start(): Promise; private setupHeartbeat; private startProactiveScheduler; /** * Returns whether the bot is running. */ get isRunning(): boolean; /** * Closes the connection and stops the bot. */ stop(): Promise; private getLifecycleConfiguration; }