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 ไบต์
สําหรับคําขอ webhook การตอบกลับจะไม่มีข้อความทั้งหมด การตอบกลับจะป้อนข้อมูลในช่อง name
และ thread.name
เท่านั้น นอกเหนือจากข้อมูลที่อยู่ในคำขอ
คำขอ HTTP
POST https://chat.googleapis.com/v1/{parent=spaces/*}/messages
URL ใช้ไวยากรณ์การแปลง 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 ตัวและประกอบด้วยตัวอักษรพิมพ์เล็ก ตัวเลข และขีดกลางเท่านั้น
- ไม่ซ้ำกันภายในพื้นที่ทำงาน แอป Chat ใช้รหัสที่กำหนดเองเดียวกันกับข้อความที่แตกต่างกันไม่ได้
โปรดดูรายละเอียดที่หัวข้อตั้งชื่อข้อความ
|
เนื้อความของคำขอ
เนื้อความของคำขอมีอินสแตนซ์ของ 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
ระบุวิธีตอบกลับข้อความ ในอนาคตเราอาจเพิ่มรัฐอื่นๆ เข้ามาอีก
Enum |
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 แทน |
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 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. |"]]