Update a message

  • This guide details how to update existing Google Chat messages (text and cards) using the Google Chat API's update() method.

  • Two update methods are outlined: one for updating messages on behalf of a user and another for updating as the Chat app itself, each requiring specific authentication and scopes.

  • Both methods use the UpdateMessage() function but differ in the request structure and available functionalities (user updates are limited to text).

  • Comprehensive code samples are provided in multiple languages (Node.js, Python, Java, Apps Script) to illustrate message updating with user and app credentials.

  • Before updating, ensure you have a Google Workspace account, a configured Google Cloud Project, installed client libraries, and proper credentials and scopes set up.

This guide explains how to use the update() method on the Message resource of the Google Chat API to update a text or card message in a space. Update a message to change message attributes, such as what it says, or the content of a card. You can also prepend a text message to a card message, or append a card to a text message.

In the Chat API, a Chat message is represented by the Message resource. While Chat users can only send messages that contain text, Chat apps can use many other messaging features, including displaying static or interactive user interfaces, collecting information from users, and delivering messages privately. To learn more about messaging features available for the Chat API, see the Google Chat messages overview.

Prerequisites

Node.js

Python

Java

Apps Script

Update a message on behalf of a user

With user authentication, only the text of a message can be updated.

To update a message with user authentication, pass the following in your request:

  • Specify the chat.messages authorization scope.
  • Call the UpdateMessage() method.
  • Pass message as an instance of Message with the following:
    • The name field set to the message to update, which includes a space ID and a message ID.
    • The text field set with the new text.
  • Pass updateMask with the value text.

If the updated message is a card message, then the text prepends to the cards (which continue to display).

Here's how to update a message, or prepend a text message to a card message with user authentication:

Node.js

Python

Java

Apps Script

To run this sample, replace the following:

  • SPACE_NAME: the ID from the space's name. You can obtain the ID by calling the ListSpaces() method or from the space's URL.
  • MESSAGE_NAME: the ID from the message's name. You can obtain the ID from the response body returned after creating a message asynchronously with the Chat API, or with the custom name assigned to the message at creation.

The Chat API returns an instance of Message that details the message that's updated.

Update a message as the Chat app

With app authentication, both the text and the cards of a message can be updated.

To update a message with app authentication, pass the following in your request:

  • Specify the chat.bot authorization scope.
  • Call the UpdateMessage() method.
  • Pass message as an instance of Message with the following:
    • The name field set to the message to update, which includes a space ID and a message ID.
    • The text field set with the new text if it needs to be updated.
    • The cardsV2 field set with the new cards if they need to be updated.
  • Pass updateMask with the list of fields to updates such as text, and cardsV2.

If the updated message is a card message and text is updated, then the updated text prepends to the cards (which continue to display). If the updated message is a text message and cards are updated, then the updated cards append to the text (which continues to display).

Here's how to update the text and cards of a message with app authentication:

Node.js

Python

Java

Apps Script

To run this sample, replace the following:

  • SPACE_NAME: the ID from the space's name. You can obtain the ID by calling the ListSpaces() method or from the space's URL.
  • MESSAGE_NAME: the ID from the message's name. You can obtain the ID from the response body returned after creating a message asynchronously with the Chat API, or with the custom name assigned to the message at creation.

The Chat API returns an instance of Message that details the message that's updated.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.