使用Slack命令打开模态

问题描述 投票:0回答:1

我有一个显示按钮的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

当此触发器是我的按钮自动生成的东西时,我总是使用method1获得Error: invalid_trigger

方法2不会引发任何错误,但也不会打开任何模式/对话框。

官方文档不是很清楚,我不知道是否需要调用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"
      };
node.js slack slack-commands
1个回答
0
投票

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);
        });

但是最重要的是,当我们对应用程序进行某些更改时,我们需要重新安装,并且当我们进行更改时,也需要令牌[[changes,而这是我在文档中找不到的]] >

© www.soinside.com 2019 - 2024. All rights reserved.