Forward messages
Forward messages between channels to share information or facilitate collaboration.
Use forward() on a message object or forwardMessage() on a channel object. Both produce the same result with different input parameters.
Additional info in the forwarded message
Forwarded messages include originalPublisher (original sender's user ID) and originalChannelId (source channel ID).
Method signature
These methods take the following parameters:
-
forward()1message.forward(
2 channelId: string
3): Promise<void> -
forwardMessage()1channel.forwardMessage(
2 message: Message
3): Promise<void>
Input
| Parameter | Required in forward() | Required in forwardMessage() | Description |
|---|---|---|---|
channelIdType: stringDefault: n/a | Yes | No | Unique identifier of the channel to which you want to forward the message. You can forward a message to the same channel on which it was published or to any other. |
messageType: MessageDefault: n/a | No | Yes | Message object that you want to forward to the selected channel. |
Output
| Type | Description |
|---|---|
Promise<void> | Method returns no output data. |
Errors
Whenever the channel ID or the message is required as a parameter, and you try to forward the message without providing it, you will receive the Channel ID is required or the Message is required error.
Sample code
Forward the latest message from the support channel to the incident-management channel.
-
forward()1// reference the channel with the message you want to forward
2const channel = await chat.getChannel("support")
3
4// reference the "message" object you want to forward
5const message = await channel.getHistory({count: 1}).messages[0]
6
7// use the "forward()" method to send the message to the "incident-management" channel
8await message.forward("incident-management") -
forwardMessage()1// reference the "support" channel with the message you want to forward
2const originalChannel = await chat.getChannel("support")
3
4// reference the last message on that "support" channel
5const lastMessage = await originalChannel.getHistory({count: 1}).messages[0]
6
7// reference the "incident-management" channel to which you want to forward the message
8const newChannel = await chat.getChannel("incident-management")
9
10// use the "forwardMessage()" method to send the message to the "incident-management" channel
11await newChannel.forwardMessage(lastMessage)