如何从 google-chat webhook 获取响应数据?

How to get response data from google-chat webhook?

我正在遵循以下示例:

const fetch = require('node-fetch');

const webhookURL = '<INCOMING-WEBHOOK-URL>';

const data = JSON.stringify({
  'text': 'Hello from a Node script!',
});

fetch(webhookURL, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json; charset=UTF-8',
  },
  body: data,
}).then((response) => {
  console.log(response);
});

就所有意图和目的而言,我的代码本质上是相同的。

根据 API 响应主体应该是 Message 类型,但我得到的是:

Response {
  size: 0,
  timeout: 0,
  [Symbol(Body internals)]: {
    body: Gunzip {
      _writeState: [Uint32Array],
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      bytesWritten: 0,
      _handle: [Zlib],
      _outBuffer: <Buffer 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 00 48 02 15 01 00 00 00 05 00 04 00 04 00 04 00 38 2f 01 15 01 00 00 00 30 46 01 15 01 00 00 00 1e 1e ... 16334 more bytes>,
      _outOffset: 0,
      _chunkSize: 16384,
      _defaultFlushFlag: 2,
      _finishFlushFlag: 2,
      _defaultFullFlushFlag: 3,
      _info: undefined,
      _maxOutputLength: 4294967295,
      _level: -1,
      _strategy: 0,
      [Symbol(kCapture)]: false,
      [Symbol(kTransformState)]: [Object],
      [Symbol(kError)]: null
    },
    disturbed: false,
    error: null
  },
  [Symbol(Response internals)]: {
    url: <my webhook url>,
    status: 200,
    statusText: 'OK',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }
}

我不确定如何处理此数据以将其读取为所需的消息类型,如 API 文档中所述。任何帮助将不胜感激!

供参考:https://developers.google.com/chat/reference/rest/v1/spaces/webhooks

解决方案非常简单。 我忘了为了按照指定 here 读取 fetch 的内容,我需要调用

const resJson = await response.json()