Objective-CCocoaCocoaiOSCocoa Message Actions API Reference for Realtime Apps

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 PubNub Storage independently or when they fetch original messages.


Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.

Add an action on a published message. Returns the added action in the response.

To Add a Message Action you can use the following method(s) in the Cocoa SDK:

  1. ParameterTypeRequiredDescription
    requestPNAddMessageActionRequestYesAdd message action request with all information about new message action which will be passed to PubNub service.
    blockPNAddMessageActionCompletionBlockNoAdd message action request completion block.
    ParameterTypeRequiredDescription
    typeNSStringYesWhat feature this message action represents.
    Maximum 15 characters.
    valueNSStringYesValue which should be added with message action type.
    channelNSStringYesName of channel which stores the message for which action should be added.
    messageTimetokenNSNumberYesTimetoken (PubNub's high precision timestamp) of message to which action should be added.
PNAddMessageActionRequest *request = [PNAddMessageActionRequest requestWithChannel:@"chat"
                                                                  messageTimetoken:@(1234567890)];
request.type = @"reaction";
request.value = @"smile";

[self.client addMessageActionWithRequest:request completion:^(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 {
            /**
             * Handle add message action error. Check 'category' property to find out possible
             * issue because of which request did fail.
             *
             * Request can be resent using: [status retry]
             */
        }
    }
}];

Response objects which is returned by client when add message action Message Action API is used:

@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

Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.

Add an action on a published message. Returns the added action in the response.

To Add a Message Action you can use the following method(s) in the Cocoa SDK:

  1. ParameterTypeRequiredDescription
    channelNSStringYesName of channel which store message for which action should be added.
    messageTimetokenNSNumberYesTimetoken of message for which action should be added.
    typeNSStringYesWhat feature this message action represents.
    valueNSStringYesValue which should be stored along with message action.
    blockPNAddMessageActionCompletionBlockNoAdd message action request completion block.
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 {
                /**
                 * Handle add message action error. Check 'category' property to find out possible
                 * issue because of which request did fail.
                 *
                 * Request can be resent using: [status retry]
                 */
            }
        }
    });

Response objects which is returned by client when add message action Message Action API is used:

@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

Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.

Remove a peviously added action on a published message. Returns an empty response.

To Remove a Message Action you can use the following method(s) in the Cocoa SDK:

  1. ParameterTypeRequiredDescription
    request PNRemoveMessageActionRequestYesRemove message action request with information about existing message action.
    blockPNRemoveMessageActionCompletionBlockNoRemove message action request completion block.
    ParameterTypeRequiredDescription
    actionTimetokenNSNumberYesMessage action addition timetoken.
    channelNSStringYesName of channel which store message for which action should be removed.
    messageTimetokenNSNumberYesTimetoken (PubNub's high precision timestamp) of message to which action should be removed.
PNRemoveMessageActionRequest *request = [PNRemoveMessageActionRequest requestWithChannel:@"chat"
                                                                        messageTimetoken:@(1234567890)];
request.actionTimetoken = @(1234567891);

[self.client removeMessageActionWithRequest:request
                                 completion:^(PNAcknowledgmentStatus *status) {
                                 
    if (!status.isError) {
        // Message action successfully removed.
    } else {
        /**
         * Handle remove message action error. Check 'category' property to find out possible
         * issue because of which request did fail.
         *
         * Request can be resent using: [status retry]
         */
    }
}];

Response objects which is returned by client when remove message action Message Action API is used:

@interface PNErrorData : PNServiceData

// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;

@end


@interface PNAcknowledgmentStatus : PNErrorStatus

// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;

// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;

@end

Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.

Remove a peviously added action on a published message. Returns an empty response.

  1. ParameterTypeRequiredDescription
    channelNSStringYesName of channel which store message for which action should be removed.
    messageTimetokenNSNumberYesTimetoken of message for which action should be removed.
    actionTimetokenNSNumberYesAction addition timetoken.
    blockPNRemoveMessageActionCompletionBlockNoRemove message action request completion block.
self.client.removeMessageAction()
    .channel("chat")
    .messageTimetoken(@(1234567890))
    .actionTimetoken(@(1234567891))
    .performWithCompletion(^(PNCreateSpaceStatus *status) {
        if (!status.isError) {
            // Message action successfully removed.
        } else {
            /**
             * Handle remove message action error. Check 'category' property to find out possible
             * issue because of which request did fail.
             *
             * Request can be resent using: [status retry]
             */
        }
    });

Response objects which is returned by client when remove message action Message Action API is used:

@interface PNErrorData : PNServiceData

// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;

@end


@interface PNAcknowledgmentStatus : PNErrorStatus

// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;

// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;

@end

Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.

Get a list of message actions in a channel. Returns a list of actions in the response.

To Get Message Actions you can use the following method(s) in the Cocoa SDK:

  1. ParameterTypeRequiredDescription
    request PNFetchMessageActionsRequestYesFetch message actions request with all information which should be used to fetch existing messages actions.
    blockPNFetchMessageActionsCompletionBlockYesFetch message actions request completion block.
    ParameterTypeRequiredDescription
    startNSNumberYesReturn values will be less than start.
    endNSNumberYesReturn values will be greater than or equal to end.
    limitNSUIntegerYesNumber of messages actions to return in response.
    channelNSStringYesName of channel from which list of message actions should be retrieved.
PNFetchMessageActionsRequest *request = [PNFetchMessageActionsRequest requestWithChannel:@"chat"];
request.start = @(1234567891);
request.limit = 200;

[self.client fetchMessageActionsWithRequest:request
                                 completion:^(PNFetchMessageActionsResult *result,
                                              PNErrorStatus *status) {
                                              
    if (!status.isError) {
        /**
         * Message actions successfully fetched.
         * Result object has following information:
         *     result.data.actions - list of message action instances
         *     result.data.start - fetched messages actions time range start (oldest message
         *         action timetoken).
         *     result.data.end - fetched messages actions time range end (newest action timetoken).
         */
    } else {
        /**
         * Handle fetch message actions error. Check 'category' property to find out possible
         * issue because of which request did fail.
         *
         * Request can be resent using: [status retry]
         */
    }
}];

Response objects which is returned by client when fetch message actions Message Action API is used:

@interface PNFetchMessageActionsData : PNServiceData

// List of fetched messages actions.
@property (nonatomic, readonly, strong) NSArray<PNMessageAction *> *actions;

/**
 * Fetched messages actions time range start (oldest message action timetoken).
 *
 * This timetoken can be used as 'start' value to fetch older messages actions.
 */
@property (nonatomic, readonly, strong) NSNumber *start;

// Fetched messages actions time range end (newest action timetoken).
@property (nonatomic, readonly, strong) NSNumber *end;

@end
 
 
@interface PNFetchMessageActionsResult : PNResult

// Fetch message actions request processed information.
@property (nonatomic, readonly, strong) PNFetchMessageActionsData *data;

@end

Error resonse which is used in case of Message Action API call failure:

@interface PNErrorData : PNServiceData

// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;

@end

 
@interface PNErrorStatus : PNStatus

// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;

// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;

@end

Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.

Get a list of message actions in a channel. Returns a list of actions in the response.

To Get Message Actions you can use the following method(s) in the Cocoa SDK:

  1. ParameterTypeRequiredDescription
    channelNSStringYesName of channel from which list of messages actions should be retrieved.
    startNSNumberNoMessage action timetoken denoting the start of the range requested.
    Return values will be less than start.
    endNSNumberNoMessage action timetoken denoting the end of the range requested.
    Return values will be greater than or equal to end.
    limitNSUIntegerNoNumber of message actions to return in response.
    blockPNFetchMessageActionsCompletionBlockYesFetch message actions request completion block.
self.client.fetchMessageActions()
    .channel(@"chat")
    .start(@(1234567891))
    .limit(200)
    .performWithCompletion(^(PNFetchMessageActionsResult *result,
                             NErrorStatus *status) {
      
        if (!status.isError) {
            /**
             * Message action successfully added.
             * Result object has following information:
             *     result.data.actions - list of message action instances
             *     result.data.start - fetched messages actions time range start (oldest message
             *         action timetoken).
             *     result.data.end - fetched messages actions time range end (newest action timetoken).
             */
        } else {
            /**
             * Handle fetch message actions error. Check 'category' property to find out possible
             * issue because of which request did fail.
             *
             * Request can be resent using: [status retry]
             */
        }
    });

Response objects which is returned by client when fetch message actions Message Action API is used:

@interface PNFetchMessageActionsData : PNServiceData

// List of fetched messages actions.
@property (nonatomic, readonly, strong) NSArray<PNMessageAction *> *actions;

/**
 * Fetched messages actions time range start (oldest message action timetoken).
 *
 * This timetoken can be used as 'start' value to fetch older messages actions.
 */
@property (nonatomic, readonly, strong) NSNumber *start;

// Fetched messages actions time range end (newest action timetoken).
@property (nonatomic, readonly, strong) NSNumber *end;

@end
 
 
@interface PNFetchMessageActionsResult : PNResult

// Fetch message actions request processed information.
@property (nonatomic, readonly, strong) PNFetchMessageActionsData *data;

@end

Error resonse which is used in case of Message Action API call failure:

@interface PNErrorData : PNServiceData

// Stringified error information.
@property (nonatomic, readonly, strong) NSString *information;

@end

 
@interface PNErrorStatus : PNStatus

// Whether status object represent error or not.
@property (nonatomic, readonly, assign, getter = isError) BOOL error;

// Additional information related to error status object.
@property (nonatomic, readonly, strong) PNErrorData *errorData;

@end