Message Actions API for Swift Native SDK
Add or remove actions on published messages to build features like receipts, reactions, or to associate custom metadata to messages. Clients can subscribe to a channel to receive message action events on that channel. They can also fetch past message actions from Message Persistence independently or when they fetch original messages.
Message Actions vs. Message Reactions
Message Actions is the flexible, low-level API for adding any metadata to messages (read receipts, delivery confirmations, custom data), while Message Reactions specifically refers to using Message Actions for emoji/social reactions.
In PubNub Core and Chat SDKs, the same underlying Message Actions API is referred to as Message Reactions when used for emoji reactions - it's the same functionality, just different terminology depending on the use case.
Add Message Action
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal.
Add an action on a published message
. Returns the added action in the response.
Method(s)
To Add a Message Action you can use the following method(s) in the Swift SDK:
func addMessageAction(
channel: String,
type actionType: String,
value: String,
messageTimetoken: Timetoken,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: ((Result<PubNubMessageAction, Error>) -> Void)?
)
Parameter | Description |
---|---|
channel *Type: String Default: n/a | The name of the channel |
type *Type: String Default: n/a | The Message Action's type |
value *Type: String Default: n/a | The Message Action's value |
messageTimetoken *Type: Timetoken Default: n/a | The publish timetoken of a parent message. |
custom Default: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completion Type: ((Result<PubNubMessageAction, Error>) -> Void)? Default: nil | The async Result of the method call. |
Completion Handler Result
Success
The PubNubMessageAction
that was added.
public protocol PubNubMessageAction {
/// The type of action
var actionType: String { get }
/// The value that corresponds to the type
var actionValue: String { get }
/// The `Timetoken` for this specific action
var actionTimetoken: Timetoken { get }
/// The `Timetoken` for the message this action relates to
var messageTimetoken: Timetoken { get }
/// The publisher of the message action
show all 20 linesFailure
An Error
describing the failure.
Basic Usage
Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
Remove Message Action
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal.
Remove a previously added action on a published message.
Method(s)
To Remove a Message Action you can use the following method(s) in the Swift SDK:
func removeMessageActions(
channel: String,
message timetoken: Timetoken,
action actionTimetoken: Timetoken,
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: ((Result<(channel: String, message: Timetoken, action: Timetoken), Error>) -> Void)?
)
Parameter | Description |
---|---|
channel *Type: String Default: n/a | The name of the channel. |
message *Type: Timetoken Default: n/a | The publish timetoken of a parent message. |
action *Type: Timetoken Default: n/a | The action timetoken of a message action to be removed. |
custom Type: RequestConfiguration Default: RequestConfiguration() | An object that allows for per-request customization of PubNub Configuration or Network Session |
completion Type: ((Result<(channel: String, message: Timetoken, action: Timetoken), Error>) -> Void)? Default: nil | The async Result of the method call |
Completion Handler Result
Success
A Tuple
containing the channel, message Timetoken
, and action Timetoken
of the action that was removed.
Failure
An Error
describing the failure.
Basic Usage
Get Message Actions
Requires Message Persistence
This method requires that Message Persistence is enabled for your key in the Admin Portal.
Get a list of message actions in a channel
. Returns a list of actions sorted by the action's timetoken in ascending order.
Truncated response
Number of message actions in the response may be truncated when internal limits are hit. If the response is truncated, a more
property will be returned with additional parameters. Send iterative calls to Message Persistence adjusting the parameters to fetch more message actions.
Method(s)
To Get Message Actions you can use the following method(s) in the Swift SDK:
func fetchMessageActions(
channel: String,
page: PubNubBoundedPage? = PubNubBoundedPageBase(),
custom requestConfig: PubNub.RequestConfiguration = PubNub.RequestConfiguration(),
completion: ((Result<(actions: [PubNubMessageAction], next: PubNubBoundedPage?), Error>) -> Void)?
)
Parameter | Description |
---|---|
channel *Type: String Default: n/a | The name of the channel. |
page Type: PubNubBoundedPage? Default: PubNubBoundedPageBase() | The paging object used for pagination. It allows you to specify a range of messages to retrieve based on specific time bounds. |
custom Default: PubNub.RequestConfiguration() | An object that allows for per-request customization of PubNub configuration or network session. For more information, refer to the Request Configuration section. |
completion Type: ((Result<(channel: String, message: Timetoken, action: Timetoken), Error>) -> Void)? Default: nil | The async Result of the method call. |
Completion Handler Result
Success
An Array
of PubNubMessageAction
for the request channel, and the next request PubNubBoundedPage
(if one exists).
public protocol PubNubMessageAction {
/// The type of action
var actionType: String { get }
/// The value that corresponds to the type
var actionValue: String { get }
/// The `Timetoken` for this specific action
var actionTimetoken: Timetoken { get }
/// The `Timetoken` for the message this action relates to
var messageTimetoken: Timetoken { get }
/// The publisher of the message action
show all 20 linespublic protocol PubNubBoundedPage {
/// The start value for the next set of remote data
var start: Timetoken? { get }
/// The bounded end value that will be eventually fetched to
var end: Timetoken? { get }
/// The previous limiting value (if any)
var limit: Int? { get }
}
Failure
An Error
describing the failure.
Basic Usage