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
) async throws -> Timetoken -
forward()
(on theChannel
object)channel.forward(
message: MessageImpl
) async throws -> Timetoken
Input
Parameter | Required for Message | Required in Channel | 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: MessageImpl Default: n/a | No | Yes | MessageImpl object that you want to forward to the selected channel. |
Output
Parameter | Description |
---|---|
Timetoken | Timetoken of the forwarded message. |
Basic usage
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Forward the latest message from the support
channel to the incident-management
channel.
-
forward()
(on theMessage
object)// Assuming you have a reference of type "ChatImpl" named "chat"
Task {
if let channel = try await chat.getChannel(channelId: "support") {
if let message = try await channel.getHistory(count: 1).messages.first {
// Forward the latest message to the "incident-management" channel
let timetoken = try await message.forward(channelId: "incident-management")
debugPrint("Message forwarded successfully with timetoken: \(timetoken)")
} else {
debugPrint("No messages found in history")
}
} else {
debugPrint("No channel found")
}
} -
forward()
(on theChannel
object)// Assuming you have a reference of type "ChatImpl" named "chat"
Task {
if let channel = try await chat.getChannel(channelId: "support") {
if let message = try await channel.getHistory(count: 1).messages.first {
if let incidentChannel = try await chat.getChannel(channelId: "incident-management") {
// Forward the latest message to the "incident-management" channel
let timetoken = try await incidentChannel.forward(message: message)
debugPrint("Message forwarded successfully with timetoken: \(timetoken)")
}
} else {
debugPrint("No messages found in history")
}
}
}