Share Slack home publish pipeline

Co-authored-by: Adam Moussa <amoussa1229@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-05-08 00:24:06 +00:00 • committed by Adam Moussa
parent 8073eb3662
commit 44e46a1fd0

View file

@ -146,6 +146,10 @@ export const handler = async (event) => {
const userId = body.event.user;
return publishHomeView(userId, []);
};
async function publishHomeView(userId, expanded) {
const { Item: metadata } = await ddb.send(
new GetCommand({ TableName: TABLE_NAME, Key: { pk: "metadata" } })
);
@ -159,7 +163,6 @@ export const handler = async (event) => {
return { statusCode: 200, body: JSON.stringify({ error: "No payment data" }) };
}
const expanded = [];
const view = buildHomeView(payments, metadata, boaTransactions, expanded);
const slackToken = await getSlackToken();
@ -180,7 +183,7 @@ export const handler = async (event) => {
}
return { statusCode: 200, body: JSON.stringify({ ok: true }) };
};
}
// --- Block action handler (button clicks) ---
@ -195,32 +198,13 @@ async function handleBlockAction(body) {
if (actionId.startsWith("toggle_section_")) {
const section = actionId.replace("toggle_section_", "");
const meta = JSON.parse(body.view?.private_metadata || "{}");
const expanded = meta.expanded || [];
const expanded = Array.isArray(meta.expanded) ? [...meta.expanded] : [];
const idx = expanded.indexOf(section);
if (idx >= 0) expanded.splice(idx, 1);
else expanded.push(section);
const userId = body.user?.id;
const { Item: metadata } = await ddb.send(
new GetCommand({ TableName: TABLE_NAME, Key: { pk: "metadata" } })
);
const [payments, boaTransactions] = await Promise.all([
scanPayments(),
scanBoATransactions(),
]);
const view = buildHomeView(payments, metadata, boaTransactions, expanded);
const slackToken = await getSlackToken();
const res = await fetch("https://slack.com/api/views.publish", {
method: "POST",
headers: {
Authorization: `Bearer ${slackToken}`,
"Content-Type": "application/json; charset=utf-8",
},
body: JSON.stringify({ user_id: userId, view }),
});
const data = await res.json();
if (!data.ok) console.error("Slack views.publish error:", JSON.stringify(data));
return { statusCode: 200, body: JSON.stringify({ ok: true }) };
return publishHomeView(userId, expanded);
}
const payments = await scanPayments();