node.js - 如果变量在标题中,则 Slack Dialog.open 不会打开

标签 node.js slack slack-api

每当我尝试向对话框标题添加变量时,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"

您没有收到它肯定还有其他原因。

关于node.js - 如果变量在标题中,则 Slack Dialog.open 不会打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56184394/

相关文章:

linux - 在外国计算机上使用本地命令提示符

Slack 应用程序在添加传入的 webbook 时出错

Jenkins Pipeline currentBuild 持续时间总是返回 0

javascript - 我应该如何在 javascript 中将复杂对象持久化为字符串

arrays - Mongoose如何对查询返回的对象数组进行排序

python - 通过 "0"和 Slack API 将 `slacker` 发布到 Slack channel

javascript - 代表另一个用户创建多方 channel (slack API)

slack-api - usergroups.user.update 的权限被拒绝

javascript - Socket.io 仅在两个客户端之间同步

javascript - 如何张贴提及松弛传入的 webhooks