0

我正在尝试从交互式 Slack 组件的 HTTP 响应中获取特定值,并将它们发布到 Google 表格的特定单元格中。

我认为我在这里遗漏了一些基本的东西,因为当我尝试按预期运行时,什么都没有发生。

实际的 JSON 字符串如下所示:(我将其在线格式化以使其更易于查看,并将敏感数据替换为 x)


{
   "parameter": {
      "payload": {
         "type": "message_action",
         "token": "xxxxxx",
         "action_ts": "1579669130.303488",
         "team": {
            "id": "xxxx",
            "domain": "xxxxxx"
         },
         "user": {
            "id": "xxxxxx",
            "name": "xxxxx"
         },
         "channel": {
            "id": "xxxxx",
            "name": "privategroup"
         },
         "callback_id": "send to sheets",
         "trigger_id": "xxxx",
         "message_ts": "1579646357.002000",
         "message": {
            "client_msg_id": "xxxxxx",
            "type": "message",
            "text": "<xxxxx> blah",
            "user": "xxxxxx",
            "ts": "1579646357.002000",
            "team": "xxxxx",
            "blocks": [

-It continues on from here-

我想要的是在“message”中获取“ts”和“user”

到目前为止,我的代码如下所示:

function doPost(e) {
  if (typeof e !== 'undefined') { 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getSheetByName('Escalations');
    var lastRow = sheet.getLastRow();

    var parsed = JSON.parse(e.postData.contents);
    var userName = parsed.parameter.payload.message.user; 
    var time = parsed.parameter.payload.message.ts; 

    var slackDetails = [time,userName]; 

    sheet.getRange(lastRow + 1,13,1,2).setValues([slackDetails]);
  }
  return ContentService.createTextOutput('thanks');
}

有人知道我在做什么错吗?

4

0 回答 0