@@ -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,88 +89,90 @@ const handler = async function (event, context) {
8989 } ) ;
9090
9191 if ( filteredList . length ) {
92- const hourlyMessages = filteredList . flatMap ( ( event ) => {
92+ const hourlyMessages = filteredList . map ( ( event ) => {
9393 const eventDate = DateTime . fromISO ( event . startDateLocalized ) ;
9494
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 ,
109111 } ,
110- ] ,
111- } ;
112+ } ,
113+ ] ,
114+ } ;
112115
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' ,
115134 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 ,
118138 } ,
139+ value : `join_event_${ event . id } ` ,
140+ url : event . eventJoinLink ,
141+ action_id : 'button-join-event' ,
119142 } ;
143+ }
120144
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 ) ;
134146
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+ }
136159
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+ {
141165 type : 'mrkdwn' ,
142- text : `*Location:* ${ event . eventJoinLink } ` ,
166+ text : slackify ( event . eventCalendarDescription ) ,
143167 } ,
144- } ) ;
168+ ] ,
169+ } ,
170+ {
171+ type : 'divider' ,
145172 }
173+ ) ;
146174
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 ;
174176 } ) ;
175177
176178 const hourlyAdminMessage = {
@@ -200,10 +202,11 @@ const handler = async function (event, context) {
200202 type : 'section' ,
201203 text : {
202204 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+ ) } >`,
207210 } ,
208211 } ;
209212
@@ -224,11 +227,6 @@ const handler = async function (event, context) {
224227 } ;
225228 }
226229
227- const channels = [ DEFAULT_SLACK_EVENT_CHANNEL ] ;
228- if ( event . eventSlackAnnouncementsChannelId ) {
229- channels . push ( event . eventSlackAnnouncementsChannelId ) ;
230- }
231-
232230 return [
233231 ...list ,
234232 titleBlock ,
@@ -241,20 +239,23 @@ const handler = async function (event, context) {
241239 } ,
242240 ...( event . eventZoomHostCode
243241 ? [
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+ } ,
249248 } ,
250- } ,
251- ]
249+ ]
252250 : [ ] ) ,
253251 {
254252 type : 'section' ,
255253 text : {
256254 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+ } >`,
258259 } ,
259260 } ,
260261 {
@@ -285,3 +286,4 @@ const handler = async function (event, context) {
285286} ;
286287
287288module . exports . handler = schedule ( '50 * * * *' , handler ) ;
289+
0 commit comments