IBM Cloud Functions/OpenWhisk Slack 包和消息附件

IBM Cloud Functions / OpenWhisk Slack package and message attachments

我正在尝试使用 IBM Cloud Functions and OpenWhisk 可用的 Slack 包。我创建了一个 Node.js 操作,它生成一个 JSON 对象,其中包含 textattachments 值。该对象按使用 Slack 包的 post 方法的顺序传递。当通过 Incoming Webhook posted 时,消息本身会显示,附件不会。为什么?需要更改什么?

return {text : "regular message text", attachments: [
       { fallback: "my fallback message",
         title: "some nice title",
         mrkdwn_in: ["text"],
         text : "Simple text"}
        ]};

动作序列是这样创建的,webhook和用户名按照文档中的步骤绑定:

ibmcloud fn action update mySequence --sequence myAction,mySlack/post

我检查了 source code for the post action,它对附件数组进行了字符串化。

最后我自己写了一个Cloud Functions action that posts statistics

// now compose the payload and post it to Slack
 var payload= {
    text : resString,
    channel : channel,
    attachments: [
       {
         fallback: "Weekly top 25 repositories",
         title: "Top 25 repositories by unique views ("+workweek+")",
         mrkdwn_in: ["text"],
         text : dataString
        }
        ]
      };

 var options = {
  method: 'POST',
  uri: webhook,
  body: payload,
  resolveWithFullResponse: true,
  json: true // Automatically stringifies the body to JSON
};

// return response to the request, so the status will be logged
return rp(options).then(function(response) {
  return response;
});

直截了当,几周以来运作良好。