0

Create Reminder

by
Published today

Create a reminder for the connected user. Requires a user token with reminders:write.

Script slack Verified

The script

Submitted by hugo989 Bun
Verified 5 hours ago
1
import { WebClient } from "@slack/web-api"
2

3
/**
4
 * Create Reminder
5
 * Create a reminder for the connected user. `time` is a Unix timestamp (up to five years ahead), a number of seconds (within 24 hours), or natural language such as "in 15 minutes" or "every Thursday at 9am". `recurrence` repeats it, e.g. { "frequency": "weekly", "weekdays": ["monday", "friday"] }, and only works with a Unix timestamp `time` — a natural-language time like "every Monday at 9am" carries its own recurrence and fails with cannot_parse if both are given. Reminders can no longer be set for other users. Requires a user token with reminders:write.
6
 */
7
export async function main(
8
  auth: RT.Slack,
9
  text: string,
10
  time: string,
11
  recurrence?: {
12
    frequency: "daily" | "weekly" | "monthly" | "yearly"
13
    weekdays?: string[]
14
  }
15
) {
16
  const client = new WebClient(auth.token)
17
  return await client.reminders.add(
18
    dropEmpty({ text, time, recurrence }) as any
19
  )
20
}
21

22
function dropEmpty<T extends { [key: string]: any }>(params: T) {
23
  return Object.fromEntries(
24
    Object.entries(params).filter(
25
      ([, v]) => v !== undefined && v !== null && v !== ""
26
    )
27
  ) as T
28
}
29