如果标题中有变量,则 Slack Dialog.open 不会打开

Slack Dialog.open not Opening if Variable is in Title

每当我尝试将变量添加到我的对话框标题时,dialog.open 不起作用并且不会抛出任何错误。

如果我从标题中删除变量一切正常,只有当我将变量添加到标题时才会如此

我在定义对话框之前执行这个

app.post('/create', function(req, res) {
  var users = []
  var {
    text, trigger_id
  } = req.body;
  text = text.toUpperCase()
  var issuetypes = []
  axios({
    method: 'get',
    url: baseURL + 'project/' + text
  }).then(function(response) {
    for (var i = 0; i < response.data.issueTypes.length; i++) {
      issuetypes.push({
        label: response.data.issueTypes[i].name,
        value: response.data.issueTypes[i].name
      });
    }

无效:

const dialog = {
      token: botToken,
      trigger_id,
      dialog: JSON.stringify({
        title: 'Create a new ' + text + ' Ticket',
        callback_id: 'submit-ticket',
        submit_label: 'Submit',
        elements: [{
          label: 'Project',
          type: 'text',
          name: 'project'
        }, {
          label: 'Summary',
          type: 'text',
          name: 'summary',
        }, {
          label: 'Description',
          type: 'textarea',
          name: 'description',
          optional: true,
        }, {
          label: 'Type',
          type: 'select',
          name: 'type',
          options: issuetypes,
        }, {
          label: 'Reporter',
          type: 'select',
          name: 'reporter',
          optional: true,
          options: [{
            label: 'Reporter',
            value: 'reporter'
          }, ],
        }, {
          label: 'Link',
          type: 'select',
          name: 'epic',
          optional: true,
          options: [{
            label: 'Epic',
            value: 'epic'
          }, ],
        }, ],
      }),
    };

作品:

const dialog = {
      token: botToken,
      trigger_id,
      dialog: JSON.stringify({
        title: 'Create a new Ticket',
        callback_id: 'submit-ticket',
        submit_label: 'Submit',
        elements: [{
          label: 'Project',
          type: 'text',
          name: 'project'
        }, {
          label: 'Summary',
          type: 'text',
          name: 'summary',
        }, {
          label: 'Description',
          type: 'textarea',
          name: 'description',
          optional: true,
        }, {
          label: 'Type',
          type: 'select',
          name: 'type',
          options: issuetypes,
        }, {
          label: 'Reporter',
          type: 'select',
          name: 'reporter',
          optional: true,
          options: [{
            label: 'Reporter',
            value: 'reporter'
          }, ],
        }, {
          label: 'Link',
          type: 'select',
          name: 'epic',
          optional: true,
          options: [{
            label: 'Epic',
            value: 'epic'
          }, ],
        }, ],
      }),
    };

然后我打电话给dialog.open

axios.post("https://slack.com/api/dialog.open", qs.stringify(dialog))
      .then(
        (result) => {
          res.send('');
        }).catch(function(err) {
        console.error(err);
      })
  }).catch(function(err) {
    console.error(err);
  })
});

关于为什么 dialog.open 不起作用的任何想法?

标题中包含变量时未显示对话框的原因是您超过了标题的最大长度 24 个字符。 (参考here

不过,您应该收到来自 API 的验证错误,尽管如 dialog.open 方法的文档所述:

"The field `title` cannot be longer than 24 characters"

一定有其他原因导致您没有收到。