62

I need to send a message in slack at a time set in advance.

Is there a way to do it through the Slack API or do I need to have a script running and checking if it's time to send the message and then send it?

LLL
  • 3,566
  • 2
  • 25
  • 44

5 Answers5

57

You should be able to create a reminder sending a message to @slackbot The message should be like:

/remind [@someone or #channel] [what] [when]

Here's some examples:

/remind @username to do something in 24 hours

or:

/remind @username to do something at 16:00
plombix
  • 396
  • 3
  • 13
Afas
  • 806
  • 1
  • 6
  • 11
  • 32
    thanks, but reminder is not a message. message can be formatted. – LLL Jun 21 '17 at 20:32
  • 2
    @LLL You can format the message... `/remind @channel *Remember* to _listen_ to the radio in 2 hours` – dotnetCarpenter Jun 28 '18 at 01:46
  • what I meant by format at the time was add attachments. So pretty much send a message you would be able to send through the messaging api but at a set time in advance. – LLL Jun 28 '18 at 08:16
23

You can use this free Slack application to send scheduled and self-destruct messages. https://timy.website

  1. Sending a scheduled message

/send Happy birthday at 12am

/send Happy birthday in 1h30m

  1. Sending a self-destruct message

/delete Secret message! at 2pm

/delete Secret message! in 3h

You can find more details on the website.

Thusitha
  • 3,393
  • 3
  • 21
  • 33
  • 9
    Nice, thanks for creating this :)! By the way, why is the maximum schedule time 24h? It would be great to schedule a message during Friday night for Monday morning to a colleague who does not want to be disturbed during the weekend (so 72h max would be great). Another thing I was thinking - don't you think the commands are a bit too generic and might collide with other Slack bots? Maybe namespace them? Not sure about this though... Anyway, really great job! – mrts Oct 28 '18 at 20:02
  • They have a free and non-free option. I assume the 24h limit is a way to differentiate. – Alwyn Schoeman Apr 01 '20 at 20:02
20

If you just want to send a short message to a user at a given time you can use the build-in reminder. The reminder.add method allows you to specify a date, time, message text and the user to receive the message.

The reminder message will appear in the "Slackbot" channel of the addressed user.

Here is an example on how it would look like: enter image description here

Update April 2019:

There is now a new API method that allows you to submit message for later sending. Its called chat.scheduleMessage.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • I want to post messages to a channel, they are not repeating, basically saying that a scheduled event is starting and/or ending now without any other triggers besides the time. Would be nice to have some formatting on them as well. Is the reminder still good for that? – LLL Jan 31 '17 at 11:24
  • 1
    yes, the reminder works for non repeating messages. The usual message formatting also works, so you can have bold text etc. No attachments though. Whats also nice about this is, that the user can snooze the reminder. I'll add an example in my answer. – Erik Kalkoken Jan 31 '17 at 11:34
  • Is it possible to not have the whole reminder thing though? Like remove the 'you asked me to remind you' and mark as complete part and just have a message with red or green on the side that says something along the lines of 'Scheduled maintenance of server blah starting/ ending' – LLL Jan 31 '17 at 11:40
  • 1
    No, I don't believe that is possible. If you want a fully custom user interface you will need to build your own reminder service. Then you will also need to setup your own scheduler (e.g. cron) to ensure messages are send at the right time. – Erik Kalkoken Jan 31 '17 at 11:50
  • Thanks, I'll have to look for a scheduler then. Unrelated to the OP, but know any lightweight free ones for .net? – LLL Jan 31 '17 at 11:53
  • 2
    I can recommend using a web cron tool. Since your service needs to be accessible from the Web anyway for Slack, that works pretty well. This is the cron web site I am using for all my bots. Its free and reliable. https://cron-job.org/en/ – Erik Kalkoken Jan 31 '17 at 11:57
  • 1
    Thanks, I'll look into it. – LLL Jan 31 '17 at 11:59
3

You can use the official slack api at endpoint chat.postMessage with a key post_at to have your message scheduled. More information in official slack documentation https://api.slack.com/messaging/scheduling. You can also use 3rd party applications, which are free most of the time, for example https://thetopchat.com/ and schedule your message with commands like, for example:

/delay in 3 hours {your message here}

or

/schedule tomorrow at 3pm {your message here}
Ivan Hanák
  • 2,214
  • 1
  • 16
  • 25
1

The Slack API now provides a dedicated endpoint for that. You will need the chat:write scope and the docs say:

Schedules a message to be sent to a channel.

I just implemented it and works as expected.

You can check the docs here: chat.scheduleMessage

Bruno Paulino
  • 5,611
  • 1
  • 41
  • 40