Skip to content

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.

Create a command

First think of which command you want the app to respond to. For example:

cmd
/send [amount] [token] [@username]
Properties
  • 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.
    • values: [] An array of strings that defines the accepted values for the parameter.
Example

Create the command file commands.ts in your project root src folder.

src/commands.ts
import type { CommandGroup } from "@xmtp/message-kit";
 
export const commands: CommandGroup[] = [
  {
    name: "Transactions",
    icon: "💸",
    description: "Multipurpose transaction command.",
    commands: [
      {
        command: "/send [amount] [token] [@username]",
        description:
          "Send a specified amount of a cryptocurrency to a destination address.",
        params: {
          amount: {
            default: 10, // Default value
            type: "number", // This will parse it to a number
          },
          token: {
            default: "usdc", // Default value
            type: "string", // String field always need to specify accepted values
            values: ["eth", "dai", "usdc", "degen"], // Accepted values
          },
          username: {
            default: "", // No default username
            type: "username", // This will parse it to a username array
          },
        },
      },
    ],
  },
];

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);

Overlapping commands

If the group has overlapping commands, meaning, the command is repeated in more than one mini app bot, the command will need to specifiy the handle of the mini app bot.

cmd
/command@bot_handle