Skip to content

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.

A workspace owner or admin saves a Slack bot token that may post messages (chat:write), sendable only to slack.com:

Terminal window
printf %s "$SLACK_BOT_TOKEN" | reminix secrets set SLACK_TOKEN --hosts slack.com
{
"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:

Terminal window
reminix scripts publish ./weekly-revenue --publish
reminix scripts run weekly-revenue --input '{"channel":"#revenue"}' --log

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:

Terminal window
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.

Add a trigger on this script’s run.failed. See Alert when a run fails.

Related: Schedules and triggers, Secrets.