1

I'm trying to format a date in a Slack message via the Web API. I'm using Botkit and thus my fields are being parsed with Mustache, however logs show that the correct formatting is coming out afterwards (therefore I don't think Mustache is the issue here).

The message as shown in Botkit debug logs is "... on <!date^1511407982054^{date_long_pretty} at {time}|Wednesday at 10am> ...". Other <formatting> in the message works just fine both before and after this occurrence.

I'm sure I'm at fault, but can't figure out how. Any help would be appreciated.

Slack rendering:

screenshot in Slack

Some things I've tried:

  • sending a message that only contains the date format string
  • I've been using new Date().getTime() to generate the value. Tried using new Date().getTime() * 1000 in case there was a difference there (moment.js does a * 1000 when you ask for a unix epoch number - maybe units are different).
Adam A
  • 14,469
  • 6
  • 30
  • 38
  • 1
    If you're posting the message via RTM and not `chat.postMessage`, it's possible the `<!date>` syntax is not part of the very narrow formatting options allowed when posting via RTM. – Taylor Singletary Nov 20 '17 at 19:22
  • Thanks for that. Looking closer at the library (I'm using Botkit), it uses RTM to receive messages, but unless you explicitly configure send_via_rtm, it uses the Web API for sending messages. So I'm actually using the web API. – Adam A Nov 20 '17 at 23:56

1 Answers1

2

Turns out I needed to use Math.floor(new Date().getTime() / 1000) to generate the Unix timestamp

Adam A
  • 14,469
  • 6
  • 30
  • 38