mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
refactor: clean up code formatting and improve debug logging in Slack actions
This commit is contained in:
@@ -762,8 +762,10 @@ export default class SlackAPI {
|
||||
if (event["type"] === "reaction_added") {
|
||||
logger.debug("Reaction added event received");
|
||||
|
||||
// Respond immediately to Slack to prevent retry
|
||||
// Process the event asynchronously
|
||||
/*
|
||||
* Respond immediately to Slack to prevent retry
|
||||
* Process the event asynchronously
|
||||
*/
|
||||
Response.sendTextResponse(req, res, "ok");
|
||||
|
||||
const reactionData = {
|
||||
@@ -774,8 +776,10 @@ export default class SlackAPI {
|
||||
messageTs: (event["item"] as JSONObject)?.["ts"] as string,
|
||||
};
|
||||
|
||||
// Process emoji reactions for Incidents, Alerts, and Scheduled Maintenance
|
||||
// Each handler will silently ignore if the channel is not linked to their resource type
|
||||
/*
|
||||
* Process emoji reactions for Incidents, Alerts, and Scheduled Maintenance
|
||||
* Each handler will silently ignore if the channel is not linked to their resource type
|
||||
*/
|
||||
try {
|
||||
await SlackIncidentActions.handleEmojiReaction(reactionData);
|
||||
} catch (err) {
|
||||
@@ -791,9 +795,13 @@ export default class SlackAPI {
|
||||
}
|
||||
|
||||
try {
|
||||
await SlackScheduledMaintenanceActions.handleEmojiReaction(reactionData);
|
||||
await SlackScheduledMaintenanceActions.handleEmojiReaction(
|
||||
reactionData,
|
||||
);
|
||||
} catch (err) {
|
||||
logger.error("Error handling scheduled maintenance emoji reaction:");
|
||||
logger.error(
|
||||
"Error handling scheduled maintenance emoji reaction:",
|
||||
);
|
||||
logger.error(err);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +52,7 @@ const jsonBodyParserMiddleware: RequestHandler = ExpressJson({
|
||||
extended: true,
|
||||
verify: (req: ExpressRequest, _res: ExpressResponse, buf: Buffer) => {
|
||||
(req as OneUptimeRequest).rawBody = buf.toString();
|
||||
logger.debug(
|
||||
`Raw JSON Body for signature verification captured`,
|
||||
);
|
||||
logger.debug(`Raw JSON Body for signature verification captured`);
|
||||
},
|
||||
}); // 50 MB limit.
|
||||
|
||||
|
||||
@@ -45,11 +45,7 @@ enum SlackActionType {
|
||||
}
|
||||
|
||||
// Emoji names that trigger saving a message as a Private Note (Internal Note)
|
||||
export const PrivateNoteEmojis: string[] = [
|
||||
"pushpin",
|
||||
"round_pushpin",
|
||||
"pin",
|
||||
];
|
||||
export const PrivateNoteEmojis: string[] = ["pushpin", "round_pushpin", "pin"];
|
||||
|
||||
// Emoji names that trigger saving a message as a Public Note
|
||||
export const PublicNoteEmojis: string[] = [
|
||||
|
||||
@@ -801,22 +801,23 @@ export default class SlackAlertActions {
|
||||
}
|
||||
|
||||
// Get the project auth token using the team ID
|
||||
const projectAuth =
|
||||
await WorkspaceProjectAuthTokenService.findOneBy({
|
||||
query: {
|
||||
workspaceProjectId: teamId,
|
||||
},
|
||||
select: {
|
||||
projectId: true,
|
||||
authToken: true,
|
||||
},
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
const projectAuth = await WorkspaceProjectAuthTokenService.findOneBy({
|
||||
query: {
|
||||
workspaceProjectId: teamId,
|
||||
},
|
||||
select: {
|
||||
projectId: true,
|
||||
authToken: true,
|
||||
},
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!projectAuth || !projectAuth.projectId || !projectAuth.authToken) {
|
||||
logger.debug("No project auth found for team ID. Ignoring emoji reaction.");
|
||||
logger.debug(
|
||||
"No project auth found for team ID. Ignoring emoji reaction.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -849,10 +850,9 @@ export default class SlackAlertActions {
|
||||
const alertId: ObjectID = workspaceLog.alertId;
|
||||
|
||||
// Get the alert number for the confirmation message
|
||||
const alertNumber: number | null =
|
||||
await AlertService.getAlertNumber({
|
||||
alertId: alertId,
|
||||
});
|
||||
const alertNumber: number | null = await AlertService.getAlertNumber({
|
||||
alertId: alertId,
|
||||
});
|
||||
|
||||
// Get the user ID in OneUptime based on Slack user ID
|
||||
const userAuth = await WorkspaceUserAuthTokenService.findOneBy({
|
||||
@@ -918,8 +918,7 @@ export default class SlackAlertActions {
|
||||
await AlertService.getAlertLinkInDashboard(projectId, alertId)
|
||||
).toString();
|
||||
|
||||
const confirmationMessage: string =
|
||||
`✅ Message saved as *private note* to <${alertLink}|Alert #${alertNumber}>.`;
|
||||
const confirmationMessage: string = `✅ Message saved as *private note* to <${alertLink}|Alert #${alertNumber}>.`;
|
||||
|
||||
await SlackUtil.sendMessageToThread({
|
||||
authToken: authToken,
|
||||
|
||||
@@ -1317,22 +1317,23 @@ export default class SlackIncidentActions {
|
||||
}
|
||||
|
||||
// Get the project auth token using the team ID
|
||||
const projectAuth =
|
||||
await WorkspaceProjectAuthTokenService.findOneBy({
|
||||
query: {
|
||||
workspaceProjectId: teamId,
|
||||
},
|
||||
select: {
|
||||
projectId: true,
|
||||
authToken: true,
|
||||
},
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
const projectAuth = await WorkspaceProjectAuthTokenService.findOneBy({
|
||||
query: {
|
||||
workspaceProjectId: teamId,
|
||||
},
|
||||
select: {
|
||||
projectId: true,
|
||||
authToken: true,
|
||||
},
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!projectAuth || !projectAuth.projectId || !projectAuth.authToken) {
|
||||
logger.debug("No project auth found for team ID. Ignoring emoji reaction.");
|
||||
logger.debug(
|
||||
"No project auth found for team ID. Ignoring emoji reaction.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1125,7 +1125,9 @@ export default class SlackScheduledMaintenanceActions {
|
||||
channelId: string;
|
||||
messageTs: string;
|
||||
}): Promise<void> {
|
||||
logger.debug("Handling emoji reaction for Scheduled Maintenance with data:");
|
||||
logger.debug(
|
||||
"Handling emoji reaction for Scheduled Maintenance with data:",
|
||||
);
|
||||
logger.debug(data);
|
||||
|
||||
const { teamId, reaction, userId, channelId, messageTs } = data;
|
||||
@@ -1142,22 +1144,23 @@ export default class SlackScheduledMaintenanceActions {
|
||||
}
|
||||
|
||||
// Get the project auth token using the team ID
|
||||
const projectAuth =
|
||||
await WorkspaceProjectAuthTokenService.findOneBy({
|
||||
query: {
|
||||
workspaceProjectId: teamId,
|
||||
},
|
||||
select: {
|
||||
projectId: true,
|
||||
authToken: true,
|
||||
},
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
const projectAuth = await WorkspaceProjectAuthTokenService.findOneBy({
|
||||
query: {
|
||||
workspaceProjectId: teamId,
|
||||
},
|
||||
select: {
|
||||
projectId: true,
|
||||
authToken: true,
|
||||
},
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!projectAuth || !projectAuth.projectId || !projectAuth.authToken) {
|
||||
logger.debug("No project auth found for team ID. Ignoring emoji reaction.");
|
||||
logger.debug(
|
||||
"No project auth found for team ID. Ignoring emoji reaction.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1187,7 +1190,8 @@ export default class SlackScheduledMaintenanceActions {
|
||||
return;
|
||||
}
|
||||
|
||||
const scheduledMaintenanceId: ObjectID = workspaceLog.scheduledMaintenanceId;
|
||||
const scheduledMaintenanceId: ObjectID =
|
||||
workspaceLog.scheduledMaintenanceId;
|
||||
|
||||
// Get the scheduled maintenance number for the confirmation message
|
||||
const scheduledMaintenanceNumber: number | null =
|
||||
@@ -1271,7 +1275,10 @@ export default class SlackScheduledMaintenanceActions {
|
||||
// Send confirmation message as a reply to the original message thread
|
||||
try {
|
||||
const scheduledMaintenanceLink: string = (
|
||||
await ScheduledMaintenanceService.getScheduledMaintenanceLinkInDashboard(projectId, scheduledMaintenanceId)
|
||||
await ScheduledMaintenanceService.getScheduledMaintenanceLinkInDashboard(
|
||||
projectId,
|
||||
scheduledMaintenanceId,
|
||||
)
|
||||
).toString();
|
||||
|
||||
const confirmationMessage: string =
|
||||
|
||||
Reference in New Issue
Block a user