使用 Slack 命令打开模态

Open modal using Slack command

我有一个显示按钮的 Slack 命令。当我点击这个按钮时,我需要显示一个模式。为此,单击它后我这样做:

const dialog = {
  callback_id: "submit-ticket",
  elements: [
    {
      hint: "30 second summary of the problem",
      label: "Title",
      name: "title",
      type: "text",
      value: "teste"
    },
    {
      label: "Description",
      name: "description",
      optional: true,
      type: "textarea"
    },
    {
      label: "Urgency",
      name: "urgency",
      options: [
        { label: "Low", value: "Low" },
        { label: "Medium", value: "Medium" },
        { label: "High", value: "High" }
      ],
      type: "select"
    }
  ],
  submit_label: "Submit",
  title: "Submit a helpdesk ticket"
};

const modalInfo = {
    dialog: JSON.stringify(dialog),
    token, // this is correct
    trigger_id: actionJSONPayload.trigger_id
  };


  // This is what I get confused with...

  // Method 1
  slack.dialog.open(modalInfo).catch(err => {
    console.log("ERROR: ", err);
  });
  // end method 1

  // Method 2
  sendMessageToSlackResponseURL(actionJSONPayload.response_url, modalInfo);

...

function sendMessageToSlackResponseURL(responseURL: any, JSONmessage: any) {
  const postOptions = {
    headers: {
      "Content-type": "application/json"
    },
    json: JSONmessage,
    method: "POST",
    uri: responseURL
  };
  request(postOptions, (error: any, response: any, body: any) => {
    if (error) {
      console.log("----Error: ", error);
    }
  });
}
// end method 2

当这个触发器是我的按钮自动生成的东西时,我总是 Error: invalid_trigger 使用方法 1。

方法 2 不会抛出任何错误,但也不会打开任何 modal/dialog。

官方文档写的不是很清楚,不知道需要调用dialog.open还是views.open。无论哪种方式,最后一个都无法从 Slack package

获得

这也是我之前显示的按钮:

const message = {
        attachments: [
          {
            actions: [
              {
                name: "send_sms",
                style: "danger",
                text: "Yes",
                type: "button",
                value: "yes"
              },
              {
                name: "no",
                text: "No",
                type: "button",
                value: "no"
              }
            ],
            attachment_type: "default",
            callback_id: "alert",
            color: "#3AA3E3",
            fallback: "We could not load the options. Try later",
            text: "Do you want to alert by SMS about P1 error/fix?"
          }
        ],
        text: "P1 SMSs"
      };

here

复制模态
const headers = {
  headers: {
    "Content-type": "application/json; charset=utf-8",
    "Authorization": "Bearer " + token
  }
};

const modalInfo = {
        "token": token,
        "trigger_id": reqBody.trigger_id,
        "view": slack.modal
      };

      axios
        .post("https://slack.com/api/views.open", modalInfo, headers)
        .then(response => {
          const data = response.data;
          if (!data.ok) {
            return data.error;
          }
        })
        .catch(error => {
          console.log("-Error: ", error);
        });

但最重要的是,当我们对我们的应用程序进行一些更改时,我们需要重新安装它,而且当我们这样做时,令牌更改 这是我在文档中找不到的东西