Slack's channel history timestamp parameters

Describe the problem

I’m trying to get certain messages from a channel. The way I had it configured with HTTP node was by making a request to this URL:
https://slack.com/api/conversations.history?channel={{ $(‘get_all_messages_for_feedback’).item?.json?.channel }}&latest={{ $(‘get_all_messages_for_feedback’).item?.json?.ts }}&inclusive=true&limit=1

and setting batch to 1 item at a time. My ts in this case was 1763741692.993999

Then I decided to move all my HTTP nodes that interact with Slack to intended Slack nodes, and for this purpose I created a node, where I used Channes > History > By ID to replicate the functionality, but got a problem with configuring the Latest parameter.

I added the Latest field and tried passing the same value I passed to the previous request, but got an error.

As I later found out, in this node the Latest and Oldest fields accept values as date objects, but I would really like to use the same timestamp format I used in my HTTP request.

Is there a way to allow this?

What is the error message?

Slack error response: "invalid_ts_latest"

Please share your workflow

Share the output returned by the last node

get_all_messages_for_feedback output:

[
  {
    "ts": "1763741692.993999",
    "channel": "D09TBPS2ZJ4"
  }
]

Information on your n8n setup

  • n8n version: 2.0.2
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker

This might be not working because your passing a unix timestamp, and the node might be expecting an iso string or a standard date object. You can wrap it in a expression that would convert it or use a code node.

{{ DateTime.fromSeconds(Number($json.ts)).toJSDate() }}

Thank you for your answer!
I tried this solution, but for me it didn’t work well, because this way it tends to retrieve a message before the one I want when using the timestamp.

I ended up trying a solution like this:
{{ new Date(Math.ceil($json.ts) * 1000) }}

This works by taking slack’s timestamp (1767634872.235599), rounding it up to 1767634873, converting to milliseconds and making a Date object out of it.
This way I get message with a timestamp of 1767634872.235599 as latest

It’s not as precise as passing the timestamp directly, but given that I won’t have a case where a user sends two messages in the same second - this should work fine for me.

What still seems quite strange to me is why the node accepts a Date object, when an API that I’m calling expects a Unix timestamp

1 Like

I’m glad you figured it out! I didn’t think of the rounding!

1 Like