Structure
File structure
Each app consists of the following files:
app-project/ # Optional middleware files
├── src/
│ └── index.ts # Entry point for your agent.
│ └── prompt.ts # Prompt for your agent.
├── tsconfig.json
├── package.json
└── .env # Environment variables
Runner
This is the main function that runs the listener.
import {
run,
XMTPContext,
} from "@xmtp/message-kit";
run(
async (context: XMTPContext) => {
// your logic here
},
{ skills,
/*optional parameters*/
},
);
Optional parameters
privateKey
: the private key of the agent wallet, like any normal wallet private key.experimental
: experimental features like logging all group messages. Default isfalse
.attachments
: to receive attachments. Default isfalse
.gptModel
: model to be used. Default isgpt-4o
.client
: Optional parameters to pass to the XMTP client.skills
: Custom skills to be used. Default is to create the skills in thesrc/skills.ts
file.hideInitLogMessage
: hide the init log message with messagekit logo and stuffmemberChange
: if true, member changes will be enabled, like adding members to the group
XMTPContext
XMTPContext bridges the skills to the XMTP protocol. It's aware of conversations, groups and users.
import { XMTPContext } from "@xmtp/message-kit";
run(async (context: XMTPContext) => {
const {
message,
group,
conversation,
client,
version,
v2client,
members,
admins,
runConfig,
superAdmins,
} = context;
});
Context properties
message
: the message objectgroup
: the group objectconversation
: the conversation objectclient
: the client objectversion
: the version of the clientv2client
: the v2 client objectmembers
: the members of the groupadmins
: the admins of the groupsuperAdmins
: the super admins of the grouprunConfig
: the config of the Runnersender
: the sender of the message
Clients
Use this instead of XMTP sdks for compatibility with MessageKit
import { V2Client, V3Client } from "@xmtp/message-kit";
You can export other clients on run time by importing the xmtpClient
function.
import { xmtpClient } from "@xmtp/message-kit";
const { v2client: newClient } = await xmtpClient({
{
privateKey: /*Your private key*/,
/*optional parameters*/
},
);
This is used in the Cron middleware to send updates to the users.
Manual Installation
You can also install the package manually using your preferred package manager.
bun
bun i @xmtp/message-kit