Skip to content

Commit e34147f

Browse files
committed
text file
1 parent e6abf70 commit e34147f

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

examples/gm-text/src/lib/helper.ts

+12-21
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,17 @@ export interface UserReturnType {
3535
wallet: ReturnType<typeof createWalletClient>;
3636
}
3737

38-
export type xmtpConfig = {
39-
path?: string;
40-
hideInitLogMessage?: boolean;
41-
} & ClientOptions;
42-
43-
export type Agent = {
38+
export type xmtpClientType = {
4439
name?: string;
4540
walletKey?: string;
4641
encryptionKey?: string;
4742
onMessage?: (message: Message) => Promise<void>;
48-
config?: xmtpConfig;
43+
config?: ClientOptions;
4944
};
5045

5146
export type Message = {
5247
id: string; // Unique identifier for the message
5348
sent: Date; // Date when the message was sent
54-
isDM: boolean; // Whether the message is a direct message
5549
content: {
5650
text?: string | undefined; // Text content of the message
5751
reply?: string | undefined; // Reply content if the message is a reply
@@ -90,7 +84,7 @@ export type Message = {
9084
};
9185
};
9286

93-
export async function xmtpClient(agent?: Agent): Promise<XMTP> {
87+
export async function xmtpClient(agent?: xmtpClientType): Promise<XMTP> {
9488
let xmtp: XMTP | null = null; // Ensure a single instance
9589
xmtp = new XMTP(agent);
9690
await xmtp.init();
@@ -102,9 +96,9 @@ export class XMTP {
10296
address: string | undefined;
10397
inboxId: string | undefined;
10498
onMessage: (message: Message) => Promise<void>;
105-
agent?: Agent;
99+
agent?: xmtpClientType;
106100

107-
constructor(agent?: Agent) {
101+
constructor(agent?: xmtpClientType) {
108102
this.onMessage = agent?.onMessage ?? (() => Promise.resolve());
109103
this.agent = agent;
110104
}
@@ -133,18 +127,18 @@ export class XMTP {
133127
let env = this.agent?.config?.env;
134128
if (!env) env = "production";
135129

136-
const volumePath =
130+
const dbPath =
137131
process.env.RAILWAY_VOLUME_MOUNT_PATH ??
138-
this.agent?.config?.path ??
132+
this.agent?.config?.dbPath ??
139133
".data/xmtp";
140134

141-
if (!fs.existsSync(volumePath)) {
142-
fs.mkdirSync(volumePath, { recursive: true });
135+
if (!fs.existsSync(dbPath)) {
136+
fs.mkdirSync(dbPath, { recursive: true });
143137
}
144138

145139
const defaultConfig: ClientOptions = {
146140
env: env,
147-
dbPath: `${volumePath}/${user.account.address.toLowerCase()}-${env}`,
141+
dbPath: `${dbPath}/${user.account.address.toLowerCase()}-${env}`,
148142
codecs: [new TextCodec()],
149143
};
150144

@@ -291,17 +285,14 @@ export function createUser(key: string): UserReturnType {
291285
}
292286

293287
export async function parseMessage(
294-
message: DecodedMessage | undefined | null,
288+
message: DecodedMessage,
295289
conversation: Conversation | undefined,
296290
client: Client,
297291
): Promise<Message | undefined> {
298-
if (message === null || message === undefined) return undefined;
299-
300292
const content = {
301293
text: message.content as string,
302294
};
303295

304-
const date = message.sentAt;
305296
let sender:
306297
| {
307298
inboxId: string;
@@ -335,7 +326,7 @@ export async function parseMessage(
335326
admins: conversation?.admins,
336327
superAdmins: conversation?.superAdmins,
337328
},
338-
sent: date,
329+
sent: message.sentAt,
339330
content,
340331
typeId: "text",
341332
client: {

packages/agent-starter/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"directory": "packages/agent-starter"
1212
},
1313
"license": "MIT",
14+
"type": "module",
1415
"exports": {
1516
".": {
1617
"types": "./dist/index.d.ts",

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

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export type Conversation = {
5757
export type Message = {
5858
id: string; // Unique identifier for the message
5959
sent: Date; // Date when the message was sent
60-
isDM: boolean; // Whether the message is a direct message
6160
content: {
6261
text?: string; // Text content of the message
6362
reply?: string; // Reply content if the message is a reply

0 commit comments

Comments
 (0)