Method: spaces.messages.create
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Google Chat के स्पेस में मैसेज भेजता है. उदाहरण के लिए, मैसेज भेजना देखें.
पुष्टि करने के लिए, इन तरीकों का इस्तेमाल किया जा सकता है:
- अनुमति के दायरे के साथ ऐप्लिकेशन की पुष्टि:
https://www.googleapis.com/auth/chat.bot
- अनुमति के इनमें से किसी एक दायरे के साथ उपयोगकर्ता की पुष्टि:
https://www.googleapis.com/auth/chat.messages.create
https://www.googleapis.com/auth/chat.messages
https://www.googleapis.com/auth/chat.import
(सिर्फ़ इंपोर्ट मोड में स्पेस)
Chat, मैसेज भेजने वाले व्यक्ति को अलग-अलग एट्रिब्यूट देता है. यह इस बात पर निर्भर करता है कि आपने पुष्टि करने के लिए किस तरह की प्रक्रिया का इस्तेमाल किया है.
इस इमेज में दिखाया गया है कि ऐप्लिकेशन की पुष्टि करने की सुविधा का इस्तेमाल करने पर, Chat किसी मैसेज को कैसे एट्रिब्यूट करता है. Chat, मैसेज भेजने वाले के तौर पर Chat ऐप्लिकेशन को दिखाता है. मैसेज के कॉन्टेंट में टेक्स्ट (text
), कार्ड (cardsV2
), और ऐक्सेसरी विजेट (accessoryWidgets
) शामिल हो सकते हैं.

इस इमेज में दिखाया गया है कि उपयोगकर्ता की पुष्टि करने की सुविधा का इस्तेमाल करने पर, Chat किसी मैसेज को कैसे एट्रिब्यूट करता है. Chat, उपयोगकर्ता को मैसेज भेजने वाले के तौर पर दिखाता है. साथ ही, मैसेज में Chat ऐप्लिकेशन का नाम दिखाकर, उसे एट्रिब्यूट करता है. मैसेज में सिर्फ़ टेक्स्ट (text
) शामिल किया जा सकता है.

मैसेज का साइज़ 32,000 बाइट से ज़्यादा नहीं होना चाहिए. इसमें मैसेज का कॉन्टेंट भी शामिल है.
वेबहुक अनुरोधों के लिए, जवाब में पूरा मैसेज शामिल नहीं होता. जवाब में, अनुरोध में दी गई जानकारी के अलावा सिर्फ़ name
और thread.name
फ़ील्ड अपने-आप भर जाते हैं.
एचटीटीपी अनुरोध
POST https://chat.googleapis.com/v1/{parent=spaces/*}/messages
यूआरएल में gRPC ट्रांसकोडिंग सिंटैक्स का इस्तेमाल किया गया है.
पाथ पैरामीटर
पैरामीटर |
parent |
string
ज़रूरी है. उस स्पेस का नाम जिसमें मैसेज बनाना है. फ़ॉर्मैट: spaces/{space}
|
क्वेरी पैरामीटर
पैरामीटर |
threadKey (deprecated) |
string
ज़रूरी नहीं. इस्तेमाल नहीं किया जा सकता: इसके बजाय, thread.thread_key का इस्तेमाल करें. थ्रेड का आईडी. इसमें ज़्यादा से ज़्यादा 4,000 वर्ण डाले जा सकते हैं. कोई थ्रेड शुरू करने या उसमें मैसेज जोड़ने के लिए, कोई मैसेज लिखें और threadKey या thread.name डालें. इसका इस्तेमाल करने के उदाहरण के लिए, मैसेज थ्रेड शुरू करना या उसका जवाब देना देखें.
|
requestId |
string
ज़रूरी नहीं. इस मैसेज के लिए यूनीक अनुरोध आईडी. किसी मौजूदा अनुरोध आईडी की जानकारी देने पर, नया मैसेज बनाने के बजाय, उस आईडी से बनाया गया मैसेज दिखता है.
|
messageReplyOption |
enum (MessageReplyOption )
ज़रूरी नहीं. इससे पता चलता है कि कोई मैसेज, थ्रेड शुरू करता है या किसी थ्रेड का जवाब देता है. यह सुविधा सिर्फ़ नाम वाले स्पेस में काम करती है. उपयोगकर्ता के इंटरैक्शन का जवाब देते समय, इस फ़ील्ड को अनदेखा कर दिया जाता है. किसी थ्रेड में इंटरैक्शन करने पर, जवाब उसी थ्रेड में बनाया जाता है. ऐसा न करने पर, जवाब एक नई थ्रेड के तौर पर बन जाता है.
|
messageId |
string
ज़रूरी नहीं. मैसेज के लिए कस्टम आईडी. इससे Chat ऐप्लिकेशन, मैसेज के रिसॉर्स के नाम (मैसेज के name फ़ील्ड में दिखाया गया) में, सिस्टम से असाइन किया गया आईडी सेव किए बिना, मैसेज को ऐक्सेस, अपडेट या मिटा सकते हैं. इस फ़ील्ड की वैल्यू इन ज़रूरी शर्तों के मुताबिक होनी चाहिए:
client- से शुरू होता है. उदाहरण के लिए, client-custom-name एक मान्य कस्टम आईडी है, लेकिन custom-name नहीं.
- इसमें ज़्यादा से ज़्यादा 63 वर्ण हो सकते हैं. साथ ही, इसमें सिर्फ़ अंग्रेज़ी के छोटे अक्षर, संख्याएं, और हाइफ़न का इस्तेमाल किया जा सकता है.
- स्पेस में यूनीक हो. कोई चैट ऐप्लिकेशन, अलग-अलग मैसेज के लिए एक ही कस्टम आईडी का इस्तेमाल नहीं कर सकता.
ज़्यादा जानकारी के लिए, मैसेज का नाम देना लेख पढ़ें.
|
अनुरोध का मुख्य भाग
अनुरोध के मुख्य भाग में Message
का उदाहरण है.
जवाब का मुख्य भाग
कामयाब रहने पर, जवाब के मुख्य हिस्से में Message
का नया इंस्टेंस शामिल किया जाता है.
अनुमति के दायरे
इसके लिए, OAuth के इनमें से किसी एक स्कोप की ज़रूरत होती है:
https://www.googleapis.com/auth/chat.bot
https://www.googleapis.com/auth/chat.import
https://www.googleapis.com/auth/chat.messages
https://www.googleapis.com/auth/chat.messages.create
ज़्यादा जानकारी के लिए, अनुमति से जुड़ी गाइड देखें.
MessageReplyOption
किसी मैसेज का जवाब देने का तरीका बताता है. आने वाले समय में, अन्य राज्यों में भी यह सुविधा उपलब्ध कराई जा सकती है.
Enums |
MESSAGE_REPLY_OPTION_UNSPECIFIED |
डिफ़ॉल्ट. नई थ्रेड शुरू करता है. इस विकल्प का इस्तेमाल करने पर, शामिल किए गए किसी भी thread ID या threadKey को अनदेखा कर दिया जाता है. |
REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD |
thread ID या threadKey से चुनी गई थ्रेड के जवाब के तौर पर मैसेज बनाता है. अगर ऐसा नहीं होता है, तो मैसेज की नई थ्रेड शुरू हो जाती है. |
REPLY_MESSAGE_OR_FAIL |
thread ID या threadKey से तय की गई थ्रेड के जवाब के तौर पर मैसेज बनाता है. अगर किसी नए threadKey का इस्तेमाल किया जाता है, तो एक नई थ्रेड बन जाती है. अगर मैसेज नहीं बन पाता है, तो NOT_FOUND गड़बड़ी का मैसेज दिखता है. |
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-07-25 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-07-25 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eCreates a message in a Google Chat space, attributing it to the Chat app or user based on authentication.\u003c/p\u003e\n"],["\u003cp\u003eSupports sending text, cards, and widgets using app authentication, while user authentication only allows text.\u003c/p\u003e\n"],["\u003cp\u003eOffers different message reply options for starting new threads or replying within existing ones.\u003c/p\u003e\n"],["\u003cp\u003eRequires specific authorization scopes for the request, such as \u003ccode\u003echat.bot\u003c/code\u003e or \u003ccode\u003echat.messages\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eProvides a way to name a message with a custom ID for easy retrieval and management within a space.\u003c/p\u003e\n"]]],["This document outlines the process for creating messages in Google Chat spaces via the `create()` method, using either user or app authentication. Messages can include text, cards, and widgets, with a maximum size of 32,000 bytes. The process involves a POST request to a specified URL with path parameters for the space and query parameters like `threadKey`, `requestId`, `messageReplyOption` and `messageId`. The request body defines the message content, and the successful response returns the new message details. It also specifies the required OAuth scopes.\n"],null,["# Method: spaces.messages.create\n\n- [HTTP request](#body.HTTP_TEMPLATE)\n- [Path parameters](#body.PATH_PARAMETERS)\n- [Query parameters](#body.QUERY_PARAMETERS)\n- [Request body](#body.request_body)\n- [Response body](#body.response_body)\n- [Authorization scopes](#body.aspect)\n- [MessageReplyOption](#MessageReplyOption)\n- [Try it!](#try-it)\n\nCreates a message in a Google Chat space. For an example, see [Send a message](https://developers.google.com/workspace/chat/create-messages).\n\nSupports the following types of [authentication](https://developers.google.com/workspace/chat/authenticate-authorize):\n\n- [App authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app) with the authorization scope:\n - `https://www.googleapis.com/auth/chat.bot`\n- [User authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user) with one of the following authorization scopes:\n - `https://www.googleapis.com/auth/chat.messages.create`\n - `https://www.googleapis.com/auth/chat.messages`\n - `https://www.googleapis.com/auth/chat.import` (import mode spaces only)\n\nChat attributes the message sender differently depending on the type of authentication that you use in your request.\n\nThe following image shows how Chat attributes a message when you use app authentication. Chat displays the Chat app as the message sender. The content of the message can contain text (`text`), cards (`cardsV2`), and accessory widgets (`accessoryWidgets`).\n\nThe following image shows how Chat attributes a message when you use user authentication. Chat displays the user as the message sender and attributes the Chat app to the message by displaying its name. The content of message can only contain text (`text`).\n\nThe maximum message size, including the message contents, is 32,000 bytes.\n\nFor [webhook](https://developers.google.com/workspace/chat/quickstart/webhooks) requests, the response doesn't contain the full message. The response only populates the `name` and `thread.name` fields in addition to the information that was in the request.\n\n### HTTP request\n\n`POST https://chat.googleapis.com/v1/{parent=spaces/*}/messages`\n\nThe URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.\n\n### Path parameters\n\n| Parameters ||\n|----------|----------------------------------------------------------------------------------------------------------|\n| `parent` | `string` Required. The resource name of the space in which to create a message. Format: `spaces/{space}` |\n\n### Query parameters\n\n| Parameters ||\n|------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `threadKey` **(deprecated)** | `string` Optional. Deprecated: Use [thread.thread_key](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.thread_key) instead. ID for the thread. Supports up to 4000 characters. To start or add to a thread, create a message and specify a `threadKey` or the [thread.name](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.name). For example usage, see [Start or reply to a message thread](https://developers.google.com/workspace/chat/create-messages#create-message-thread). |\n| `requestId` | `string` Optional. A unique request ID for this message. Specifying an existing request ID returns the message created with that ID instead of creating a new message. |\n| `messageReplyOption` | `enum (`[MessageReplyOption](/workspace/chat/api/reference/rest/v1/spaces.messages/create#MessageReplyOption)`)` Optional. Specifies whether a message starts a thread or replies to one. Only supported in named spaces. When [responding to user interactions](https://developers.google.com/workspace/chat/receive-respond-interactions), this field is ignored. For interactions within a thread, the reply is created in the same thread. Otherwise, the reply is created as a new thread. |\n| `messageId` | `string` Optional. A custom ID for a message. Lets Chat apps get, update, or delete a message without needing to store the system-assigned ID in the message's resource name (represented in the message `name` field). The value for this field must meet the following requirements: - Begins with `client-`. For example, `client-custom-name` is a valid custom ID, but `custom-name` is not. - Contains up to 63 characters and only lowercase letters, numbers, and hyphens. - Is unique within a space. A Chat app can't use the same custom ID for different messages. For details, see [Name a message](https://developers.google.com/workspace/chat/create-messages#name_a_created_message). |\n\n### Request body\n\nThe request body contains an instance of [Message](/workspace/chat/api/reference/rest/v1/spaces.messages#Message).\n\n### Response body\n\nIf successful, the response body contains a newly created instance of [Message](/workspace/chat/api/reference/rest/v1/spaces.messages#Message).\n\n### Authorization scopes\n\nRequires one of the following OAuth scopes:\n\n- `https://www.googleapis.com/auth/chat.bot`\n- `https://www.googleapis.com/auth/chat.import`\n- `https://www.googleapis.com/auth/chat.messages`\n- `https://www.googleapis.com/auth/chat.messages.create`\n\nFor more information, see the [Authorization guide](/workspace/chat/authenticate-authorize).\n\nMessageReplyOption\n------------------\n\nSpecifies how to reply to a message. More states might be added in the future.\n\n| Enums ||\n|----------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `MESSAGE_REPLY_OPTION_UNSPECIFIED` | Default. Starts a new thread. Using this option ignores any [thread ID](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.name) or [`threadKey`](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.thread_key) that's included. |\n| `REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD` | Creates the message as a reply to the thread specified by [thread ID](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.name) or [`threadKey`](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.thread_key). If it fails, the message starts a new thread instead. |\n| `REPLY_MESSAGE_OR_FAIL` | Creates the message as a reply to the thread specified by [thread ID](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.name) or [`threadKey`](/workspace/chat/api/reference/rest/v1/spaces.messages#Message.Thread.FIELDS.thread_key). If a new `threadKey` is used, a new thread is created. If the message creation fails, a `NOT_FOUND` error is returned instead. |"]]