Structure
File structure
Each app consists of the following files:
app-project/ # Optional middleware files
├── src/
│ └── index.ts # Entry point for your app. // [!code hl] // [!code focus]
│ └── commands.ts # Commands for your app. // [!code hl] // [!code focus]
├── tsconfig.json // [!code hl] // [!code focus]
├── package.json // [!code hl] // [!code focus]
└── .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",
triggers: ["/help"],
description: "Command for managing default behaviours.",
commands: [
{
command: "/help",
handler: undefined,
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)