Search code examples
timestampwebhooksslackslack-api

How can I get the timestamp id for a webhook in slack?


Problem: I have an external system that posts an alert to a Slack channel via an incoming webhook. The posted alert is eventually resolved and the alert posted in Slack will need to be updated. I know to update the post I need the timestamp (ts) id.

Question: Is there a way to immediately get the the timestamp (ts) id of a webhook when it is posted into a Slack channel? The way I am reading the documentation I will need to do several queries using the slack api just to get the ts id. I would prefer to get the ts immediately after posting.


Solution

  • You can get the ts of that posting immediately through Slack's Event API.

    After serup (e.g. subscribing to message.channels event) your app will receive all messages incl. the ones send through the webhook incl. their ts. Your all can then filter and listen to the correct message and react to it with an API call to modify it etc.

    Here is an example of what information your app will receive: (from the Slack documentation)

    {
        "type": "message",
        "channel": "C2147483705",
        "user": "U2147483697",
        "text": "Hello world",
        "ts": "1355517523.000005"
    }