Skip to content

Getting Started

If you are just starting with BotCity or want an overview of how to report processed items in the automation code, follow the guide below.

Report data with the Maestro SDK

You report information about the processed items using the Maestro SDK in your automation code.

Install the SDK

If the dependency is not installed yet, follow the instructions below:

pip install botcity-maestro-sdk

Dependency in requirements.txt

Besides installing the package, include the dependency in the robot's requirements.txt file.

<repositories>
    <repository>
        <id>nexus-botcity-public</id>
        <url>https://devtools.botcity.dev:8081/repository/botcity-public/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <!-- Your other dependencies -->
    <dependency>
        <groupId>dev.botcity</groupId>
        <artifactId>maestro-sdk</artifactId>
        <version>2.2.0</version>
    </dependency>
</dependencies>
dotnet add package BotCity.Maestro.SDK

Import the SDK

After installation, import the dependency and instantiate the Maestro SDK:

# Importing the Maestro SDK dependency
from botcity.maestro import *

# Disabling errors if there is no connection with the Orchestrator
BotMaestroSDK.RAISE_NOT_CONNECTED = False

# Instantiating the Maestro SDK
maestro = BotMaestroSDK.from_sys_args()
# Getting the details of the current task being executed
execution = maestro.get_execution()
// Importing the Maestro SDK dependency
import dev.botcity.maestro_sdk.*;
...

public void action(BotExecution botExecution) {

    try {
        // Instantiating the Maestro SDK
        BotMaestroSDK maestro = new BotMaestroSDK();
        maestro.login(botExecution);
    ...
// Import for integration with BotCity Maestro SDK
using Dev.BotCity;
using Dev.BotCity.MaestroSdk.Model.Execution;

// Instantiating the Maestro SDK
BotMaestroSDK maestro = BotMaestroSDK.FromSysArgs();
// Fetching the details of the current task being executed
Execution execution = await maestro.GetExecutionAsync(maestro.GetTaskId());

Report the process data

When finishing the task, report the number of items processed during the execution.

maestro.finish_task(
    task_id=execution.task_id,
    status=AutomationTaskFinishStatus.SUCCESS,
    message="Task Finished OK.",
    total_items=100, # Total number of items processed
    processed_items=90, # Number of items processed successfully
    failed_items=10 # Number of items processed with failure

)
maestro.finishTask(
    botExecution.getTaskId(),
    "Task Finished OK.",
    FinishStatus.SUCCESS,
    100, // Total number of items processed
    90, // Number of items processed successfully
    10 // Number of items processed with failure
);
await maestro.FinishTaskAsync(
    execution.TaskId,
    FinishStatusEnum.SUCCESS,
    "Task Finished OK.",
    100, // Total number of items processed
    90, // Number of items processed successfully
    10 // Number of items processed with failure
);

Complete code

Below is a complete example of an automation that counts the processed items and reports the data when finishing the task.

from botcity.core import DesktopBot
from botcity.maestro import *

# Disabling errors if there is no connection with the Orchestrator
BotMaestroSDK.RAISE_NOT_CONNECTED = False

def main():
    maestro = BotMaestroSDK.from_sys_args()
    execution = maestro.get_execution()

    # Implementing here the logic to process the items
    bot = DesktopBot()

    # The items can be any entity related to your automation process
    items = []
    processed_items = 0
    failed_items = 0

    # You can use the logic that is necessary to consume, process, and count the items
    for item in items:
        try:
            # Process the item...

            # Counting as an item processed successfully
            processed_items+=1

        except Exception:
            # Counting as an item processed with failure
            failed_items+=1

    # At the end, simply report the data of the processed items when finishing the task
    maestro.finish_task(
        task_id=execution.task_id,
        status=AutomationTaskFinishStatus.SUCCESS,
        message="Task Finished OK.",
        total_items=len(items), # Total number of items processed
        processed_items=processed_items, # Number of items processed successfully
        failed_items=failed_items # Number of items processed with failure
    )

def not_found(label):
    print(f"Element not found: {label}")

if __name__ == '__main__':
    main()
import java.util.List;
import java.util.ArrayList;
import dev.botcity.framework.bot.DesktopBot;
import dev.botcity.maestro_sdk.BotExecutor;
import dev.botcity.maestro_sdk.BotMaestroSDK;
import dev.botcity.maestro_sdk.model.AutomationTask.FinishStatus;
import dev.botcity.maestro_sdk.runner.BotExecution;
import dev.botcity.maestro_sdk.runner.RunnableAgent;

public class FirstBot extends DesktopBot implements RunnableAgent
{
    public FirstBot() {
        try {
            setResourceClassLoader(this.getClass().getClassLoader());
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void action(BotExecution botExecution) {

        try {
            BotMaestroSDK maestro = new BotMaestroSDK();
            maestro.login(botExecution);

            // The items can be any entity related to your automation process
            List<Object> items = new ArrayList<Object>();
            int processedItems = 0;
            int failedItems = 0;

            // You can use the logic that is necessary to consume, process, and count the items
            for(Object item : items){
                try{
                    // Process the item...

                    // Counting as an item processed successfully
                    processedItems+=1;
                }
                catch(Exception e){
                    // Counting as an item processed with failure
                    failedItems+=1;
                }
            }

            // At the end, simply report the data of the processed items when finishing the task
            maestro.finishTask(
                botExecution.getTaskId(),
                "Task Finished OK.",
                FinishStatus.SUCCESS,
                items.size(), // Total number of items processed
                processedItems, // Number of items processed successfully
                failedItems // Number of items processed with failure
            );

        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    private void notFound(String label) {
        System.out.println("Element not found: "+label);
    }

    public static void main(String[] args) {
        BotExecutor.run(new FirstBot(), args);
    }
}
using Dev.BotCity.MaestroSdk.Model.AutomationTask;
using Dev.BotCity.MaestroSdk.Model.Execution;
using System;
using System.Threading.Tasks;

namespace FirstBot
{
    class Program
    {
        static async Task Main(string[] args)
        {
            BotMaestroSDK maestro = BotMaestroSDK.FromSysArgs();
            Execution execution = await maestro.GetExecutionAsync(maestro.GetTaskId());

            Console.WriteLine("Task ID is: " + execution.TaskId);
            Console.WriteLine("Task Parameters are: " + string.Join(", ", execution.Parameters));

            // The items can be any entity related to your automation process
            string[] items;
            int processedItems = 0;
            int failedItems = 0;

            // You can use the logic that is necessary to consume, process, and count the items
            foreach (string item in items) 
            {
                try {
                    // Process the item...

                    // Counting as an item processed successfully
                    processedItems+=1;

                } catch (Exception ex) {
                    // Counting as an item processed with failure
                    failedItems+=1;
                }
            }

            // At the end, simply report the data of the processed items when finishing the task
            await maestro.FinishTaskAsync(
                execution.TaskId,
                FinishStatusEnum.SUCCESS,
                "Task Finished OK.",
                items.Length, // Total number of items processed
                processedItems, // Number of items processed successfully
                failedItems // Number of items processed with failure
            );
        }
    }
}

Code structure

Your automation does not need to follow a specific code structure.

You freely define the process logic and how to count the items.

At the end of the execution, report this data with the finish_task method of the Maestro SDK.