2016-03-02 66 views
4

我正在使用botkit by howdy爲api調用postMessage方法。當我傳遞附件屬性時,它給我invalid_array_arg錯誤。它獲取POST的方式有問題Slackbot附件 - 有什麼問題嗎?

bot.api.chat.postMessage(
     { 
      channel : '#general', 
      text : 'hi', 
      parse : true, 
      username: '@' + bot.identity.name, 
      as_user : true, 
      icon_url: listOfMessages.logoUrl, 
      attachments: [{"pretext": "pre-hello", "text": "text-world"}] 

     }, function (err,res) { 
      if(err) console.log(err); 
      console.log(res); 
     } 
    ); 
+0

來自Slack文檔的錯誤消息:'該方法傳遞了一個PHP風格的數組參數(例如,名稱爲foo [7])。這些從來都不適用於Slack API.' [Link](https://api.slack.com/methods/chat.postMessage) –

回答

14

我遇到了同樣的問題,並通過對數組進行了字符串化處理。

attachments: JSON.stringify([{"pretext": "pre-hello", "text": "text-world"}]) 
+2

在ruby slack-api gem中有同樣的問題。 重要的是對整個附件數組轉換成JSON,不只是在附件中,例如所述對象: '附件:[附件] .to_json' – andrewleung

+0

它實際上是注意到作爲[鬆弛API的一部分文檔](https://api.slack.com/methods/chat.update):「_可選附件參數應該包含一個JSON編碼的附件數組......」 –

+0

但https://api.slack.com /methods/chat.postMessage/test這也不起作用,需要添加附件才能添加文本,這些文本僅在短文中發佈文本 – sunil