googleapis / google-api-nodejs-client

Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
https://googleapis.dev/nodejs/googleapis/latest/
Apache License 2.0
11.27k stars 1.91k forks source link

POST API call to Chat V1 messages not working #3379

Open andresrguzman opened 8 months ago

andresrguzman commented 8 months ago

Thanks for stopping by to ask us a question! Please make sure to include:

Trying to follow documentation in how to request extra configurations to the user, I'm following the docs to use ActionResponse but when I use the client I get Error: Message cannot be empty. and if I try the API using fetch I get 400 Bad Request. Hoping I get this image but I'm not getting anything

I've tried the following using the client


   import { chat, auth } from '@googleapis/chat';

   const googleAppAuth = new auth.GoogleAuth({
     // Specify required scopes.
     scopes: ['https://www.googleapis.com/auth/chat.bot'],
   });
   const chatAppClient = await chat({
      version: 'v1',
      auth: googleAppAuth,
   });

    chatAppClient.spaces.messages.create({
        parent: space,
        requestBody: {
          actionResponse: {
            type: 'REQUEST_CONFIG',
            url: 'https://google.com',
          },
        },
      });

and using raw api call:

    const token = await googleAppAuth.getAccessToken();
    console.log(await fetchEndPoint(`https://chat.googleapis.com/v1/${eventData.space?.name}/messages`, {
      body: JSON.stringify({
        actionResponse: {
          type: 'REQUEST_CONFIG',
          url: 'https://google.com',
        },
      }),
      method: 'POST',
      headers: {
        Authorization: `Bearer ${token!}`,
      },
    }));

googleAppAuth is using ADC with the chat scope.

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.