On this page

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

ParameterRequired in forward()Required in forwardMessage()Description
channelId
Type: String
Default:
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.
message
Type: Message
Default:
n/a
No
Yes
Message object that you want to forward to the selected channel.

Output

TypeDescription
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()

    1val 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 }
    show all 23 lines
  • forwardMessage()

    1val 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 {
    show all 27 lines
Last updated on