google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

POST API call to Chat V1 messages not working

Open andresrguzman opened this issue 2 years ago • 0 comments

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

  • What you're trying to do

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

  • What code you've already tried

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.

  • Any error messages you're getting

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.

andresrguzman avatar Oct 26 '23 18:10 andresrguzman