Skip to content

Command

If the message starts with a / it is considered a command. See more details in the commands section.

Command object

The command object is a text type contains the following extra property:

{
  content: string, // The raw content of the message
  command: string, // The command root "send"
  params: params // The value of the parameters of the command
}

If the parameter is not correctly declared in the src/command.ts file or the text input from the user is not correct, the params will return undefined

Receive a command

Here's an example of how you can receive a text message in your app:

const { content, typeId } = context.message;
 
if (typeId === "text") {
  const { command, params } = content;
  // Use the extracted command and params
}

Let's say the user sends the command to the app.

cmd
/send 10 usdc @bo

The helper function will extract the parameters from the command.

params
{
  "command": "send",
  "params": {
    "amount": 10,
    "token": "usdc",
    "username": [
      {
        "address": "0xbo",
        "inboxId": "0xbo",
        "accountAddresses": ["0xbo"],
        "name": "bo"
      }
    ]
  }
}

Command handlers

An easier way to declare how to handle and respond to commands is to use handlers. Handlers help you orgaize the code being useful when you are managing multiple bots

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]",
        description:
          "Send a specified amount of a cryptocurrency to a destination address.",
        handler: transaction,  
        params: {
          amount: {
            default: 10,
            type: "number",
          },
          token: {
            default: "usdc",
            type: "string",
            values: ["eth", "dai", "usdc", "degen"],
          },
          username: {
            default: "",
            type: "username",
          },
        },
      },
    ],
  },
];