@@ -51,7 +51,7 @@ function createEventsQuery(calendars) {
51
51
` ;
52
52
}
53
53
54
- const handler = async function ( event , context ) {
54
+ const handler = async function ( handlerEvent , handlerContext ) {
55
55
const graphQLClient = new GraphQLClient ( `${ process . env . CMS_URL } /api` , {
56
56
headers : {
57
57
Authorization : `bearer ${ process . env . CMS_TOKEN } ` ,
@@ -89,90 +89,98 @@ const handler = async function (event, context) {
89
89
} ) ;
90
90
91
91
if ( filteredList . length ) {
92
- const hourlyMessages = filteredList . map ( ( event ) => {
92
+ const hourlyMessages = filteredList . flatMap ( ( event ) => {
93
93
const eventDate = DateTime . fromISO ( event . startDateLocalized ) ;
94
94
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
- } ;
95
+ const announcementsChannels = [ DEFAULT_SLACK_EVENT_CHANNEL ] ;
96
+ if ( event . eventSlackAnnouncementsChannelId && event . eventSlackAnnouncementsChannelId !== DEFAULT_SLACK_EVENT_CHANNEL ) {
97
+ announcementsChannels . push ( event . eventSlackAnnouncementsChannelId ) ;
98
+ }
115
99
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 (
100
+ const createMessage = ( channel ) => {
101
+ const message = {
102
+ channel : channel ,
103
+ text : `Starting soon: ${ event . title } : ${ eventDate . toFormat (
123
104
'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' ,
105
+ ) } `,
106
+ unfurl_links : false ,
107
+ unfurl_media : false ,
108
+ blocks : [
109
+ {
110
+ type : 'header' ,
111
+ text : {
112
+ type : 'plain_text' ,
113
+ text : '⏰ Starting Soon:' ,
114
+ emoji : true ,
115
+ } ,
116
+ } ,
117
+ ] ,
142
118
} ;
143
- }
144
119
145
- message . blocks . push ( titleBlock ) ;
146
-
147
- if (
148
- event . eventJoinLink &&
149
- event . eventJoinLink . substring ( 0 , 4 ) !== 'http'
150
- ) {
151
- message . blocks . push ( {
120
+ const titleBlock = {
152
121
type : 'section' ,
153
122
text : {
154
123
type : 'mrkdwn' ,
155
- text : `*Location:* ${ event . eventJoinLink } ` ,
124
+ text : `*${
125
+ event . title
126
+ } *\n<!date^${ eventDate . toSeconds ( ) } ^{date_long_pretty} {time}|${ eventDate . toFormat (
127
+ 'EEEE, fff'
128
+ ) } >`,
156
129
} ,
157
- } ) ;
158
- }
130
+ } ;
159
131
160
- message . blocks . push (
161
- {
162
- type : 'context' ,
163
- elements : [
164
- {
132
+ if (
133
+ event . eventJoinLink &&
134
+ event . eventJoinLink . substring ( 0 , 4 ) === 'http'
135
+ ) {
136
+ titleBlock . accessory = {
137
+ type : 'button' ,
138
+ text : {
139
+ type : 'plain_text' ,
140
+ text : 'Join Event' ,
141
+ emoji : true ,
142
+ } ,
143
+ value : `join_event_${ event . id } ` ,
144
+ url : event . eventJoinLink ,
145
+ action_id : 'button-join-event' ,
146
+ } ;
147
+ }
148
+
149
+ message . blocks . push ( titleBlock ) ;
150
+
151
+ if (
152
+ event . eventJoinLink &&
153
+ event . eventJoinLink . substring ( 0 , 4 ) !== 'http'
154
+ ) {
155
+ message . blocks . push ( {
156
+ type : 'section' ,
157
+ text : {
165
158
type : 'mrkdwn' ,
166
- text : slackify ( event . eventCalendarDescription ) ,
159
+ text : `*Location:* ${ event . eventJoinLink } ` ,
167
160
} ,
168
- ] ,
169
- } ,
170
- {
171
- type : 'divider' ,
161
+ } ) ;
172
162
}
173
- ) ;
174
163
175
- return message ;
164
+ message . blocks . push (
165
+ {
166
+ type : 'context' ,
167
+ elements : [
168
+ {
169
+ type : 'mrkdwn' ,
170
+ text : slackify ( event . eventCalendarDescription ) ,
171
+ } ,
172
+ ] ,
173
+ } ,
174
+ {
175
+ type : 'divider' ,
176
+ }
177
+ ) ;
178
+
179
+ return message ;
180
+ } ;
181
+
182
+ const messages = announcementsChannels . map ( createMessage ) ;
183
+ return messages ;
176
184
} ) ;
177
185
178
186
const hourlyAdminMessage = {
@@ -227,6 +235,11 @@ const handler = async function (event, context) {
227
235
} ;
228
236
}
229
237
238
+ const channels = [ DEFAULT_SLACK_EVENT_CHANNEL ] ;
239
+ if ( event . eventSlackAnnouncementsChannelId && event . eventSlackAnnouncementsChannelId !== DEFAULT_SLACK_EVENT_CHANNEL ) {
240
+ channels . push ( event . eventSlackAnnouncementsChannelId ) ;
241
+ }
242
+
230
243
return [
231
244
...list ,
232
245
titleBlock ,
@@ -252,10 +265,9 @@ const handler = async function (event, context) {
252
265
type : 'section' ,
253
266
text : {
254
267
type : 'mrkdwn' ,
255
- text : `*Announcement posted to:* <#${
256
- event . eventSlackAnnouncementsChannelId ||
257
- DEFAULT_SLACK_EVENT_CHANNEL
258
- } >`,
268
+ text :
269
+ `*Announcement posted to:* ` +
270
+ channels . map ( ( channel ) => `<#${ channel } >` ) . join ( ', ' ) ,
259
271
} ,
260
272
} ,
261
273
{
0 commit comments