Remove message actions
This guide shows you how to remove a previously added message action from a message.
- Remove an action using its own action timetoken and the target message's timetoken.
- Confirm the removal from the empty response PubNub returns.
- Recognize the status code that means the action was deleted but its event wasn't published.
Every call on this page needs an SDK instance initialized with your publish key, the target message's timetoken, and the action's own timetoken. That last value is what adding the action returned, or one you looked up with Retrieve historical message actions. Examples use the JavaScript, Swift, Java, Kotlin, C#, Python, and Objective-C SDKs. For any other language, refer to Available SDKs.
Before removing a message action, confirm the prerequisites are in place.
Remove an action
Call the remove-action method with the channel, the message's timetoken, and the action's own timetoken.
- JavaScript
- Swift
- Java
- Kotlin
- C#
- Python
- Objective-C
1await pubnub.removeMessageAction({
2 channel: 'chats.room1',
3 messageTimetoken: '15610547826969050',
4 actionTimetoken: '15610547826970050',
5});
1pubnub.removeMessageActions(
2 channel: "chats.room1",
3 message: 15610547826969050,
4 action: 15610547826970050
5) { result in
6 switch result {
7 case .success:
8 print("Action removed")
9 case let .failure(error):
10 print("failed: \(error.localizedDescription)")
11 }
12}
1pubnub.removeMessageAction()
2 .channel("chats.room1")
3 .messageTimetoken(15610547826969050L)
4 .actionTimetoken(15610547826970050L)
5 .async(result -> { /* check result */ });
1pubnub.removeMessageAction(
2 channel = "chats.room1",
3 messageTimetoken = 15610547826969050L,
4 actionTimetoken = 15610547826970050L
5).async { result -> /* check result */ }
1pubnub.RemoveMessageAction()
2 .Channel("chats.room1")
3 .MessageTimetoken(15610547826969050)
4 .ActionTimetoken(15610547826970050)
5 .Uuid("user-456")
6 .Execute(new PNRemoveMessageActionResultExt((result, status) => {
7 if (status != null && status.Error) {
8 Console.WriteLine(status.ErrorData.Information);
9 }
10 }));
C#'s RemoveMessageAction() also needs Uuid(), the publisher of the action being removed, returned as uuid when the action was added.
1def remove_action_callback(result, status):
2 if status.is_error():
3 print(status.error_data.information)
4 else:
5 print("Action removed")
6
7pubnub.remove_message_action() \
8 .channel("chats.room1") \
9 .message_timetoken(15610547826969050) \
10 .action_timetoken(15610547826970050) \
11 .pn_async(remove_action_callback)
1PNRemoveMessageActionRequest *request =
2 [PNRemoveMessageActionRequest requestWithChannel:@"chats.room1"
3 messageTimetoken:@15610547826969050];
4request.actionTimetoken = @15610547826970050;
5
6[self.client removeMessageActionWithRequest:request completion:^(PNAcknowledgmentStatus *status) {
7 if (!status.isError) {
8 NSLog(@"Action removed");
9 }
10}];
Confirm the removal
A successful call returns an empty response. There's nothing to roll back on the message itself, only the action record to delete, so PubNub has nothing else to report back.
A 207 status means PubNub deleted the action but couldn't publish the deletion event to subscribers. Treat the action as removed. A client that fetches historical message actions for this channel afterward won't see it either, even though no live event announced the removal.
Related tasks
- Message Actions in PubNub. The type/value model, the event model, and the Message Persistence requirement.
- Add message actions. Attach the action, and get the
actionTimetokenthis call needs. - Receive message actions. Handle the event this call generates on a live subscription.
- Retrieve historical message actions. Look up an
actionTimetokenyou didn't keep from the add call. - Delete messages. Remove the message itself instead of just an action attached to it.