import { WebClient } from "@slack/web-api"
/**
* Create Reminder
* 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.
*/
export async function main(
auth: RT.Slack,
text: string,
time: string,
recurrence?: {
frequency: "daily" | "weekly" | "monthly" | "yearly"
weekdays?: string[]
}
) {
const client = new WebClient(auth.token)
return await client.reminders.add(
dropEmpty({ text, time, recurrence }) as any
)
}
function dropEmpty<T extends { [key: string]: any }>(params: T) {
return Object.fromEntries(
Object.entries(params).filter(
([, v]) => v !== undefined && v !== null && v !== ""
)
) as T
}
Submitted by hugo989 2 hours ago