Skip to content

Conversation

@PierrickVoulet
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @PierrickVoulet, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new solution for integrating with Google Chat using webhooks. It provides practical Node.js examples that demonstrate how to send both basic and threaded messages to Google Chat spaces, along with the necessary project setup for dependency management. This enables developers to quickly understand and implement webhook-based communication with Google Chat.

Highlights

  • New Webhook Chat Solution: Introduces a new webhook-chat-app solution directory containing Node.js examples for interacting with Google Chat via webhooks.
  • Basic Message Sending: Includes index.js, a Node.js script demonstrating how to send a simple text message to a Google Chat space using an incoming webhook.
  • Threaded Message Sending: Adds thread-reply.js, a Node.js script showcasing how to send messages that reply to an existing thread or initiate a new one in Google Chat.
  • Project Configuration: Provides package.json and package-lock.json to manage project dependencies, specifically node-fetch for making HTTP requests.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@PierrickVoulet PierrickVoulet merged commit dc39b4f into googleworkspace:main Dec 9, 2025
4 of 7 checks passed
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a Node.js application for sending messages to Google Chat using webhooks. The implementation has some critical security and correctness issues. Specifically, credentials are hardcoded in the source code, which is a major security risk. Additionally, there is no error handling for failed HTTP requests or for promise rejections, which can lead to application crashes and difficult debugging. I've provided suggestions to address these issues by using environment variables for credentials and adding proper error handling.

* @return {Object} response
*/
async function webhook() {
const url = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-critical critical

Hardcoding credentials, even with placeholders, is a significant security risk. It can lead to accidental exposure of sensitive data if this code is committed with real values. It's a best practice to load sensitive information from environment variables. You should also add error handling for when these environment variables are not set.

Suggested change
const url = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN"
const url = `https://chat.googleapis.com/v1/spaces/${process.env.SPACE_ID}/messages?key=${process.env.KEY}&token=${process.env.TOKEN}`

* @return {Object} response
*/
async function webhook() {
const url = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-critical critical

Hardcoding credentials, even with placeholders, is a significant security risk. It can lead to accidental exposure of sensitive data if this code is committed with real values. It's a best practice to load sensitive information from environment variables. You should also add error handling for when these environment variables are not set.

Suggested change
const url = "https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?key=KEY&token=TOKEN&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD"
const url = `https://chat.googleapis.com/v1/spaces/${process.env.SPACE_ID}/messages?key=${process.env.KEY}&token=${process.env.TOKEN}&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD}`

text: "Hello from a Node script!"
})
});
return await res.json();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation does not handle non-successful HTTP responses (e.g., 4xx, 5xx status codes). fetch only rejects on network errors, not on HTTP error statuses. If the API returns an error, res.json() will likely fail with an uninformative error if the response body is not JSON. You should check res.ok and throw a descriptive error if the request was not successful.

  if (!res.ok) {
    throw new Error(`HTTP error! status: ${res.status}, body: ${await res.text()}`);
  }
  return res.json();

return await res.json();
}

webhook().then(res => console.log(res));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The promise returned by webhook() is not being handled for rejections. If the fetch call fails (e.g., network error, or an HTTP error is thrown), it will result in an unhandled promise rejection, which can crash the Node.js process. You should add a .catch() block to handle potential errors.

webhook().then(res => console.log(res)).catch(console.error);

}
})
});
return await res.json();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation does not handle non-successful HTTP responses (e.g., 4xx, 5xx status codes). fetch only rejects on network errors, not on HTTP error statuses. If the API returns an error, res.json() will likely fail with an uninformative error if the response body is not JSON. You should check res.ok and throw a descriptive error if the request was not successful.

  if (!res.ok) {
    throw new Error(`HTTP error! status: ${res.status}, body: ${await res.text()}`);
  }
  return res.json();

return await res.json();
}

webhook().then(res => console.log(res));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The promise returned by webhook() is not being handled for rejections. If the fetch call fails (e.g., network error, or an HTTP error is thrown), it will result in an unhandled promise rejection, which can crash the Node.js process. You should add a .catch() block to handle potential errors.

webhook().then(res => console.log(res)).catch(console.error);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant