簡體   English   中英

如何從 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

解決方案非常簡單。 我忘記了為了讀取這里指定的fetch的內容,我需要調用

const resJson = await response.json()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM