@@ -35,7 +35,7 @@ function createEventsQuery(calendars) {
35
35
startDateLocalized
36
36
endDateLocalized
37
37
${ calendars . solspace_calendar . calendars . map (
38
- ( { handle } ) => `
38
+ ( { handle } ) => `
39
39
... on ${ handle } _Event {
40
40
eventCalendarDescription
41
41
eventJoinLink
@@ -44,7 +44,7 @@ function createEventsQuery(calendars) {
44
44
eventSlackAnnouncementsChannelId
45
45
}
46
46
`
47
- ) }
47
+ ) }
48
48
}
49
49
}
50
50
}
@@ -89,88 +89,90 @@ const handler = async function (event, context) {
89
89
} ) ;
90
90
91
91
if ( filteredList . length ) {
92
- const hourlyMessages = filteredList . flatMap ( ( event ) => {
92
+ const hourlyMessages = filteredList . map ( ( event ) => {
93
93
const eventDate = DateTime . fromISO ( event . startDateLocalized ) ;
94
94
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
- } ,
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 ,
109
111
} ,
110
- ] ,
111
- } ;
112
+ } ,
113
+ ] ,
114
+ } ;
112
115
113
- const titleBlock = {
114
- type : 'section' ,
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' ,
115
134
text : {
116
- type : 'mrkdwn' ,
117
- text : `*${ event . title } *\n<!date^${ eventDate . toSeconds ( ) } ^{date_long_pretty} {time}|${ eventDate . toFormat ( 'EEEE, fff' ) } >` ,
135
+ type : 'plain_text' ,
136
+ text : 'Join Event' ,
137
+ emoji : true ,
118
138
} ,
139
+ value : `join_event_${ event . id } ` ,
140
+ url : event . eventJoinLink ,
141
+ action_id : 'button-join-event' ,
119
142
} ;
143
+ }
120
144
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
- }
145
+ message . blocks . push ( titleBlock ) ;
134
146
135
- message . blocks . push ( titleBlock ) ;
147
+ if (
148
+ event . eventJoinLink &&
149
+ event . eventJoinLink . substring ( 0 , 4 ) !== 'http'
150
+ ) {
151
+ message . blocks . push ( {
152
+ type : 'section' ,
153
+ text : {
154
+ type : 'mrkdwn' ,
155
+ text : `*Location:* ${ event . eventJoinLink } ` ,
156
+ } ,
157
+ } ) ;
158
+ }
136
159
137
- if ( event . eventJoinLink && event . eventJoinLink . substring ( 0 , 4 ) !== 'http' ) {
138
- message . blocks . push ( {
139
- type : 'section' ,
140
- text : {
160
+ message . blocks . push (
161
+ {
162
+ type : 'context' ,
163
+ elements : [
164
+ {
141
165
type : 'mrkdwn' ,
142
- text : `*Location:* ${ event . eventJoinLink } ` ,
166
+ text : slackify ( event . eventCalendarDescription ) ,
143
167
} ,
144
- } ) ;
168
+ ] ,
169
+ } ,
170
+ {
171
+ type : 'divider' ,
145
172
}
173
+ ) ;
146
174
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
- ] ;
168
-
169
- if ( event . eventSlackAnnouncementsChannelId ) {
170
- messages . push ( createMessage ( event . eventSlackAnnouncementsChannelId ) ) ;
171
- }
172
-
173
- return messages ;
175
+ return message ;
174
176
} ) ;
175
177
176
178
const hourlyAdminMessage = {
@@ -200,10 +202,11 @@ const handler = async function (event, context) {
200
202
type : 'section' ,
201
203
text : {
202
204
type : 'mrkdwn' ,
203
- text : `*${ event . title
204
- } *\n<!date^${ eventDate . toSeconds ( ) } ^{date_long_pretty} {time}|${ eventDate . toFormat (
205
- 'EEEE, fff'
206
- ) } >`,
205
+ text : `*${
206
+ event . title
207
+ } *\n<!date^${ eventDate . toSeconds ( ) } ^{date_long_pretty} {time}|${ eventDate . toFormat (
208
+ 'EEEE, fff'
209
+ ) } >`,
207
210
} ,
208
211
} ;
209
212
@@ -224,11 +227,6 @@ const handler = async function (event, context) {
224
227
} ;
225
228
}
226
229
227
- const channels = [ DEFAULT_SLACK_EVENT_CHANNEL ] ;
228
- if ( event . eventSlackAnnouncementsChannelId ) {
229
- channels . push ( event . eventSlackAnnouncementsChannelId ) ;
230
- }
231
-
232
230
return [
233
231
...list ,
234
232
titleBlock ,
@@ -241,20 +239,23 @@ const handler = async function (event, context) {
241
239
} ,
242
240
...( event . eventZoomHostCode
243
241
? [
244
- {
245
- type : 'section' ,
246
- text : {
247
- type : 'mrkdwn' ,
248
- text : `*Host Code:* ${ event . eventZoomHostCode } ` ,
242
+ {
243
+ type : 'section' ,
244
+ text : {
245
+ type : 'mrkdwn' ,
246
+ text : `*Host Code:* ${ event . eventZoomHostCode } ` ,
247
+ } ,
249
248
} ,
250
- } ,
251
- ]
249
+ ]
252
250
: [ ] ) ,
253
251
{
254
252
type : 'section' ,
255
253
text : {
256
254
type : 'mrkdwn' ,
257
- text : `*Announcement posted to:* ` + channels . map ( channel => `<#${ channel } >` ) . join ( ' ' ) ,
255
+ text : `*Announcement posted to:* <#${
256
+ event . eventSlackAnnouncementsChannelId ||
257
+ DEFAULT_SLACK_EVENT_CHANNEL
258
+ } >`,
258
259
} ,
259
260
} ,
260
261
{
@@ -285,3 +286,4 @@ const handler = async function (event, context) {
285
286
} ;
286
287
287
288
module . exports . handler = schedule ( '50 * * * *' , handler ) ;
289
+
0 commit comments