Skip to content

Commit ac8cf86

Browse files
committed
Send reminder message to both #vc-events and optional second channel
The diff does not look nice, but there are two main changes: For each event, instead of choosing between DEFAULT_SLACK_EVENT_CHANNEL and event.eventSlackAnnouncementsChannelId (and preferring event.eventSlackAnnouncementsChannelId over DEFAULT_SLACK_EVENT_CHANNEL) we create a message for DEFAULT_SLACK_EVENT_CHANNEL and then if event.eventSlackAnnouncementsChannelId is set, then we also create a message for that channel. We apply the same logic for the hourlyAdminMessage to generate a list of channels it got posted to.
1 parent e1a469a commit ac8cf86

File tree

1 file changed

+78
-74
lines changed
  • functions/event-reminders-hourly

1 file changed

+78
-74
lines changed

functions/event-reminders-hourly/index.js

Lines changed: 78 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -89,90 +89,92 @@ const handler = async function (event, context) {
8989
});
9090

9191
if (filteredList.length) {
92-
const hourlyMessages = filteredList.map((event) => {
92+
const hourlyMessages = filteredList.flatMap((event) => {
9393
const eventDate = DateTime.fromISO(event.startDateLocalized);
9494

95-
const message = {
96-
channel:
97-
event.eventSlackAnnouncementsChannelId ||
98-
DEFAULT_SLACK_EVENT_CHANNEL,
99-
text: `Starting soon: ${event.title}: ${eventDate.toFormat(
100-
'EEEE, fff'
101-
)}`,
102-
unfurl_links: false,
103-
unfurl_media: false,
104-
blocks: [
105-
{
106-
type: 'header',
107-
text: {
108-
type: 'plain_text',
109-
text: '⏰ Starting Soon:',
110-
emoji: true,
111-
},
112-
},
113-
],
114-
};
115-
116-
const titleBlock = {
117-
type: 'section',
118-
text: {
119-
type: 'mrkdwn',
120-
text: `*${
121-
event.title
122-
}*\n<!date^${eventDate.toSeconds()}^{date_long_pretty} {time}|${eventDate.toFormat(
95+
const createMessage = (channel) => {
96+
const message = {
97+
channel: channel,
98+
text: `Starting soon: ${event.title}: ${eventDate.toFormat(
12399
'EEEE, fff'
124-
)}>`,
125-
},
126-
};
127-
128-
if (
129-
event.eventJoinLink &&
130-
event.eventJoinLink.substring(0, 4) === 'http'
131-
) {
132-
titleBlock.accessory = {
133-
type: 'button',
134-
text: {
135-
type: 'plain_text',
136-
text: 'Join Event',
137-
emoji: true,
138-
},
139-
value: `join_event_${event.id}`,
140-
url: event.eventJoinLink,
141-
action_id: 'button-join-event',
100+
)}`,
101+
unfurl_links: false,
102+
unfurl_media: false,
103+
blocks: [
104+
{
105+
type: 'header',
106+
text: {
107+
type: 'plain_text',
108+
text: '⏰ Starting Soon:',
109+
emoji: true,
110+
},
111+
},
112+
],
142113
};
143-
}
144-
145-
message.blocks.push(titleBlock);
146114

147-
if (
148-
event.eventJoinLink &&
149-
event.eventJoinLink.substring(0, 4) !== 'http'
150-
) {
151-
message.blocks.push({
115+
const titleBlock = {
152116
type: 'section',
153117
text: {
154118
type: 'mrkdwn',
155-
text: `*Location:* ${event.eventJoinLink}`,
119+
text: `*${event.title}*\n<!date^${eventDate.toSeconds()}^{date_long_pretty} {time}|${eventDate.toFormat(
120+
'EEEE, fff'
121+
)}>`,
156122
},
157-
});
158-
}
123+
};
159124

160-
message.blocks.push(
161-
{
162-
type: 'context',
163-
elements: [
164-
{
125+
if (event.eventJoinLink && event.eventJoinLink.substring(0, 4) === 'http') {
126+
titleBlock.accessory = {
127+
type: 'button',
128+
text: {
129+
type: 'plain_text',
130+
text: 'Join Event',
131+
emoji: true,
132+
},
133+
value: `join_event_${event.id}`,
134+
url: event.eventJoinLink,
135+
action_id: 'button-join-event',
136+
};
137+
}
138+
139+
message.blocks.push(titleBlock);
140+
141+
if (event.eventJoinLink && event.eventJoinLink.substring(0, 4) !== 'http') {
142+
message.blocks.push({
143+
type: 'section',
144+
text: {
165145
type: 'mrkdwn',
166-
text: slackify(event.eventCalendarDescription),
146+
text: `*Location:* ${event.eventJoinLink}`,
167147
},
168-
],
169-
},
170-
{
171-
type: 'divider',
148+
});
172149
}
173-
);
174150

175-
return message;
151+
message.blocks.push(
152+
{
153+
type: 'context',
154+
elements: [
155+
{
156+
type: 'mrkdwn',
157+
text: slackify(event.eventCalendarDescription),
158+
},
159+
],
160+
},
161+
{
162+
type: 'divider',
163+
}
164+
);
165+
166+
return message;
167+
};
168+
169+
const messages = [
170+
createMessage(DEFAULT_SLACK_EVENT_CHANNEL)
171+
];
172+
173+
if (event.eventSlackAnnouncementsChannelId) {
174+
messages.push(createMessage(event.eventSlackAnnouncementsChannelId));
175+
}
176+
177+
return messages;
176178
});
177179

178180
const hourlyAdminMessage = {
@@ -227,6 +229,11 @@ const handler = async function (event, context) {
227229
};
228230
}
229231

232+
const channels = [DEFAULT_SLACK_EVENT_CHANNEL];
233+
if (event.eventSlackAnnouncementsChannelId) {
234+
channels.push(event.eventSlackAnnouncementsChannelId);
235+
}
236+
230237
return [
231238
...list,
232239
titleBlock,
@@ -252,10 +259,7 @@ const handler = async function (event, context) {
252259
type: 'section',
253260
text: {
254261
type: 'mrkdwn',
255-
text: `*Announcement posted to:* <#${
256-
event.eventSlackAnnouncementsChannelId ||
257-
DEFAULT_SLACK_EVENT_CHANNEL
258-
}>`,
262+
text: `*Announcement posted to:* ` + channels.map(channel => `<#${channel}>`).join(' '),
259263
},
260264
},
261265
{

0 commit comments

Comments
 (0)