Send a report every week
Say someone pulls last week’s numbers every Monday morning and pastes them into Slack. Here’s how to make that a script that runs on a schedule.
1. Save the Slack token
Section titled “1. Save the Slack token”A workspace owner or admin saves a Slack bot token that may post
messages (chat:write), sendable only to slack.com:
printf %s "$SLACK_BOT_TOKEN" | reminix secrets set SLACK_TOKEN --hosts slack.com2. Write the script
Section titled “2. Write the script”{ "slug": "weekly-revenue", "name": "Weekly revenue", "entry": "index.ts", "hosts": ["slack.com", "api.stripe.com"], "secrets": { "SLACK_TOKEN": { "host": "slack.com", "header": "Authorization", "value": "Bearer {secret}" }, "STRIPE_KEY": { "host": "api.stripe.com", "header": "Authorization", "value": "Bearer {secret}" } }, "inputSchema": { "type": "object", "required": ["channel"], "properties": { "channel": { "type": "string", "title": "Slack channel" } } }}export default async function run(inputs: { channel: string }, ctx) { const total = await lastWeeksRevenue(); // your query, through api.stripe.com ctx.log(`last week: ${total}`);
const res = await fetch("https://slack.com/api/chat.postMessage", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ channel: inputs.channel, text: `Revenue last week: ${total}`, }), }); const answer = await res.json(); if (!answer.ok) throw new Error(`Slack: ${answer.error}`); return { posted: true, total };}Publish it, and run it once by hand to check the message:
reminix scripts publish ./weekly-revenue --publishreminix scripts run weekly-revenue --input '{"channel":"#revenue"}' --log3. Add the schedule
Section titled “3. Add the schedule”On the script’s page, choose Schedules → Add schedule: every
Monday at 9:00, in your timezone, with #revenue as the channel. Or
through the API:
curl -X POST https://api.reminix.com/v1/scripts/weekly-revenue/schedules \ -H "Authorization: Bearer $REMINIX_TOKEN" -H "X-Workspace: acme" \ -H "Content-Type: application/json" \ -d '{ "name": "Monday mornings", "cron": "0 9 * * 1", "timezone": "Europe/London", "inputs": { "channel": "#revenue" } }'The schedule runs as you, with your access. Each run is on the script’s page, marked Schedule. If a time is skipped, for example because the plan’s runs for the month are used up, the schedule’s card says why.
4. Hear about it when it fails
Section titled “4. Hear about it when it fails”Add a trigger on this script’s run.failed. See
Alert when a run fails.
Related: Schedules and triggers, Secrets.