Message Actions API for PubNub Cocoa Swift SDK
This SDK has been replaced by a new PubNub Swift SDK written purely in Swift. Check it out here
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.
Add Message Action
Requires Message Persistence add-on Requires that the Message Persistence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
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:
open func addMessageAction(with: PNAddMessageActionRequest, completion: PNAddMessageActionCompletionBlock?)
Parameter Type Required Description request
PNAddMessageActionRequest Yes Add message action
request with all information about newmessage action
which will be passed to PubNub service.closure
PNAddMessageActionCompletionBlock No Add message action
request completionclosure
.
PNAddMessageActionRequest
Parameter | Type | Required | Description |
---|---|---|---|
type | String | Yes | What feature this message action represents. Maximum 15 characters. |
value | String | Yes | Value which should be added with message action type. |
channel | String | Yes | Name of channel which stores the message for which action should be added. |
messageTimetoken | NSNumber | Yes | Timetoken (PubNub's high precision timestamp) of message to which action should be added. |
Basic Usage
let request = PNAddMessageActionRequest(channel: "chat", messageTimetoken: 1234567890)
request.type = "reaction"
request.value = "smile"
self.client.addMessageAction(with: request, completion: { status in
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
Response objects which is returned by client when add message action
Message Action API is used:
open class PNAddMessageActionData : PNServiceData {
// Added message action.
open var action: PNMessageAction? { get }
}
open class PNAddMessageActionStatus : PNAcknowledgmentStatus {
// Add message action request processed information.
open var data: PNAddMessageActionData { get }
}
Add Message Action (Builder Pattern)
Requires Message Persistence add-on Requires that the Message Persistence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
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:
addMessageAction().channel(String).messageTimetoken(NSNumber).type(String).value(String).performWithCompletion(PNAddMessageActionCompletionBlock?)
Parameter Type Required Description channel
String Yes Name of channel which store message for which action
should be added.messageTimetoken
NSNumber Yes Timetoken of message for which action
should be added.type
String Yes What feature this message action
represents.value
String Yes Value which should be stored along with message action
.closure
PNAddMessageActionCompletionBlock No Add message action
request completionclosure
.
Basic Usage
self.client.addMessageAction()
.channel("chat")
.name(1234567890)
.type("reaction")
.value("smile")
.performWithCompletion({ status in
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
Response objects which is returned by client when add message action
Message Action API is used:
open class PNAddMessageActionData : PNServiceData {
// Added message action.
open var action: PNMessageAction? { get }
}
open class PNAddMessageActionStatus : PNAcknowledgmentStatus {
// Add message action request processed information.
open var data: PNAddMessageActionData { get }
}
Remove Message Action
Requires Message Persistence add-on Requires that the Message Persistence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Remove a peviously added action on a published message
. Returns an empty response.
Method(s)
To Remove a Message Action you can use the following method(s) in the Swift SDK:
open func removeMessageAction(with: PNRemoveMessageActionRequest, completion: PNRemoveMessageActionCompletionBlock?)
Parameter Type Required Description request
PNRemoveMessageActionRequest Yes Remove message action
request with information about existingmessage action
.closure
PNRemoveMessageActionCompletionBlock No Remove message action
request completionclosure
.
PNRemoveMessageActionRequest
Parameter | Type | Required | Description |
---|---|---|---|
actionTimetoken | NSNumber | Yes | Message action addition timetoken. |
channel | NSString | Yes | Name of channel which store message for which action should be removed. |
messageTimetoken | NSNumber | Yes | Timetoken (PubNub's high precision timestamp) of message to which action should be removed. |
Basic Usage
let request = PNRemoveMessageActionRequest(channel: "chat", messageTimetoken: 1234567890)
request.actionTimetoken = 1234567891
self.client.removeMessageAction(with: request, completion: { status in
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
Response objects which is returned by client when remove message action
Message Action API is used:
open class PNErrorData : PNServiceData {
// Stringified error information.
open var information: String { get }
}
open class PNAcknowledgmentStatus : PNErrorStatus {
// Whether status object represent error or not.
open var isError: Bool { get }
// Additional information related to error status object.
open var data: PNErrorData { get }
}
Remove Message Action (Builder Pattern)
Requires Message Persistence add-on Requires that the Message Persistence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Remove a peviously added action on a published message
. Returns an empty response.
Method(s)
removeMessageAction().channel(String).messageTimetoken(NSNumber).actionTimetoken(NSNumber).performWithCompletion(PNRemoveMessageActionCompletionBlock?)
Parameter Type Required Description channel
String Yes Name of channel which store message for which action
should be removed.messageTimetoken
NSNumber Yes Timetoken of message for which action
should be removed.actionTimetoken
NSNumber Yes Action
addition timetoken.closure
PNCreateSpaceCompletionBlock No Remove message action
request completionclosure
.
Basic Usage
self.client.removeMessageAction()
.channel("channel")
.messageTimetoken(1234567890)
.actionTimetoken(1234567891)
.performWithCompletion({ status in
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
Response objects which is returned by client when remove message action
Message Action API is used:
open class PNErrorData : PNServiceData {
// Stringified error information.
open var information: String { get }
}
open class PNAcknowledgmentStatus : PNErrorStatus {
// Whether status object represent error or not.
open var isError: Bool { get }
// Additional information related to error status object.
open var data: PNErrorData { get }
}
Get Message Actions
Requires Message Persistence add-on Requires that the Message Persistence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Get a list of message actions in a channel
. Returns a list of actions sorted by the action's timetoken in ascending order.
Method(s)
To Get Message Actions you can use the following method(s) in the Swift SDK:
open func fetchMessageActions(with: PNFetchMessageActionsRequest, completion: PNFetchMessageActionsCompletionBlock)
Parameter Type Required Description request
PNFetchMessageActionsRequest Yes Fetch message actions
request with all information which should be used to fetch existingmessages actions
.closure
PNFetchMessageActionsCompletionBlock Yes Fetch message actions
request completionclosure
.
PNFetchMessageActionsRequest
Parameter | Type | Required | Description |
---|---|---|---|
start | NSNumber | Yes | Return values will be less than start . |
end | NSNumber | Yes | Return values will be greater than or equal to end . |
limit | UInt | Yes | Number of messages actions to return in response. |
channel | String | Yes | Name of channel from which list of message actions should be retrieved. |
Basic Usage
self.client.fetchMessageActions()
.channel("chat")
.start(1234567891)
.limit(200)
.performWithCompletion({ (result, status) in
if !(status?.isError ?? false) {
/**
* 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
Response objects which is returned by client when fetch message actions
Message Action API is used:
open class PNFetchMessageActionsData : PNServiceData {
// List of fetched messages actions.
open var actions: [PNMessageAction] { get }
/**
* Fetched messages actions time range start (oldest message action timetoken).
*
* This timetoken can be used as 'start' value to fetch older messages actions.
*/
open var start: NSNumber { get }
// Fetched messages actions time range end (newest action timetoken).
open var end: NSNumber { get }
}
open class PNFetchMessageActionsResult : PNResult {
// Fetch message actions request processed information.
open var data: PNFetchMessageActionsData { get }
}
Error response which is used in case of Message Action API call failure:
open class PNErrorData : PNServiceData {
// Stringified error information.
open var information: String { get }
}
open class PNErrorStatus : PNStatus {
// Whether status object represent error or not.
open var isError: Bool { get }
// Additional information related to error status object.
open var data: PNErrorData { get }
}
Get Message Actions (Builder Pattern)
Requires Message Persistence add-on Requires that the Message Persistence add-on is enabled for your key. See this page on enabling add-on features on your keys:
https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-
Description
Get a list of message actions in a channel
. Returns a list of actions sorted by the action's timetoken in ascending order.
Method(s)
To Get Message Actions you can use the following method(s) in the Swift SDK:
fetchMessageActions().channel(String).start(NSNumber).end(NSNumber).limit(UInt).performWithCompletion(PNFetchMessageActionsCompletionBlock)
Parameter Type Required Description channel
String Yes Name of channel from which list of messages actions
should be retrieved.start
NSNumber No Message action
timetoken denoting the start of the range requested. Return values will be less than start.end
NSNumber No Message action
timetoken denoting the end of the range requested. Return values will be greater than or equal to end.limit
UInt No Number of message actions
to return in response.closure
PNFetchMessageActionsCompletionBlock Yes Fetch message actions
request completionclosure
.
Basic Usage
self.client.fetchMessageActions()
.channel("chat")
.start(1234567891)
.limit(200)
.performWithCompletion({ (result, status) in
if !(status?.isError ?? false) {
/**
* 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
Response objects which is returned by client when fetch message actions
Message Action API is used:
open class PNFetchMessageActionsData : PNServiceData {
// List of fetched messages actions.
open var actions: [PNMessageAction] { get }
/**
* Fetched messages actions time range start (oldest message action timetoken).
*
* This timetoken can be used as 'start' value to fetch older messages actions.
*/
open var start: NSNumber { get }
// Fetched messages actions time range end (newest action timetoken).
open var end: NSNumber { get }
}
open class PNFetchMessageActionsResult : PNResult {
// Fetch message actions request processed information.
open var data: PNFetchMessageActionsData { get }
}
Error response which is used in case of Message Action API call failure:
open class PNErrorData : PNServiceData {
// Stringified error information.
open var information: String { get }
}
open class PNErrorStatus : PNStatus {
// Whether status object represent error or not.
open var isError: Bool { get }
// Additional information related to error status object.
open var data: PNErrorData { get }
}