Skip to content

Structure

File structure

Each app consists of the following files:

app-project/              # Optional middleware files
├── src/
│   └── index.ts          # Entry point for your app.
│   └── commands.ts       # Commands for your app.
├── tsconfig.json
├── package.json
└── .env                  # Environment variables

Main code

The index.ts file is the entry point for your app. It should contain something like the following:

src/index.ts
import { run, HandlerContext } from "@xmtp/message-kit";
 
run(async (context: HandlerContext) => {
  // Get the message and the address from the sender
  const { content, sender } = context.message;
 
  // To reply, just call `reply` on the HandlerContext.
  await context.send(`gm`);
});

Commands

Each app can have a commands.ts file that contains the available commands for the users. The commands are defined as an array of objects with the following structure:

src/commands.ts
export const commands = [
  {
    name: "General Commands",
    icon: "🔧",
    description: "Command for managing default behaviours.",
    commands: [
      {
        command: "/help",
        description: "Get help with the app.",
      },
    ],
  },
];

To learn more on how to define commands, go to commands section

Environment variables

Each app should have an .env file that contains the following:

.env
KEY= # 0x... the private key of the bot wallet, like any normal wallet private key. (with the 0x prefix)
MSG_LOG=false # logs the message on the console (optional)
XMTP_ENV=production # dev or production (optional)