Skip to main content
← Back to Recipes

Post chart to Slack daily

Use a cron job or GitHub Actions to render a chart and post to Slack.

javascript
import { WebClient } from '@slack/web-api'; const res = await fetch('https://www.chart-output.com/api/v1/render', { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.CHART_OUTPUT_API_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ type: 'line', data: { labels: ['Jan','Feb','Mar'], datasets: [{ label: 'MRR', data: [12000, 15000, 18000] }] }, }), }); if (!res.ok) throw new Error(await res.text()); const chartPng = Buffer.from(await res.arrayBuffer()); const slack = new WebClient(process.env.SLACK_BOT_TOKEN); await slack.filesUploadV2({ channel_id: process.env.SLACK_CHANNEL_ID, file: chartPng, filename: 'daily-mrr.png', title: 'Daily MRR', });