2

我有一个显示按钮的 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当这个触发器是我的按钮自动生成的东西时,我总是使用 method1。

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

官方文档不是很清楚,不知道需要调用dialog.open还是views.open。无论哪种方式,最后一个都不能从Slack 包中获得

这也是我在任何事情之前显示的按钮:

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"
      };
4

1 回答 1

1

从这里复制一个模态

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

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

于 2019-10-25T09:00:22.350 回答