Forward messages

The message forwarding feature lets you resend published messages or conversations to:

  • Share relevant information - you can forward messages or threads with additional relevant context to other users, ensuring efficient knowledge sharing.

  • Collaborate and consult - forwarding messages helps in decision-making by involving those who may have valuable insights and can contribute to ongoing discussions or projects.

You can let users send a given message from one channel to another with forward() and forwardMessage().

Both of them give the same output. The only difference is that you call a given method either directly on the message (forward()) or the channel (forwardMessage()) object. Depending on the object, these methods take different input parameters - you either have to specify the Message object you want to forward or the ID of the channel where you want to send the message.

Additional info in the forwarded message

Each forwarded message contains additional metadata: originalPublisher with the user ID of the person who originally published the message (to track its owner) and originalChannelId with the ID of the channel where the message was originally published.

Method signature

These methods take the following parameters:

  • forward()

    message.forward(channelId: String): PNFuture<PNPublishResult>
  • forwardMessage()

    channel.forwardMessage(message: Message): PNFuture<PNPublishResult>

Input

ParameterTypeRequired in forward()Required in forwardMessage()DefaultDescription
channelIdStringYesNon/aUnique 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.
messageMessageNoYesn/aMessage 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.

Basic usage

Forward the latest message from the support channel to the incident-management channel.

  • forward()

    val supportChannel: Channel
    // ...

    supportChannel.getHistory(count = 1).async { historyResult ->
    historyResult.onSuccess { history ->
    // handle success
    val latestMessage = history.messages.firstOrNull()

    if (latestMessage != null) {
    latestMessage.forward("incident-management").async { forwardResult ->
    forwardResult.onSuccess {
    // handle success
    }.onFailure {
    // handle failure
    }
    show all 23 lines
  • forwardMessage()

    val supportChannel: Channel
    // ...

    supportChannel.getHistory(count = 1).async { historyResult ->
    historyResult.onSuccess { history ->
    // handle success
    val latestMessage = history.messages.firstOrNull()
    if (latestMessage != null) {
    chat.getChannel("incident-management").async { incidentResult ->
    incidentResult.onSuccess { incidentChannel ->
    // handle success
    incidentChannel?.forwardMessage(latestMessage)?.async { forwardResult ->
    forwardResult.onSuccess {
    // handle success
    }.onFailure {
    show all 27 lines
Last updated on