Conversation
Interface: Conversation
Conversation represents either a V1 or V2 conversation with a common set of methods.
Properties
clientAddress
clientAddress: string
The wallet address connected to the client
Defined in
conversations/Conversation.ts:45
context
Optional
context: InvitationContext
Optional field containing the conversationId
and metadata
for V2 conversations.
Will always be undefined on V1 conversations
Defined in
conversations/Conversation.ts:66
createdAt
createdAt: Date
Timestamp the conversation was created at
Defined in
conversations/Conversation.ts:61
ephemeralTopic
ephemeralTopic: string
A unique identifier for ephemeral envelopes for a conversation.
Defined in
conversations/Conversation.ts:53
peerAddress
peerAddress: string
The wallet address of the other party in the conversation
Defined in
conversations/Conversation.ts:57
topic
topic: string
A unique identifier for a conversation. Each conversation is stored on the network on one topic
Defined in
conversations/Conversation.ts:49
Methods
decodeMessage
decodeMessage(env
): Promise
<DecodedMessage
>
Takes a XMTP envelope as input and will decrypt and decode it
returning a DecodedMessage
instance.
Parameters
Name | Type |
---|---|
env | Envelope |
Returns
Promise
<DecodedMessage
>
Defined in
conversations/Conversation.ts:92
messages
messages(opts?
): Promise
<DecodedMessage
[]>
Retrieve messages in this conversation. Default to returning all messages.
If only a subset is required, results can be narrowed by specifying a start/end timestamp.
// Get all messages in the past 24 hours
const messages = await conversation.messages({
startTime: new Date(+new Date() - 86_400)
})
Parameters
Name | Type |
---|---|
opts? | ListMessagesOptions |
Returns
Promise
<DecodedMessage
[]>
Defined in
conversations/Conversation.ts:81
messagesPaginated
messagesPaginated(opts?
): AsyncGenerator
<DecodedMessage
[], any
, unknown
>
Deprecated
Parameters
Name | Type |
---|---|
opts? | ListMessagesPaginatedOptions |
Returns
AsyncGenerator
<DecodedMessage
[], any
, unknown
>
Defined in
conversations/Conversation.ts:85
prepareMessage
prepareMessage(content
, options?
): Promise
<PreparedMessage
>
Return a PreparedMessage
that has contains the message ID
of the message that will be sent.
Parameters
Name | Type |
---|---|
content | any |
options? | SendOptions |
Returns
Promise
<PreparedMessage
>
Defined in
conversations/Conversation.ts:123
send
send(content
, options?
): Promise
<DecodedMessage
>
Send a message into the conversation
Example
await conversation.send('Hello world') // returns a `DecodedMessage` instance
Parameters
Name | Type |
---|---|
content | any |
options? | SendOptions |
Returns
Promise
<DecodedMessage
>
Defined in
conversations/Conversation.ts:114
streamEphemeral
streamEphemeral(): Promise
<Stream
<DecodedMessage
>>
Return a Stream
of new ephemeral messages from this conversation's
ephemeral topic.
Stream instances are async generators and can be used in
for await
statements.
for await (const message of await conversation.streamEphemeral()) {
console.log(message.content)
}
Returns
Promise
<Stream
<DecodedMessage
>>
Defined in
conversations/Conversation.ts:141
streamMessages
streamMessages(): Promise
<Stream
<DecodedMessage
>>
Return a Stream
of new messages in this conversation.
Stream instances are async generators and can be used in
for await
statements.
for await (const message of await conversation.stream()) {
console.log(message.content)
}
Returns
Promise
<Stream
<DecodedMessage
>>