Home chevron_right Google Workspace chevron_right Google Chat chevron_right Guides Was this helpful? Send messages to Google Chat with incoming webhooks bookmark_border Stay organized with collections Save and categorize content based on your preferences. Incoming webhooks let you send asynchronous messages into Google Chat from applications that aren’t Chat apps. For example, you can configure a monitoring application to notify on-call personnel on Google Chat when a server goes down. To asynchronously send, update, or delete a message in a Chat space with a Chat app, see Create, read, update, delete messages. ![[./resources/send-messages-to-google-chat-with-incoming-webhook.resources/arch-pat-notifier.svg]] Prerequisites To run the example in this guide, you need: PythonNode.jsApps ScriptJava Python 3.10.7 or greater. Access to the internet and a web browser. A Google Workspacehttps://workspace.google.com/features/ account with access to Google Chathttps://workspace.google.com/products/chat/. An existing Google Chat space. The httplib2 library. If necessary, run the following command-line interface (CLI) command to install the library using pip: $pip install httplib2 Create a webhook To create a webhook, register it in the Google Chat space you want to receive messages, then write a script that sends messages. Step 1: Register the incoming webhook In a web browser, open Google Chathttps://chat.google.com/. Go to the space to which you want to add a webhook. At the top, next to space title, click Down Arrow arrow_drop_down > Apps & integrations. Click Manage webhooks. If this space already has other webhooks, click Add another. Otherwise, skip this step. For Name, enter “Quickstart Webhook”. For Avatar URL, enter https://developers.google.com/chat/images/chat-product-icon.png. Click SAVE. To copy the full webhook URL, click content_copy Copy. Click outside the box to close the Incoming webhooks dialog. Step 2: Write the webhook script The example webhook script posts a message to the space in which the webhook is registered by POSTing a create message request to the webhook URL. Google Chat API responds with an instance of Message. Choose a language below for specific instructions about how to create the webhook script: PythonNode.jsApps ScriptJava In your working directory, create a file named quickstart.py. In `quickstart.py`, copy and paste the following code: python/webhook/quickstart.py View on GitHub from json import dumpsfrom httplib2 import Httpdef main(): “““Hangouts Chat incoming webhook quickstart.””” url = ‘https://chat.googleapis.com/v1/spaces/7D8la4AAAAE/messages?key=' ‘AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=’ ‘HulDviWFMz6R5FW-GwlO4INCW1cZGDDExuWVaEbbr_g%3D’ bot_message = { ’text’: ‘Hello from a Python script!’} message_headers = {‘Content-Type’: ‘application/json; charset=UTF-8’} http_obj = Http() response = http_obj.request( uri=url, method=‘POST’, headers=message_headers, body=dumps(bot_message), ) print(response)if __name__ == ‘__main__’: main() Replace the value for the `url` variable with the webhook URL you copied in Step 1: Register the incoming webhook. Step 3: Run the webhook script Run the sample by running the following command from your working directory in your CLI: PythonNode.jsApps ScriptJava $ python3 quickstart.py When you run the sample code, the webhook sends a message to the space in which you registered it. Start or reply to a message thread You can start a message thread or reply to one by adding the threadKey parameter to the webhook URL. Each threadKey is unique to the app that sets it. If two different Chat apps or webhooks set the same threadKey, two different threads start. Start a message thread To post the first message of a thread with a webhook, append the threadKey parameter to the webhook URL. Set the threadKey to an arbitrary string, but remember what it is; you’ll need to specify it again to post a reply to the thread. https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?threadKey=ARBITRARY_STRING Reply to a message thread To send a message to an existing message thread, append the threadKey parameter to the webhook URL set to the value used to start the thread. For example, sending a message to following URL posts a reply to the thread where threadKey is MY-THREAD: https://chat.googleapis.com/v1/spaces/SPACE_ID/messages?threadKey=MY-THREAD Limits and considerations As you configure webhooks, take note of these limits and considerations: Each webhook only works in the Chat space in which it's registered. You can't publish webhooks on the Google Workspace Marketplace. Webhooks aren't conversational. They can't respond to or receive messages from users or [events](https://developers.google.com/chat/api/reference/rest/v1/Event) from Google Chat. If only select [organizational unitshttps://support.google.com/a/topic/1227584](https://support.google.com/a/topic/1227584) (OUs) in your domain have [Chat apps enabledhttps://support.google.com/a/answer/7651360](https://support.google.com/a/answer/7651360), incoming webhooks return the following error: { "error": { "code": 403, "message": "The caller does not have permission", "status": "PERMISSION_DENIED" }} Incoming webhooks work in direct messages, but only when all users have [Chat apps enabledhttps://support.google.com/a/answer/7651360](https://support.google.com/a/answer/7651360). Because **![[./resources/send-messages-to-google-chat-with-incoming-webhook.resources/24px.svg]] Manage webhooks** is only available from a web browser, webhooks must be set up from the Chat web app. Webhooks are not configurable from the Chat mobile app. Was this helpful? Recommended for you REST Resource: spaces.messages Build on the Chat platform to streamline interactions and workflows across teams. Updated Mar 2, 2023 Build a Chat app with Google Cloud Functions Build on the Chat platform to streamline interactions and workflows across teams. Updated Mar 22, 2023 Authenticate and authorize Chat apps and API requests Build on the Chat platform to streamline interactions and workflows across teams. Updated Mar 22, 2023