mirror of
https://github.com/Sea-Haven-Industries/payments-dashboard.git
synced 2026-10-07 12:49:02 +00:00
Share Slack home publish pipeline
Co-authored-by: Adam Moussa <amoussa1229@users.noreply.github.com>
This commit is contained in:
parent
8073eb3662
commit
44e46a1fd0
1 changed files with 7 additions and 23 deletions
|
|
@ -146,6 +146,10 @@ export const handler = async (event) => {
|
||||||
|
|
||||||
const userId = body.event.user;
|
const userId = body.event.user;
|
||||||
|
|
||||||
|
return publishHomeView(userId, []);
|
||||||
|
};
|
||||||
|
|
||||||
|
async function publishHomeView(userId, expanded) {
|
||||||
const { Item: metadata } = await ddb.send(
|
const { Item: metadata } = await ddb.send(
|
||||||
new GetCommand({ TableName: TABLE_NAME, Key: { pk: "metadata" } })
|
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" }) };
|
return { statusCode: 200, body: JSON.stringify({ error: "No payment data" }) };
|
||||||
}
|
}
|
||||||
|
|
||||||
const expanded = [];
|
|
||||||
const view = buildHomeView(payments, metadata, boaTransactions, expanded);
|
const view = buildHomeView(payments, metadata, boaTransactions, expanded);
|
||||||
const slackToken = await getSlackToken();
|
const slackToken = await getSlackToken();
|
||||||
|
|
||||||
|
|
@ -180,7 +183,7 @@ export const handler = async (event) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return { statusCode: 200, body: JSON.stringify({ ok: true }) };
|
return { statusCode: 200, body: JSON.stringify({ ok: true }) };
|
||||||
};
|
}
|
||||||
|
|
||||||
// --- Block action handler (button clicks) ---
|
// --- Block action handler (button clicks) ---
|
||||||
|
|
||||||
|
|
@ -195,32 +198,13 @@ async function handleBlockAction(body) {
|
||||||
if (actionId.startsWith("toggle_section_")) {
|
if (actionId.startsWith("toggle_section_")) {
|
||||||
const section = actionId.replace("toggle_section_", "");
|
const section = actionId.replace("toggle_section_", "");
|
||||||
const meta = JSON.parse(body.view?.private_metadata || "{}");
|
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);
|
const idx = expanded.indexOf(section);
|
||||||
if (idx >= 0) expanded.splice(idx, 1);
|
if (idx >= 0) expanded.splice(idx, 1);
|
||||||
else expanded.push(section);
|
else expanded.push(section);
|
||||||
|
|
||||||
const userId = body.user?.id;
|
const userId = body.user?.id;
|
||||||
const { Item: metadata } = await ddb.send(
|
return publishHomeView(userId, expanded);
|
||||||
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 }) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const payments = await scanPayments();
|
const payments = await scanPayments();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue