Skip to content

Commit 72c08c1

Browse files
committed
Send reminder message to both DEFAULT_SLACK_EVENT_CHANNEL and event.eventSlackAnnouncementsChannelId
1 parent e1a469a commit 72c08c1

File tree

1 file changed

+80
-87
lines changed
  • functions/event-reminders-hourly

1 file changed

+80
-87
lines changed

functions/event-reminders-hourly/index.js

Lines changed: 80 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function createEventsQuery(calendars) {
3535
startDateLocalized
3636
endDateLocalized
3737
${calendars.solspace_calendar.calendars.map(
38-
({ handle }) => `
38+
({ handle }) => `
3939
... on ${handle}_Event {
4040
eventCalendarDescription
4141
eventJoinLink
@@ -44,7 +44,7 @@ function createEventsQuery(calendars) {
4444
eventSlackAnnouncementsChannelId
4545
}
4646
`
47-
)}
47+
)}
4848
}
4949
}
5050
}
@@ -89,90 +89,85 @@ 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,
95+
const createMessage = (channel) => {
96+
const message = {
97+
channel: channel,
98+
text: `Starting soon: ${event.title}: ${eventDate.toFormat('EEEE, fff')}`,
99+
unfurl_links: false,
100+
unfurl_media: false,
101+
blocks: [
102+
{
103+
type: 'header',
104+
text: {
105+
type: 'plain_text',
106+
text: '⏰ Starting Soon:',
107+
emoji: true,
108+
},
111109
},
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(
123-
'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',
110+
],
142111
};
143-
}
144-
145-
message.blocks.push(titleBlock);
146112

147-
if (
148-
event.eventJoinLink &&
149-
event.eventJoinLink.substring(0, 4) !== 'http'
150-
) {
151-
message.blocks.push({
113+
const titleBlock = {
152114
type: 'section',
153115
text: {
154116
type: 'mrkdwn',
155-
text: `*Location:* ${event.eventJoinLink}`,
117+
text: `*${event.title}*\n<!date^${eventDate.toSeconds()}^{date_long_pretty} {time}|${eventDate.toFormat('EEEE, fff')}>`,
156118
},
157-
});
158-
}
119+
};
159120

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

175-
return message;
147+
message.blocks.push(
148+
{
149+
type: 'context',
150+
elements: [
151+
{
152+
type: 'mrkdwn',
153+
text: slackify(event.eventCalendarDescription),
154+
},
155+
],
156+
},
157+
{
158+
type: 'divider',
159+
}
160+
);
161+
162+
return message;
163+
};
164+
165+
const messages = [
166+
createMessage(DEFAULT_SLACK_EVENT_CHANNEL),
167+
createMessage(event.eventSlackAnnouncementsChannelId),
168+
];
169+
170+
return messages;
176171
});
177172

178173
const hourlyAdminMessage = {
@@ -202,11 +197,10 @@ const handler = async function (event, context) {
202197
type: 'section',
203198
text: {
204199
type: 'mrkdwn',
205-
text: `*${
206-
event.title
207-
}*\n<!date^${eventDate.toSeconds()}^{date_long_pretty} {time}|${eventDate.toFormat(
208-
'EEEE, fff'
209-
)}>`,
200+
text: `*${event.title
201+
}*\n<!date^${eventDate.toSeconds()}^{date_long_pretty} {time}|${eventDate.toFormat(
202+
'EEEE, fff'
203+
)}>`,
210204
},
211205
};
212206

@@ -239,23 +233,22 @@ const handler = async function (event, context) {
239233
},
240234
...(event.eventZoomHostCode
241235
? [
242-
{
243-
type: 'section',
244-
text: {
245-
type: 'mrkdwn',
246-
text: `*Host Code:* ${event.eventZoomHostCode}`,
247-
},
236+
{
237+
type: 'section',
238+
text: {
239+
type: 'mrkdwn',
240+
text: `*Host Code:* ${event.eventZoomHostCode}`,
248241
},
249-
]
242+
},
243+
]
250244
: []),
251245
{
252246
type: 'section',
253247
text: {
254248
type: 'mrkdwn',
255-
text: `*Announcement posted to:* <#${
256-
event.eventSlackAnnouncementsChannelId ||
249+
text: `*Announcement posted to:* <#${event.eventSlackAnnouncementsChannelId ||
257250
DEFAULT_SLACK_EVENT_CHANNEL
258-
}>`,
251+
}>`,
259252
},
260253
},
261254
{

0 commit comments

Comments
 (0)