payments_dashboard_pipedream/slack-app-home-p_3nC3laY/publish_home_view/entry.js
2026-03-31 23:46:11 +00:00

34 lines
No EOL
773 B
JavaScript

export default defineComponent({
props: {
slack_bot_token: {
type: "string",
label: "Slack Bot Token",
secret: true,
},
},
async run({ steps }) {
const user_id = steps.build_home_view.$return_value.user_id;
const view = steps.build_home_view.$return_value.view;
const res = await fetch("https://slack.com/api/views.publish", {
method: "POST",
headers: {
"Authorization": `Bearer ${this.slack_bot_token}`,
"Content-Type": "application/json; charset=utf-8",
},
body: JSON.stringify({
user_id,
view,
}),
});
const data = await res.json();
if (!data.ok) {
throw new Error(`Slack API error: ${JSON.stringify(data)}`);
}
return data;
},
});