googleapis / googleapis/google-api-nodejs-client

POST API call to Chat V1 messages not working

Aperta
#3,379 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
priority: p3 type: question
Lingua principale
TypeScript
Stelle
12.2k
Fork
2k
Merge medio
1g 9h
PR unite (30g)
24

Descrizione

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](https://developers.google.com/chat/api/reference/rest/v1/spaces.messages#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](https://github.com/googleapis/google-api-nodejs-client/assets/82604276/21c88687-2055-42e9-b8d3-5e7b23115385)
but I'm not getting anything

- What code you've already tried

I've tried the following using the client

```javascript

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:

```javascript
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](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start with the linked ActionResponse documentation and compare it with the chatAppClient.spaces.messages.create call and the POST /v1/{space}/messages fetch example. Reproduce the reported “Message cannot be empty” and 400 responses, then determine the expected request behavior and document or resolve the discrepancy.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
api
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
20/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.