How to delete message replies using Slack API?

Viewed 1026

I'm getting an error when I try to use Slack API to remove the replies saying the channel doesn't exists.

To validate it, I'm calling the:

https://slack.com/api/channels.history?token={token}&channel={channel}&count=1&inclusive=true&latest={ts}&oldest={ts}

Then I get the message back.

The message I'm getting back is this one:

{
    "ok": true,
    "latest": "1540555927.024300",
    "oldest": "1540555927.024300",
    "messages": [
        {
            "text": "This message was deleted.",
            "edited": {
                "user": "UD6SLKGEP",
                "ts": "1540555928.000000"
            },
            "type": "message",
            "subtype": "tombstone",
            "user": "USLACKBOT",
            "hidden": true,
            "thread_ts": "1540555927.024300",
            "reply_count": 1,
            "replies": [
                {
                    "user": "UD6SLKGEP",
                    "ts": "1540555928.024401"
                }
            ],
            "subscribed": false,
            "unread_count": 1,
            "ts": "1540555927.024300"
        }
    ],
    "has_more": false,
    "is_limited": true
}

As you can see, there is this "This message was deleted." that seems to be generated automatically and keep showing up because I still have replies associated to it.

If I call the same endpoint passing the reply ts (1540555928.024401), for the same channel I get this:

{
    "ok": true,
    "latest": "1540555928.024401",
    "oldest": "1540555928.024401",
    "messages": [
        {
            "type": "message",
            "user": "UD6SLKGEP",
            "text": "45d7bc14a6fa03 23456789 abcdefghijklmnop",
            "bot_id": "BD6AJUY8G",
            "thread_ts": "1540555927.024300",
            "ts": "1540555928.024401"
        }
    ],
    "has_more": false,
    "is_limited": true
}

Which means that there is a message there, which is a reply from another message.

The problem starts when I try to remove this reply message.

I call this endpoint:

https://slack.com/api/chat.delete?token={token}

Passing the channel and the reply ts as the payload:

{
    "channel": "CD65XB2D7",
    "message_ts": "1540555928.024401"
}

Now instead of having the message removed, I get this response:

{
    "ok": false,
    "error": "channel_not_found",
    "warning": "missing_charset",
    "response_metadata": {
        "warnings": [
            "missing_charset"
        ]
    }
}

But the channel exists and I'm using it to remove other messages as well. That happens when I try to remove the reply from a message only.

Is there something special about removing reply messages?

1 Answers
Related