@@ -89,90 +89,92 @@ 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
- } ;
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 (
123
99
'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
+ ] ,
142
113
} ;
143
- }
144
-
145
- message . blocks . push ( titleBlock ) ;
146
114
147
- if (
148
- event . eventJoinLink &&
149
- event . eventJoinLink . substring ( 0 , 4 ) !== 'http'
150
- ) {
151
- message . blocks . push ( {
115
+ const titleBlock = {
152
116
type : 'section' ,
153
117
text : {
154
118
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
+ ) } >`,
156
122
} ,
157
- } ) ;
158
- }
123
+ } ;
159
124
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 : {
165
145
type : 'mrkdwn' ,
166
- text : slackify ( event . eventCalendarDescription ) ,
146
+ text : `*Location:* ${ event . eventJoinLink } ` ,
167
147
} ,
168
- ] ,
169
- } ,
170
- {
171
- type : 'divider' ,
148
+ } ) ;
172
149
}
173
- ) ;
174
150
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 ;
176
178
} ) ;
177
179
178
180
const hourlyAdminMessage = {
@@ -227,6 +229,11 @@ const handler = async function (event, context) {
227
229
} ;
228
230
}
229
231
232
+ const channels = [ DEFAULT_SLACK_EVENT_CHANNEL ] ;
233
+ if ( event . eventSlackAnnouncementsChannelId ) {
234
+ channels . push ( event . eventSlackAnnouncementsChannelId ) ;
235
+ }
236
+
230
237
return [
231
238
...list ,
232
239
titleBlock ,
@@ -252,10 +259,7 @@ const handler = async function (event, context) {
252
259
type : 'section' ,
253
260
text : {
254
261
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 ( ' ' ) ,
259
263
} ,
260
264
} ,
261
265
{
0 commit comments