Commands
Each app can have a commands.ts
file that contains the commands that the app can execute. The commands are defined as an array of objects with the following keys:
Receive a command
See more details in the receive commands section.
Declare a command
First think of which command you want the app to respond to. For example:
cmd
/send [amount] [token] [@username]
- command: The name of the command.
- description: The description of the command.
- params: Defines the parameters required for the command.
- default: The default value for the parameter. This can be any type.
- type: The type of the parameter. It can be one of the following:
number
: The parameter is a number.string
: The parameter is a string.username
: The parameter is a username.quoted
: The parameter is a quoted string.address
: The parameter is an address.prompt
: The parameter is a prompt.
- values:
[]
An array of strings that defines the accepted values for the parameter.
Create the command file commands.ts
in your project root src
folder.
src/commands.ts
import { handler as transaction } from "./handler/transaction.js";
export const commands: CommandGroup[] = [
{
name: "Transactions",
triggers: ["@send", "/send"],
description: "Multipurpose transaction frame built onbase.",
commands: [
{
command: "/send [amount] [token] [@username]", // Important for the AI agent to understand the command
description:
"Send a specified amount of a cryptocurrency to a destination address.",
handler: transaction, // The handler that will execute the command
params: { // To declare the parameters
amount: {
default: 10,
type: "number",
},
token: {
default: "usdc",
type: "string",
values: ["eth", "dai", "usdc", "degen"],
},
username: {
default: "",
type: "username",
},
},
},
],
},
];
Handle intent
To parse a string and execute a command handler, you can use the following method. When using responses from LLMs, you may want to execute the intent of the generated commands. This method will parse commands or send chained messages if they are in an array.
//Sepcifify the conversation
context.intent("/send 10 usdc to @alix", conv);
// open ai call
const { reply } = await textGeneration(response, prompt);
//Process the intent or an array of intents
context.intent(reply);
Learn more about intent.