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(channelId: String): PNFuture<PNPublishResult> -
forwardMessage()1channel.forwardMessage(message: Message): PNFuture<PNPublishResult>
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 |
|---|---|
PNFuture<PNPublishResult> | PNFuture containing the PNPublishResult that contains timetoken of the forwarded message. |
Sample code
Forward the latest message from the support channel to the incident-management channel.
-
forward()
show all 23 lines1val supportChannel: Channel
2// ...
3
4supportChannel.getHistory(count = 1).async { historyResult ->
5 historyResult.onSuccess { history ->
6 // handle success
7 val latestMessage = history.messages.firstOrNull()
8
9 if (latestMessage != null) {
10 latestMessage.forward("incident-management").async { forwardResult ->
11 forwardResult.onSuccess {
12 // handle success
13 }.onFailure {
14 // handle failure
15 } -
forwardMessage()
show all 27 lines1val supportChannel: Channel
2// ...
3
4supportChannel.getHistory(count = 1).async { historyResult ->
5 historyResult.onSuccess { history ->
6 // handle success
7 val latestMessage = history.messages.firstOrNull()
8 if (latestMessage != null) {
9 chat.getChannel("incident-management").async { incidentResult ->
10 incidentResult.onSuccess { incidentChannel ->
11 // handle success
12 incidentChannel?.forwardMessage(latestMessage)?.async { forwardResult ->
13 forwardResult.onSuccess {
14 // handle success
15 }.onFailure {