【问题标题】:IBM Cloud Functions / OpenWhisk Slack package and message attachmentsIBM Cloud Functions / OpenWhisk Slack 包和消息附件
【发布时间】:2019-03-23 01:15:03
【问题描述】:

我正在尝试使用适用于 IBM Cloud FunctionsOpenWhisk 的 Slack 包。我创建了一个 Node.js 操作,它生成一个带有 textattachments 值的 JSON 对象。该对象以使用 Slack 包的 post 方法的顺序传递。消息本身在通过 Incoming 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,它对附件数组进行了字符串化。

【问题讨论】:

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


    【解决方案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;
    });
    

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

    【讨论】:

      猜你喜欢
      • 2019-04-27
      • 2016-07-05
      • 2018-08-05
      • 2018-12-07
      • 2021-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      相关资源
      最近更新 更多