googleapis / googleapis/google-api-nodejs-client

POST API call to Chat V1 messages not working

Offen
#3,379 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
priority: p3 type: question
Vorherrschende Sprache
TypeScript
Sterne
12.2k
Forks
2k
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
24

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
api
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
20/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.