Message Actions API for Objective-C SDK
Use message actions to add or remove metadata on published messages. Common uses include receipts and reactions. Clients subscribe to a channel to receive message action events. Clients can also fetch past message actions from Message Persistence, either on demand or when fetching original messages.
Reactions
"Message Reactions" is a specific application of the Message Actions API for emoji or social reactions.
Add message action
Requires Message Persistence
Enable Message Persistence for your key in the Admin Portal as described in the support article.
Add an action to a published message. The response includes the added action.
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.
Method(s)
Use this Objective-C method:
- (void)addMessageActionWithRequest:(PNAddMessageActionRequest *)request
completion:(nullable PNAddMessageActionCompletionBlock)block;
Parameter | Description |
---|---|
request * | Request containing the message action details. |
block Type: PNAddMessageActionCompletionBlock | Completion block. |
PNAddMessageActionRequest
Parameter | Description |
---|---|
type *Type: NSString | Message action type. Maximum 15 characters. |
value *Type: NSString | Message action value. |
channel *Type: NSString | Channel name of the target message. |
messageTimetoken *Type: NSNumber | Timetoken of the target message. |
Sample code
// Basic configuration
PNConfiguration *config = [PNConfiguration configurationWithPublishKey:@"demo"
subscribeKey:@"demo"
userID:@"actionUser"];
// Create a PubNub client instance
PubNub *client = [PubNub clientWithConfiguration:config];
// Add listener for PubNub events
[client addListener:self];
// Create a request object for adding a message action
PNAddMessageActionRequest *request = [PNAddMessageActionRequest requestWithChannel:@"chat"
messageTimetoken:@(17457898826964534)];
show all 55 linesResponse
@interface PNAddMessageActionData : PNServiceData
// Added message action.
@property (nonatomic, nullable, readonly, strong) PNMessageAction *action;
@end
@interface PNAddMessageActionStatus : PNAcknowledgmentStatus
// Add message action request processed information.
@property (nonatomic, readonly, strong) PNAddMessageActionData *data;
@end
Add message action (builder pattern)
Requires Message Persistence
Enable Message Persistence for your key in the Admin Portal as described in the support article.
Add an action to a published message. The response includes the added action.
Method(s)
Use this Objective-C method:
addMessageAction()
.channel(NSString *)
.messageTimetoken(NSNumber *)
.type(NSString *)
.value(NSString *)
.performWithCompletion(nullable PNAddMessageActionCompletionBlock);
Parameter | Description |
---|---|
channel *Type: NSString | Channel name of the target message. |
messageTimetoken *Type: NSNumber | Timetoken of the target message. |
type *Type: NSString | Message action type. |
value *Type: NSString | Message action value. |
block Type: PNAddMessageActionCompletionBlock | Completion block. |
Sample code
self.client.addMessageAction()
.channel(@"chat")
.messageTimetoken(@(1234567890))
.type(@"reaction")
.value(@"smile")
.performWithCompletion(^(PNAddMessageActionStatus *status) {
if (!status.isError) {
/**
* Message action successfully added.
* Created message action information available here: status.data.action
*/
} else {
if (status.statusCode == 207) {
// Message action has been added, but event not published.
} else {
show all 24 lines