Skip to content

Commit

Permalink
fix: Fixed Event Syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
noahonyejese committed Oct 1, 2024
1 parent 3fcf780 commit 50a95ab
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
19 changes: 12 additions & 7 deletions app/api/slack/events/conversations/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,24 @@ export const POST = async (req: NextRequest) => {
if (type === 'event_callback' && event?.type === 'reaction_added') {
validateReactionSlackEvent(event);
await updateSlackReaction(event);
return new Response(
JSON.stringify({
success: true,
}),
{ status: 200 }
);
}

if (type === 'event_callback' && event?.type === 'message') {
validateMessageSlackEvent(event);
await updateSlackMessage(event);
return new Response(
JSON.stringify({
success: true,
}),
{ status: 200 }
);
}

return new Response(
JSON.stringify({
success: true,
}),
{ status: 200 }
);
} catch (error) {
if (error instanceof Error) {
console.log(error.message);
Expand Down
15 changes: 15 additions & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ exports.clearRealtimeDatabase = functions.pubsub
const ref = rtdb.ref(pathToClear);
await ref.remove();

await initializeRealtimeDatabase();

console.log(`Successfully cleared the path: ${pathToClear}`);
return null;
} catch (error) {
Expand Down Expand Up @@ -106,3 +108,16 @@ const takeScreenshotAndUpload = async (bucket: Bucket) => {

return screenshotFileName;
};

const initializeRealtimeDatabase = async () => {
const ref = await firestore.collection("metrics").get();
const metrics = ref.docs.map((doc) => doc.data());
const dataRef = rtdb.ref("/data");
metrics.forEach((metric) => {
dataRef.child(metric.id).set({
title: metric.title,
description: metric.description,
sensors: {},
});
});
};
2 changes: 1 addition & 1 deletion server/slack/syncs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const validateReactionSlackEvent = (event: ReactionAddedEvent) => {
export const updateSlackReaction = async (event: ReactionAddedEvent) => {
const db = admin.database();
const userRef = db.ref(
`data/team-communication/sensor-1/value/${event.user}`
`data/team-communication/sensors/slack/value/${event.user}`
);

const snapshot = await userRef.once('value');
Expand Down

0 comments on commit 50a95ab

Please sign in to comment.