我正在开发一个 Slack Bolt JS 应用程序,用户可以在其中批准/拒绝任务。
我正在尝试打开一个新模式(在一次 API 调用之后),它将确认任务是否完成,这给了我错误。
我需要此批准响应来比较从 api 收到的状态,因此我无法使此 api 异步。
下面是我用来打开模式以提供操作注释的代码。
// Handle selection of a pending task in the static select
app.action(
{ type: "block_actions", action_id: /^pending_task_action_(\d+)$/ },
async ({ ack, body, client }) => {
await ack();
const selectedOption = body.actions[0].selected_option.value;
const selectedApplicationId = body.actions[0].block_id;
const userEmail = body.user.name + "@mdsol.com";
try {
const selectedCategory = body.view.private_metadata;
// Open a modal with a text input for reasonm
await client.views.open({
trigger_id: body.trigger_id,
view: {
type: "modal",
callback_id: "reason_modal",
private_metadata: JSON.stringify({
selectedOption,
selectedApplicationId,
selectedCategory,
userEmail,
}),
title: {
type: "plain_text",
text: ":wave: Please comment",
},
blocks: [
{
type: "input",
block_id: "reason_input",
element: {
type: "plain_text_input",
action_id: "reason",
multiline: true,
},
label: {
type: "plain_text",
text: "Please provide comment for your action:",
},
},
],
submit: {
type: "plain_text",
text: "Submit",
},
},
});
} catch (error) {
console.error("Error handling pending task action:", error);
}
}
);
为了处理此评论,我在下面编写了代码,在这里我收到了错误。
// Handle submission of the reason modal
app.view('reason_modal', async ({ ack, body, view, client }) => {
await ack()
const viewId = view.id;
// Open a quick loading modal
await client.views.update({
view_id: viewId,
"response_action": "update",
view: {
type: "modal",
title: {
type: "plain_text",
text: ":man-biking:Processing..",
},
blocks: [
{
type: "section",
text: {
type: "plain_text",
text: ":hourglass_flowing_sand: Processing your request... ",
},
},
],
},
});
//Making One api call here
const approvalResponse = await axios.post(approvalUrl, payload, {
headers: {
"Content-Type": "application/json",
"x-api-key": process.env.X_API_KEY,
},
});
//Below Modal is returning same error.
if (approvalResponse.status == 200) {
// Update the modal with the final content
await client.views.update({
view_id: viewId,
"response_action": "update",
view: {
type: "modal",
callback_id: "modal-1",
title: {
type: "plain_text",
text: "Action Update!",
},
blocks: [
{
type: "section",
block_id: "section-1",
text: {
type: "mrkdwn",
text:"task is completed",
},
},
],
},
});
}
错误
尝试了各种方法,例如打开视图推动视图,但仍然遇到相同的错误。
同样的问题!我找不到解决方案。