File tree 8 files changed +31
-44
lines changed
8 files changed +31
-44
lines changed Original file line number Diff line number Diff line change @@ -29,9 +29,6 @@ You can generate random keys with the following command:
29
29
yarn gen:keys
30
30
```
31
31
32
- > [ !WARNING]
33
- > Running the ` gen:keys ` script will overwrite the existing ` .env ` file.
34
-
35
32
### Fetching messages
36
33
37
34
There are to ways to fetch messages from a conversation, one is by starting a stream
@@ -72,32 +69,6 @@ for (const conversation of conversations) {
72
69
}
73
70
```
74
71
75
- ### Working with addresses
76
-
77
- Conversations in XMTP can be ` DMs ` or ` Groups ` . The underlying technicalities are the same, but DMs are essentially groups locked between two users that can be reused - basically a fixed group of 2. This is how MLS works.
78
-
79
- Each member of a conversation has the following properties:
80
-
81
- ``` tsx
82
- inboxId : string ; // unique identifier from the XMTP network
83
- accountAddresses : Array < string > ; // ethereum network addresses
84
- installationIds : Array < string > ; // How many active devices the user has
85
- permissionLevel : PermissionLevel ; // In the context of a group, if it's admin or not
86
- consentState : ConsentState ; // If it's blocked or allowed via consent
87
- ```
88
-
89
- To fetch an ethereum address in a DM, you can use a script like the following:
90
-
91
- ``` tsx
92
- const address =
93
- (await group .members ?.find (
94
- (member : any ) => member .inboxId === dm .dmPeerInboxId ,
95
- )?.accountAddresses [0 ]) || " " ;
96
- ```
97
-
98
- > [ !WARNING]
99
- > XMTP is working on integrating passkeys as a pillar of identity. Expect a breaking change soon as XMTP prepares for the first v3 stable release.
100
-
101
72
## Web inbox
102
73
103
74
Interact with the XMTP network using [ xmtp.chat] ( https://xmtp.chat ) , the official web inbox for developers.
Original file line number Diff line number Diff line change @@ -20,9 +20,6 @@ You can generate random keys with the following command:
20
20
yarn gen:keys
21
21
```
22
22
23
- > [ !WARNING]
24
- > Running the ` gen:keys ` script will overwrite the existing ` .env ` file.
25
-
26
23
## Start the XMTP agent
27
24
28
25
Start your XMTP client and begin listening to messages. The bot responds to the following commands:
Original file line number Diff line number Diff line change 1
1
import { Client , type XmtpEnv } from "@xmtp/node-sdk" ;
2
- import { createSigner , getEncryptionKeyFromHex } from "@/helpers" ;
2
+ import {
3
+ createSigner ,
4
+ getAddressOfMember ,
5
+ getEncryptionKeyFromHex ,
6
+ } from "@/helpers" ;
3
7
4
8
/* Get the wallet key associated to the public key of
5
9
* the agent and the encryption key for the local db
@@ -62,8 +66,10 @@ async function main() {
62
66
console . log ( "Unable to find conversation, skipping" ) ;
63
67
continue ;
64
68
}
69
+ const members = await conversation . members ( ) ;
65
70
66
- console . log ( `Sending "gm" response...` ) ;
71
+ const address = getAddressOfMember ( members , message . senderInboxId ) ;
72
+ console . log ( `Sending "gm" response to ${ address } ...` ) ;
67
73
/* Send a message to the conversation */
68
74
await conversation . send ( "gm" ) ;
69
75
Original file line number Diff line number Diff line change @@ -18,9 +18,6 @@ You can generate random keys with the following command:
18
18
yarn gen:keys
19
19
```
20
20
21
- > [ !WARNING]
22
- > Running the ` gen:keys ` script will overwrite the existing ` .env ` file.
23
-
24
21
## Usage
25
22
26
23
``` tsx
Original file line number Diff line number Diff line change 1
1
import { getRandomValues } from "node:crypto" ;
2
- import { IdentifierKind } from "@xmtp/node-bindings" ;
2
+ import { IdentifierKind , type GroupMember } from "@xmtp/node-bindings" ;
3
3
import { type Signer } from "@xmtp/node-sdk" ;
4
4
import { fromString , toString } from "uint8arrays" ;
5
5
import { createWalletClient , http , toBytes } from "viem" ;
@@ -44,6 +44,25 @@ export const createSigner = (key: `0x${string}`): Signer => {
44
44
} ;
45
45
} ;
46
46
47
+ /**
48
+ * Get the address of a member
49
+ * @param members - The members of the group
50
+ * @param inboxId - The inboxId of the member
51
+ * @returns The address of the member
52
+ */
53
+ export function getAddressOfMember ( members : GroupMember [ ] , inboxId : string ) {
54
+ for ( const member of members ) {
55
+ for ( const identifier of member . accountIdentifiers ) {
56
+ if (
57
+ identifier . identifierKind === IdentifierKind . Ethereum &&
58
+ member . inboxId === inboxId
59
+ ) {
60
+ return identifier . identifier ;
61
+ }
62
+ }
63
+ }
64
+ }
65
+
47
66
/**
48
67
* Generate a random encryption key
49
68
* @returns The encryption key
Original file line number Diff line number Diff line change @@ -22,9 +22,6 @@ You can generate random keys with the following command:
22
22
yarn gen:keys
23
23
```
24
24
25
- > [ !WARNING]
26
- > Running the ` gen:keys ` script will overwrite the existing ` .env ` file.
27
-
28
25
## Usage
29
26
30
27
``` tsx
Original file line number Diff line number Diff line change @@ -18,9 +18,6 @@ You can generate random keys with the following command:
18
18
yarn gen:keys
19
19
```
20
20
21
- > [ !WARNING]
22
- > Running the ` gen:keys ` script will overwrite the existing ` .env ` file.
23
-
24
21
## Usage
25
22
26
23
``` tsx
Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ await writeFile(
15
15
`WALLET_KEY=${ walletKey }
16
16
ENCRYPTION_KEY=${ encryptionKeyHex }
17
17
` ,
18
+ {
19
+ flag : "a" ,
20
+ } ,
18
21
) ;
19
22
20
23
console . log ( `Keys written to ${ filePath } ` ) ;
You can’t perform that action at this time.
0 commit comments