Delete Messages Older Than X Days in a Mattermost Channel
delete_old_messages.RdThis function deletes messages that are older than a specified number of days in a given Mattermost channel. It auto-paginates through all posts in the channel, filters by creation timestamp, and deletes the ones older than the specified number of days.
Usage
delete_old_messages(
channel_id,
days,
dry_run = FALSE,
pattern = NULL,
auth = get_default_auth()
)Arguments
- channel_id
Character string. The ID of the Mattermost channel from which messages should be deleted.
- days
Numeric. The age in days of the messages to be deleted.
- dry_run
Logical. When `TRUE`, returns the candidate messages with `delete_status = "DRY_RUN"` without calling `delete_post()`. Default `FALSE`.
- pattern
Optional character regex pattern. When provided, only messages whose `message` text matches `pattern` are selected for deletion.
- auth
The authentication object created by `authenticate_mattermost()`.
Value
A data frame with columns `message_id` and `delete_status`, or an empty data frame if no messages were deleted.
Examples
if (FALSE) { # \dontrun{
teams <- get_all_teams()
team_channels <- get_team_channels(team_id = teams$id[1])
channel_id <- get_channel_id_lookup(team_channels, name = "off-topic")
posts <- delete_old_messages(channel_id, 7, dry_run = TRUE)
} # }