使用Slack命令打开模式

时间:2019-10-22 14:34:48

标签: node.js slack slack-commands

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

1 个答案:

答案 0 :(得分:0)

here复制模式,

BEGIN:VCALENDAR
PRODID:-//Compnay Inc//Product Application//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:20191110T160000Z
DTEND:20191110T180000Z
DTSTAMP:20191025T083215Z
UID:cb106efc-cb70-4563-8049-246f6310e89c
CREATED:20191025T083215Z
DESCRIPTION:Seattle
LAST-MODIFIED:20191025T083215Z
LOCATION:Seattle
GEO:47.650094, -122.344233
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Test
TRANSP:OPAQUE
BEGIN:VALARM
TRIGGER:-PT24H
REPEAT:1
DURATION:PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT

但是最重要的是,当我们对应用程序进行一些更改时,我们需要重新安装,并且当我们执行此操作时,令牌也会进行更改,而这是我无法做到的在文档上找不到