@textile/hub > Users > sendMessage
Users.sendMessage() method
A local user can author messages to remote user through their public-key
Signature:
sendMessage(from: Identity, to: Public, body: Uint8Array): Promise<UserMessage>;
Parameters
Parameter | Type | Description |
---|---|---|
from | Identity | defines the local, sending, user. Any object that conforms to the Identity interface. |
to | Public | defines the remote, receiving user. Any object that conforms to the Public interface. |
body | Uint8Array | is the message body bytes in UInt8Array format. |
Returns:
Promise<UserMessage>
Example
import { Users, Identity, PublicKey } from "@textile/hub"
async function example(users: Users, from: Identity, to: PublicKey, message: string) {
const encoder = new TextEncoder()
const body = encoder.encode(message)
return await users.sendMessage(from, to, body)
}