0

我正在尝试在模式内实现依赖外部选择,但在将第一个下拉列表的状态传递给第二个时遇到问题。我可以在 app.action 监听器中看到我需要的状态,但我在 app.options 监听器中没有得到相同的状态。

app.action("case_types") 中的 body.view.state。我特别需要 case_create_case_type_block 状态。

  "state": {
    "values": {
      "case_create_user_select_block": {
        "case_create_selected_user": {
          "type": "users_select",
          "selected_user": "U01R3AE65GE"
        }
      },
      "case_create_case_type_block": {
        "case_types": {
          "type": "external_select",
          "selected_option": {
            "text": { "type": "plain_text", "text": "Incident", "emoji": true },
            "value": "Incident"
          }
        }
      },
      "case_create_case_subtype_block": {
        "case_subtypes": { "type": "external_select", "selected_option": null }
      },
      "case_create_case_owner_block": {
        "case_owners": { "type": "external_select", "selected_option": null }
      },
      "case_create_subject_block": {
        "case_create_case_subject": {
          "type": "plain_text_input",
          "value": null
        }
      },
      "case_create_description_block": {
        "case_create_case_description": {
          "type": "plain_text_input",
          "value": null
        }
      }
    }
  },

app.options("case_subtypes") 中的 body.view.state

  "state": {
    "values": {
      "case_create_user_select_block": {
        "case_create_selected_user": {
          "type": "users_select",
          "selected_user": "U01R3AE65GE"
        }
      }
    }
  },

我也尝试自己更新视图,希望它能更新 app.action({ action_id: "case_types" }) 中的状态变量

    //need to update view with new values
    try {
      // Call views.update with the built-in client
      const result = await client.views.update({
        // Pass the view_id
        view_id: body.view.id,
        // Pass the current hash to avoid race conditions
        hash: body.view.hash,
      });
      console.log("Case Type View Update result:");
      console.log(JSON.stringify(result));

      //await ack();
    } catch (error) {
      console.error(error);
      //await ack();
    }
4

1 回答 1

0

我最终在 github 问题页面上发布了这个 slack bolt。这是一个将在未来版本中修复的错误。以下是使用私有元数据来保存状态以检查未来相关下拉列表的解决方法。

// Action handler for case type
app.action('case_type_action_id', async ({ ack, body, client }) => {
  try {
    // Create a copy of the modal view template and update the private metadata
    // with the selected case type from the first external select
    const viewTemplate = JSON.parse(JSON.stringify(modalViewTemplate))
    viewTemplate.private_metadata = JSON.stringify({
      case_type: body.view.state.values['case_type_block_id']['case_type_action_id'].selected_option.value,
    });

    // Call views.update with the built-in client
    const result = await client.views.update({
      // Pass the view_id
      view_id: body.view.id,
      // Pass the current hash to avoid race conditions
      hash: body.view.hash,
      // Pass the updated view
      view: viewTemplate,
    });
    console.log(JSON.stringify(result, 0, 2));
  } catch (error) {
    console.error(error);
  }

  await ack();
});

// Options handler for case subtype
app.options('case_subtype_action_id', async ({ body, options, ack }) => {
  try {
    // Get the private metadata that stores the selected case type
    const privateMetadata = JSON.parse(body.view.private_metadata);

    // Continue to render the case subtype options based on the case type
    // ...
  } catch (error) {
    console.error(error);
  }
});

在此处查看完整说明:https ://github.com/slackapi/bolt-js/issues/1146

于 2021-10-15T18:10:30.773 回答