> For the complete documentation index, see [llms.txt](https://yeomen.gitbook.io/command/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yeomen.gitbook.io/command/yeomenai-library.md).

# YeomenAI library

### Overview

`YeomenAI` is a JavaScript object that provides various utility functions for managing Yeoman workers, generating messages, handling transactions, and more. This documentation explains the purpose and functionality of each function within the `YeomenAI` object.

### Constants

#### MESSAGE\_TYPES

Defines different types of messages that can be generated by the application.

* **INFO**: Informational messages
* **SUCCESS**: Messages indicating successful operations
* **WARNING**: Warning messages
* **ERROR**: Error messages

<figure><img src="/files/8y8Xg06F1tj05oEx4YfP" alt=""><figcaption><p>Info messages</p></figcaption></figure>

### Functions

#### `delay(seconds)`

Delays the execution for a specified number of seconds.

**Parameters**

* **seconds**: Number of seconds to delay.

#### `exit(state)`

Terminates the current Yeoman worker and posts an exit status with the given state.

**Parameters**

* **state**: The state is either 0 or 1 when exiting the Yeoman worker. 1 signifies an error state and 0 signifies a successful termination.

#### `telegramAlert(text)`

Sends an alert message to a specified Telegram chat. The Telegram alert is only sent if a user has correctly setup Telegram alerts.

**Parameters**

* **text**: The text message to send as an alert.

#### `sendTransaction(functionName, args, systemId)`

Handles blockchain transactions and posts a transaction message with the provided function name, arguments, and system ID.

**Parameters**

* **functionName**: The name of the contract function to call.
* **args**: The arguments to pass to the contract function.
* **systemId**: The system ID associated with the transaction.

#### `estimateContractGas(functionName, args, systemId)`

Estimates the gas required for a smart contract function call. This is also useful in cases to check if a transaction is likely to work if broadcast to the network.

**Parameters**

* **functionName**: The name of the contract function to call.
* **args**: The arguments to pass to the contract function.
* **systemId**: The system ID associated with the gas estimation.

#### `statusMessage(message, type = YeomenAI.MESSAGE_TYPES.INFO)`

Posts a status message with the given message and type.

**Parameters**

* **message**: The message to display.
* **type**: (Optional) The type of message. Default is `YeomenAI.MESSAGE_TYPES.INFO`.

#### `logMessage(message, type = YeomenAI.MESSAGE_TYPES.INFO)`

Logs a message with the given message and type.

**Parameters**

* **message**: The message to log.
* **type**: (Optional) The type of message. Default is `YeomenAI.MESSAGE_TYPES.INFO`.

#### `getQueryData(query)`

Executes a GraphQL query and posts the query data. This is only for projects that support GraphQL which is limited.

**Parameters**

* **query**: The GraphQL query string.

#### `getQuerySubscription(query)`

Subscribes to a GraphQL query and listens for real-time updates. This is only for projects that support GraphQL which is limited.

**Parameters**

* **query**: The GraphQL query string.

#### `getStorageItem(key)`

Retrieves a stored item from the local storage. This is useful in cases when you want to store some values for when the Yeoman resumes operation as all Yeomen is stateless.

**Parameters**

* **key**: The key of the storage item to retrieve.

#### `setStorageItem(key, value)`

Stores a key-value pair in the local storage. This is useful in cases when you want to store some values for when the Yeoman resumes operation as all Yeomen is stateless.

**Parameters**

* **key**: The key of the storage item to set.
* **value**: The value to store.

#### `removeStorageItem(key)`

Removes a specified item from the local storage. This is useful in cases when you want to store some values for when the Yeoman resumes operation as all Yeomen is stateless.

**Parameters**

* **key**: The key of the storage item to remove.

#### `prompt(data)`

Displays a prompt to the user and handles the user's input via Command.

**Parameters**

* **data**: An array containing the prompt configuration.

#### `markdown(data)`

Displays markdown content to the user. This is visible on the console for each of the Yeomen.

**Parameters**

* **data**: The markdown content to display.

#### `getContractData(functionName, args)`

Fetches data from a smart contract using the specified function name and arguments. This is fetched directly from the RPC endpoint.

**Parameters**

* **functionName**: The name of the contract function to call.
* **args**: The arguments to pass to the contract function.

#### `decodeMudRecord(schema, keyTuple, record)`

Decodes a record using the provided schema and key tuple. This provides a useful helper to decode MUD records that are retrieved directly from the RPC end point.

**Parameters**

* **schema**: The schema used to decode the record.
* **keyTuple**: The key tuple associated with the record.
* **record**: The record to decode.

`getApp(appId)`&#x20;

Fetches details of an application by its ID.

Parameters

* **appId**: The identifier of the application to fetch.&#x20;

`invokeApp(appId, options)`&#x20;

Invokes an application and executes the associated code.

Parameters

* **appId**: The identifier of the application to invoke.&#x20;
* **options**: (Optional) Options object, which may include form fields.&#x20;

`addAccount(data)`&#x20;

Adds a new account with provided data.

Parameters

* **data**: The account data to add.&#x20;

`signMessage(message)`&#x20;

Signs a message using the current account.

Parameters

* **message**: The message to sign.

This documentation provides a detailed overview of the functions available in the `YeomenAI` helper object, including their purpose and input parameters. Each function is designed to perform specific tasks related to Yeomen worker management, message generation, and interaction with blockchain networks.
