Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INT-209] Update CheckWithTech Slack message even if requestor doesn't have Slack linked #193

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 62 additions & 47 deletions features/calendar/check_with_tech_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -448,26 +450,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":
Expand All @@ -476,6 +462,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 = [
Expand All @@ -495,29 +485,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,
markspolakovs marked this conversation as resolved.
Show resolved Hide resolved
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,
});
}

Expand Down