代码之家  ›  专栏  ›  技术社区  ›  data_henrik

ibmcloud函数/OpenWhisk Slack包和消息附件

  •  0
  • data_henrik  · 技术社区  · 6 年前

    我正在尝试使用可用于 IBM Cloud Functions OpenWhisk 文本 附件 价值观。对象以使用Slack包的post方法的顺序传递。当通过传入的Webhook发布消息时,会显示消息本身,而不会显示附件。为什么?需要改变什么?

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

    操作序列是这样创建的,webhook和username按照文档中的步骤绑定:

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

    source code for the post action 它将附件数组字符串化。

    1 回复  |  直到 6 年前
        1
  •  0
  •   data_henrik    6 年前

    最后我一个人写了一段时间 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;
    });