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()
methods.
Both of them give the same output. The only difference is that you call a given method either directly on the message or the channel 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()
(on theMessage
object)message.forward(
channelId: String,
completion: ((Swift.Result<Timetoken, Error>) -> Void)?
) -
forward()
(on theChannel
object)channel.forward(
message: MessageImpl,
completion: ((Swift.Result<Timetoken, Error>) -> Void)? = nil
)
Input
Parameter | Type | Required for Message | Required in Channel | Default | Description |
---|---|---|---|---|---|
channelId | String | Yes | No | n/a | 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 | MessageImpl | No | Yes | n/a | MessageImpl object that you want to forward to the selected channel. |
Output
Type | Description |
---|---|
Timetoken | Timetoken of the forwarded message. |
Basic usage
Forward the latest message from the support
channel to the incident-management
channel.
-
forward()
(on theMessage
object)
show all 37 lines/// Assuming you have all necessary dependencies and a "chat" instance available
/// Fetch the "support" channel
chat?.getChannel(channelId: "support") { result in
switch result {
case let .success(channel):
if let supportChannel = channel {
print("Fetched support channel metadata with ID: \(supportChannel.id)")
/// Get the latest message from the "support" channel's history
supportChannel.getHistory(count: 1) { historyResult in
switch historyResult {
case let .success(response):
if let latestMessage = response.messages.first {
print("Latest message: \(latestMessage)")
/// Forward the latest message to the "incident-management" channel
latestMessage.forward(channelId: "incident-management") { forwardResult in -
forward()
(on theChannel
object)
show all 49 lines/// Assuming you have all necessary dependencies and a "chat" instance available
/// Fetch the "support" channel
chat?.getChannel(channelId: "support") { supportResult in
switch supportResult {
case let .success(supportChannel):
if let supportChannel = supportChannel {
print("Fetched support channel metadata with ID: \(supportChannel.id)")
/// Get the latest message from the "support" channel's history
supportChannel.getHistory(count: 1) { historyResult in
switch historyResult {
case let .success(response):
if let latestMessage = response.messages.first {
print("Latest message: \(latestMessage)")
// Fetch the "incident-management" channel
chat?.getChannel(channelId: "incident-management") { incidentResult in