Node.js 无法通过Slack API发布消息-获取错误';无文本';

Node.js 无法通过Slack API发布消息-获取错误';无文本';,node.js,slack-api,Node.js,Slack Api,为什么我会收到错误“no_text” 下面的Json是有效的,取自slack文档示例 在bot.postMessage(channel',params)中,如果我填充第二个参数(即用“some_text”替换“”),它将打印“some_text”,但不打印附件 bot.postMessage(频道'some_text',params)-->可以工作,但附件没有显示出来 const element = { "text": "Would you like to play a ga

为什么我会收到错误“no_text”

下面的Json是有效的,取自slack文档示例

bot.postMessage(channel',params)
中,如果我填充第二个参数(即用“some_text”替换“”),它将打印“some_text”,但不打印附件

bot.postMessage(频道'some_text',params)
-->可以工作,但附件没有显示出来

    const element = {
      "text": "Would you like to play a game?",
      "response_type": "in_channel",
      "attachments": [
          {
              "text": "Choose a game to play",
              "fallback": "If you could read this message, you'd be choosing something fun to do right now.",
              "color": "#3AA3E3",
              "attachment_type": "default",
              "callback_id": "game_selection",
              "actions": [
                  {
                      "name": "games_list",
                      "text": "Pick a game...",
                      "type": "select",
                      "options": [
                          {
                              "text": "Hearts",
                              "value": "hearts"
                          },
                          {
                              "text": "Global Thermonuclear War",
                              "value": "war"
                          }
                      ]
                  }
              ]
          }
      ]
  }

    console.log('JSON.stringify(element): '+JSON.stringify(element));
    params = {
      icon_emoji: ':r2:',
      attachments: JSON.stringify(element)
    }
    bot.postMessage(channel, '', params).always(function (data) {...}

问题是由于传递给
bot.PostMessage
的参数中缺少文本字段。你的情妇应该

params = {
  icon_emoji: ':r2:',
  text: "Would you like to play a game?",
  response_type: "in_channel",
  attachments: element
}
元素现在应该从实际的附件开始

const element = [
      {
          "text": "Choose a game to play",
          "fallback": "If you could read this message, you'd be choosing something fun to do right now.",
          "color": "#3AA3E3",
          "attachment_type": "default",
          "callback_id": "game_selection",
          "actions": [
              {
                  "name": "games_list",
                  "text": "Pick a game...",
                  "type": "select",
                  "options": [
                      {
                          "text": "Hearts",
                          "value": "hearts"
                      },
                      {
                          "text": "Global Thermonuclear War",
                          "value": "war"
                      }
                  ]
              }
          ]
      }
  ]

非常感谢。错误消失了,但当我在空闲时间运行它时,它只打印文本“你想玩游戏吗?”并且不显示下拉菜单-有什么想法吗?