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

时间:2018-10-18 08:57:09

标签: node.js ibm-cloud slack openwhisk ibm-cloud-functions

我正在尝试使用IBM Cloud FunctionsOpenWhisk可用的Slack软件包。我创建了一个Node.js操作,该操作生成具有 text attachments 值的JSON对象。该对象按顺序使用Slack包的post方法传递。通过传入的Webhook发布消息时会显示消息本身,而不会显示附件。为什么?需要更改什么?

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,它对附件数组进行了字符串化处理。

1 个答案:

答案 0 :(得分:-1)

我最终自己写了一个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;
});

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