Our great sponsors
-
telescope
A tool for tracking blogs in orbit around Seneca's open source involvement (by Seneca-CDOT)
-
Puts Debuggerer
Ruby library for improved puts debugging, automatically displaying bonus useful information such as source line number and source code.
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
Making the slack bot announce signups issue was fun to work, despite the technical difficulties with the e2e tests, when I got close to getting my PR merged. One cannot always rely on technology, as occasional downtime is inevitable.
const { logger } = require('@senecacdot/satellite'); const { App } = require('@slack/bolt'); const { SLACK_BOT_CHANNEL_ID } = process.env; const createSlackApp = () => { const { SLACK_BOT_TOKEN, SLACK_BOT_SIGNING_SECRET } = process.env; if (!(SLACK_BOT_TOKEN && SLACK_BOT_SIGNING_SECRET && SLACK_BOT_CHANNEL_ID)) { logger.info('Skipping Slack Bot integration, not configured'); return false; } const app = new App({ token: SLACK_BOT_TOKEN.trim(), signingSecret: SLACK_BOT_SIGNING_SECRET.trim(), }); return app; }; const constructMessageBlocks = (displayName, githubUsername, blogUrl) => { const messageBlocks = [ { type: 'header', text: { type: 'plain_text', emoji: true, text: 'New Member Notification :tada:', }, }, { type: 'divider', }, { type: 'context', elements: [ { type: 'image', image_url: `https://github.com/${githubUsername}.png?size=64`, alt_text: 'avatar', }, { type: 'mrkdwn', text: `*${displayName}* has joined the Telescope community. Be the first one to welcome them.`, }, { type: 'mrkdwn', text: ``, }, { type: 'mrkdwn', text: `<${blogUrl} | *Visit Blog*>`, }, ], }, ]; return messageBlocks; }; const publishSignUpMessage = async (displayName, githubUsername, blogUrl) => { if (!(displayName && githubUsername && blogUrl)) throw new Error( 'displayName, gitHubUsername, and blogUrl are required to send sign up announcement' ); const app = createSlackApp(); if (app) { try { const messageBlocks = constructMessageBlocks(displayName, githubUsername, blogUrl); const result = await app.client.chat.postMessage({ channel: SLACK_BOT_CHANNEL_ID.trim(), text: `${displayName} has joined the Telescope community. Be the first one to welcome them.`, blocks: messageBlocks, unfurl_links: false, }); logger.debug({ result }, 'Slack Bot message delivery successful'); } catch (error) { logger.warn({ error }, 'Slack Bot message delivery unsuccessful'); } } }; module.exports = publishSignUpMessage;