From 75bc187e7278b6d45859c8dcb4e3b70e1bdf2bbd Mon Sep 17 00:00:00 2001 From: Marks Polakovs Date: Tue, 26 Nov 2024 22:18:30 +0000 Subject: [PATCH 1/4] [INT-209] Update CheckWithTech Slack message even if requestor doesn't have Slack linked --- features/calendar/check_with_tech_actions.ts | 89 +++++++++++--------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/features/calendar/check_with_tech_actions.ts b/features/calendar/check_with_tech_actions.ts index f988a820..9b3628a5 100644 --- a/features/calendar/check_with_tech_actions.ts +++ b/features/calendar/check_with_tech_actions.ts @@ -448,26 +448,10 @@ export async function _sendCWTFollowUpAndUpdateMessage( env.SLACK_CHECK_WITH_TECH_CHANNEL, "SLACK_CHECK_WITH_TECH_CHANNEL not set", ); - const requestor = cwt.submitted_by_user.identities.find( - (x) => x.provider === "slack", - ); - if (!requestor) { - return; - } const api = await slackApiConnection(); - const responseParts = [ - `Your #check-with-tech request for ${ - cwt.event.name - } has been ${newStatus.toLowerCase()} by ${getUserName(actor)}.`, - newNotes ? `Notes: ${newNotes}` : "", - `View your event <${env.PUBLIC_URL}/calendar/${cwt.event_id}|here>.`, - ].filter(Boolean); - await api.client.chat.postMessage({ - channel: requestor.provider_key, - text: responseParts.join("\n"), - mrkdwn: true, - }); + // First update the existing channel message, then DM the requestor if + // they have a linked Slack account. let newContext; switch (newStatus) { case "Confirmed": @@ -495,29 +479,54 @@ export async function _sendCWTFollowUpAndUpdateMessage( newRequest ?? cwt.request, ]; - await api.client.chat.update({ - channel: env.SLACK_CHECK_WITH_TECH_CHANNEL, - ts: cwt.slack_message_ts, - text: [...lines, newContext].join("\n"), - blocks: [ - { - type: "section", - text: { - type: "mrkdwn", - text: lines.join("\n"), - }, - }, - { - type: "context", - elements: [ - { - type: "plain_text", - text: newContext!, - emoji: true, + try { + await api.client.chat.update({ + channel: env.SLACK_CHECK_WITH_TECH_CHANNEL, + ts: cwt.slack_message_ts, + text: [...lines, newContext].join("\n"), + blocks: [ + { + type: "section", + text: { + type: "mrkdwn", + text: lines.join("\n"), }, - ], - }, - ], + }, + { + type: "context", + elements: [ + { + type: "plain_text", + text: newContext!, + emoji: true, + }, + ], + }, + ], + }); + } catch (e) { + console.error("Failed to update #check-with-tech message"); + console.error(e); + // Still try to DM the requestor + } + + const requestor = cwt.submitted_by_user.identities.find( + (x) => x.provider === "slack", + ); + if (!requestor) { + return; + } + const responseParts = [ + `Your #check-with-tech request for ${ + cwt.event.name + } has been ${newStatus.toLowerCase()} by ${getUserName(actor)}.`, + newNotes ? `Notes: ${newNotes}` : "", + `View your event <${env.PUBLIC_URL}/calendar/${cwt.event_id}|here>.`, + ].filter(Boolean); + await api.client.chat.postMessage({ + channel: requestor.provider_key, + text: responseParts.join("\n"), + mrkdwn: true, }); } From 4fc38dad8e42568bb7df7ce1eedb8fcf24eb55f4 Mon Sep 17 00:00:00 2001 From: Marks Polakovs Date: Tue, 26 Nov 2024 22:20:34 +0000 Subject: [PATCH 2/4] Handle all statuses --- features/calendar/check_with_tech_actions.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/features/calendar/check_with_tech_actions.ts b/features/calendar/check_with_tech_actions.ts index 9b3628a5..d02db1aa 100644 --- a/features/calendar/check_with_tech_actions.ts +++ b/features/calendar/check_with_tech_actions.ts @@ -460,6 +460,10 @@ export async function _sendCWTFollowUpAndUpdateMessage( case "Rejected": newContext = `:x: Declined by ${getUserName(actor)}`; break; + case "Requested": + invariant(false, "CWTFollowUp: Expected status other than Requested"); + default: + invariant(false, "CWTFollowUp: Unknown status " + newStatus); } const lines = [ From 6f33d4abf21fcfebcbade754aca8ed72dfd689e1 Mon Sep 17 00:00:00 2001 From: Marks Polakovs Date: Tue, 26 Nov 2024 22:21:13 +0000 Subject: [PATCH 3/4] No longer need this assertion --- features/calendar/check_with_tech_actions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/calendar/check_with_tech_actions.ts b/features/calendar/check_with_tech_actions.ts index d02db1aa..295665ed 100644 --- a/features/calendar/check_with_tech_actions.ts +++ b/features/calendar/check_with_tech_actions.ts @@ -501,7 +501,7 @@ export async function _sendCWTFollowUpAndUpdateMessage( elements: [ { type: "plain_text", - text: newContext!, + text: newContext, emoji: true, }, ], From 6def56b27dcb171beef4093dbe4fe86a9b5d11c5 Mon Sep 17 00:00:00 2001 From: Marks Polakovs Date: Tue, 26 Nov 2024 22:24:19 +0000 Subject: [PATCH 4/4] Don't follow up for notes --- features/calendar/check_with_tech_actions.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/features/calendar/check_with_tech_actions.ts b/features/calendar/check_with_tech_actions.ts index 295665ed..d07e0fa7 100644 --- a/features/calendar/check_with_tech_actions.ts +++ b/features/calendar/check_with_tech_actions.ts @@ -404,13 +404,15 @@ export async function handleSlackViewEvent(data: SlackViewMiddlewareArgs) { if (!newStatus) { return; } - await _sendCWTFollowUpAndUpdateMessage( - cwt, - actor, - newStatus, - notes ?? "", - request, - ); + if (reqType !== "Note") { + await _sendCWTFollowUpAndUpdateMessage( + cwt, + actor, + newStatus, + notes ?? "", + request, + ); + } } export interface FullCheckWithTech extends CheckWithTech {