Skip to content

Commit 0c56810

Browse files
committed
Fix lint errors
1 parent fa348ed commit 0c56810

File tree

9 files changed

+482
-187
lines changed

9 files changed

+482
-187
lines changed

examples/express/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"dependencies": {
1212
"@xmtp/agent-starter": "workspace:*",
1313
"axios": "^1.7.9",
14-
"express": "^4.21.2"
14+
"express": "^5.0.1"
1515
},
1616
"devDependencies": {
17-
"@types/express": "^4.17.21",
17+
"@types/express": "^5.0.0",
1818
"@types/node": "^22.10.9",
1919
"typescript": "^5.7.3"
2020
},

examples/express/src/index.ts

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
import { xmtpClient, type XMTP } from "@xmtp/agent-starter";
2-
import express from "express";
2+
import express, { type Request, type Response } from "express";
33
import fetch from "node-fetch";
44

55
async function createServer(port: number, agent: XMTP) {
66
const app = express();
77
app.use(express.json());
88

99
// Endpoint to RECEIVE encrypted messages
10-
app.post("/receive", async (req, res) => {
11-
try {
12-
const { nonce, ciphertext, fromAddress } = req.body;
13-
const decryptedMessage = await agent.decrypt(
14-
nonce,
15-
ciphertext,
16-
fromAddress,
17-
);
18-
19-
console.log(`Server on port ${port} decrypted:`, decryptedMessage);
20-
return res.json({ success: true, decryptedMessage });
21-
} catch (error) {
22-
console.error("Error in /receive:", error);
23-
return res.status(500).json({ error: (error as Error).message });
24-
}
10+
app.post("/receive", (req: Request, res: Response) => {
11+
const { nonce, ciphertext, fromAddress } = req.body as {
12+
nonce: string;
13+
ciphertext: string;
14+
fromAddress: string;
15+
};
16+
agent
17+
.decrypt(nonce, ciphertext, fromAddress)
18+
.then((decryptedMessage) => {
19+
console.log(`Server on port ${port} decrypted:`, decryptedMessage);
20+
res.json({ success: true, decryptedMessage });
21+
})
22+
.catch((error: unknown) => {
23+
console.error("Error in /receive:", error);
24+
res.status(500).json({ error: (error as Error).message });
25+
});
2526
});
2627

2728
return new Promise((resolve) => {

examples/gated-group/src/index.ts

+27-33
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import {
2-
XMTP,
3-
xmtpClient,
4-
type Client,
5-
type Message,
6-
} from "@xmtp/agent-starter";
1+
import { xmtpClient, type Client, type Message } from "@xmtp/agent-starter";
72
import { Alchemy, Network } from "alchemy-sdk";
8-
import express from "express";
3+
import express, { type Request, type Response } from "express";
94

105
const settings = {
116
apiKey: process.env.ALCHEMY_API_KEY, // Replace with your Alchemy API key
@@ -44,20 +39,23 @@ async function main() {
4439
// Endpoint to add wallet address to a group from an external source
4540
const app = express();
4641
app.use(express.json());
47-
app.post("/add-wallet", async (req, res) => {
48-
try {
49-
const { walletAddress, groupId } = req.body;
50-
const verified = true; // (await checkNft(walletAddress, "XMTPeople"));
51-
if (!verified) {
52-
console.log("User cant be added to the group");
53-
return;
54-
} else {
55-
await addToGroup(groupId, agent.client as Client, walletAddress, true);
42+
app.post("/add-wallet", (req: Request, res: Response) => {
43+
const { walletAddress, groupId } = req.body as {
44+
walletAddress: string;
45+
groupId: string;
46+
};
47+
// const verified = true; // (await checkNft(walletAddress, "XMTPeople"));
48+
// if (!verified) {
49+
// console.log("User cant be added to the group");
50+
// return;
51+
// } else {
52+
addToGroup(groupId, agent.client as Client, walletAddress, true)
53+
.then(() => {
5654
res.status(200).send("success");
57-
}
58-
} catch (error: any) {
59-
res.status(400).send(error.message);
60-
}
55+
})
56+
.catch((error: unknown) => {
57+
res.status(400).send((error as Error).message);
58+
});
6159
});
6260
// Start the servfalcheer
6361
const PORT = process.env.PORT || 3000;
@@ -85,15 +83,15 @@ export async function createGroup(
8583
try {
8684
let senderInboxId = "";
8785
await client.conversations.sync();
88-
const conversations = await client.conversations.list();
86+
const conversations = client.conversations.list();
8987
console.log("Conversations", conversations.length);
9088
const group = await client.conversations.newGroup([
9189
senderAddress,
9290
clientAddress,
9391
]);
9492
console.log("Group created", group.id);
9593
const members = await group.members();
96-
const senderMember = members.find((member: any) =>
94+
const senderMember = members.find((member) =>
9795
member.accountAddresses.includes(senderAddress.toLowerCase()),
9896
);
9997
if (senderMember) {
@@ -103,10 +101,7 @@ export async function createGroup(
103101
console.log("Sender not found in members list");
104102
}
105103
await group.addSuperAdmin(senderInboxId);
106-
console.log(
107-
"Sender is superAdmin",
108-
await group.isSuperAdmin(senderInboxId),
109-
);
104+
console.log("Sender is superAdmin", group.isSuperAdmin(senderInboxId));
110105
await group.send(`Welcome to the new group!`);
111106
await group.send(`You are now the admin of this group as well as the bot`);
112107
return group;
@@ -125,12 +120,11 @@ export async function removeFromGroup(
125120
const lowerAddress = senderAddress.toLowerCase();
126121
const isOnXMTP = await client.canMessage([lowerAddress]);
127122
console.warn("Checking if on XMTP: ", isOnXMTP);
128-
if (!isOnXMTP) {
123+
if (!isOnXMTP.get(lowerAddress)) {
129124
console.error("You don't seem to have a v3 identity ");
130125
return;
131126
}
132-
const conversation =
133-
await client.conversations.getConversationById(groupId);
127+
const conversation = client.conversations.getConversationById(groupId);
134128
console.warn("removing from group", conversation?.id);
135129
await conversation?.sync();
136130
await conversation?.removeMembers([lowerAddress]);
@@ -169,11 +163,11 @@ export async function addToGroup(
169163
try {
170164
const lowerAddress = address.toLowerCase();
171165
const isOnXMTP = await client.canMessage([lowerAddress]);
172-
if (!isOnXMTP) {
166+
if (!isOnXMTP.get(lowerAddress)) {
173167
console.error("You don't seem to have a v3 identity ");
174168
return;
175169
}
176-
const group = await client.conversations.getConversationById(groupId);
170+
const group = client.conversations.getConversationById(groupId);
177171
console.warn("Adding to group", group?.id);
178172
await group?.sync();
179173
await group?.addMembers([lowerAddress]);
@@ -209,8 +203,8 @@ export async function checkNft(
209203
const nfts = await alchemy.nft.getNftsForOwner(walletAddress);
210204

211205
const ownsNft = nfts.ownedNfts.some(
212-
(nft: any) =>
213-
nft.contract.name.toLowerCase() === collectionSlug.toLowerCase(),
206+
(nft) =>
207+
nft.contract.name?.toLowerCase() === collectionSlug.toLowerCase(),
214208
);
215209
console.log("is the nft owned: ", ownsNft);
216210
return ownsNft;

packages/agent-starter/src/content-types/agent-message.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
type ContentCodec,
44
type EncodedContent,
55
} from "@xmtp/content-type-primitives";
6+
import type { Metadata } from "../lib/types";
67

78
// Create a unique identifier for your content type
89
export const ContentTypeAgentMessage = new ContentTypeId({
@@ -15,14 +16,11 @@ export const ContentTypeAgentMessage = new ContentTypeId({
1516
// Define the message structure with metadata
1617
export class AgentMessage {
1718
public text: string;
18-
public metadata: {
19-
[key: string]: any; // Allow for flexible metadata
20-
};
19+
public metadata: Metadata;
2120

22-
constructor(text: string, metadata: any) {
21+
constructor(text: string, metadata: Metadata) {
2322
this.text = text;
2423
this.metadata = {
25-
timestamp: Date.now(),
2624
isAgent: true,
2725
...metadata,
2826
};
@@ -45,7 +43,10 @@ export class AgentMessageCodec implements ContentCodec<AgentMessage> {
4543

4644
decode(encodedContent: EncodedContent): AgentMessage {
4745
const decoded = new TextDecoder().decode(encodedContent.content);
48-
const { text, metadata } = JSON.parse(decoded);
46+
const { text, metadata } = JSON.parse(decoded) as {
47+
text: string;
48+
metadata: Metadata;
49+
};
4950
return new AgentMessage(text, metadata);
5051
}
5152

packages/agent-starter/src/lib/types.ts

+21-16
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ import type { privateKeyToAccount } from "viem/accounts";
55
export type { Client };
66
export type { ClientOptions };
77

8+
export type Metadata = {
9+
isAgent?: boolean;
10+
[key: string]: any;
11+
};
12+
813
export type agentMessage = {
914
message: string;
1015
originalMessage?: Message;
11-
metadata?: any;
16+
metadata: Metadata;
1217
receivers?: string[];
1318
typeId?:
1419
| "text"
@@ -54,23 +59,23 @@ export type Message = {
5459
sent: Date; // Date when the message was sent
5560
isDM: boolean; // Whether the message is a direct message
5661
content: {
57-
text?: string | undefined; // Text content of the message
58-
reply?: string | undefined; // Reply content if the message is a reply
59-
previousMsg?: string | undefined; // Reference to the previous message
60-
attachment?: string | undefined; // Attachment content if the message is an attachment
61-
react?: string | undefined; // Reaction content if the message is a reaction
62-
content?: any | undefined; // Any other content
63-
metadata?: any | undefined; // Metadata for the message
64-
remoteAttachment?: any | undefined; // Remote attachment content if the message is a remote attachment
65-
readReceipt?: any | undefined; // Read receipt content if the message is a read receipt
66-
agentMessage?: any | undefined; // Agent message content if the message is an agent message
67-
reaction?: any | undefined; // Reaction content if the message is a reaction
68-
params?: any | undefined; // Parameters for the message
69-
reference?: string | undefined; // Reference ID for the message
70-
skill?: string | undefined; // Skill associated with the message
62+
text?: string; // Text content of the message
63+
reply?: string; // Reply content if the message is a reply
64+
previousMsg?: string; // Reference to the previous message
65+
attachment?: string; // Attachment content if the message is an attachment
66+
react?: string; // Reaction content if the message is a reaction
67+
content: any; // Any other content
68+
metadata?: any; // Metadata for the message
69+
remoteAttachment?: any; // Remote attachment content if the message is a remote attachment
70+
readReceipt?: any; // Read receipt content if the message is a read receipt
71+
agentMessage?: any; // Agent message content if the message is an agent message
72+
reaction?: any; // Reaction content if the message is a reaction
73+
params?: any; // Parameters for the message
74+
reference?: string; // Reference ID for the message
75+
skill?: string; // Skill associated with the message
7176
any?: any; // Any other content
7277
};
73-
group?: Conversation | undefined; // Group the message belongs to
78+
group?: Conversation; // Group the message belongs to
7479
sender: User; // Sender of the message
7580
typeId: string; // Type identifier for the message
7681
client: {

0 commit comments

Comments
 (0)