الحصول على تفاصيل حول حالة قراءة سلسلة محادثات أحد المستخدمين
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يوضّح هذا الدليل كيفية استخدام الأسلوب
get()
في مورد ThreadReadState من Google Chat API للحصول على تفاصيل
حول حالة قراءة المستخدم ضمن سلسلة محادثات. للاطّلاع على حالة قراءة
رسالة في مساحة، يُرجى الاطّلاع على مقالة
الحصول على تفاصيل عن حالة قراءة مساحة أحد المستخدمين.
مورد ThreadReadState
هو مورد وحيد يمثّل تفاصيل عن
آخر رسالة قرأها مستخدم محدّد في سلسلة رسائل Google Chat.
أنشئ بيانات اعتماد معرِّف عميل OAuth لتطبيق كمبيوتر مكتبي. لتنفيذ العيّنة الواردة في
هذا الدليل، احفظ بيانات الاعتماد كملف JSON باسم credentials.json في
الدليل المحلي.
الحصول على حالة قراءة سلسلة المحادثات الخاصة بالمستخدم المتصل
للحصول على تفاصيل حول حالة قراءة المستخدم ضمن سلسلة محادثات، أدرِج ما يلي في طلبك:
حدِّد نطاق التفويض chat.users.readstate أو chat.users.readstate.readonly.
يمكنك استدعاء الأسلوب
GetThreadReadState()
، مع تمرير name لحالة قراءة سلسلة المحادثات للحصول على name التي تتضمّن
معرّف مستخدم أو اسم بديل ومعرّف مساحة. لا يتيح الحصول على حالة قراءة سلسلة المحادثات سوى قراءة حالة قراءة المستخدم المتصل، ويمكن تحديدها من خلال ضبط أحد الخيارَين التاليَين:
الاسم المستعار me على سبيل المثال:
users/me/spaces/SPACE/threads/THREAD/threadReadState.
عنوان البريد الإلكتروني في Workspace للمستخدم المتصل على سبيل المثال:
users/user@example.com/spaces/SPACE/threads/THREAD/threadReadState.
رقم تعريف المستخدم المتصل. على سبيل المثال:
users/USER/spaces/SPACE/threads/THREAD/threadReadState.
يحصل المثال التالي على حالة قراءة سلسلة المحادثات الخاصة بالمستخدم المتصل:
import{createClientWithUserCredentials}from'./authentication-utils.js';constUSER_AUTH_OAUTH_SCOPES=['https://www.googleapis.com/auth/chat.users.readstate.readonly'];// This sample shows how to get the thread read state for a space and calling userasyncfunctionmain(){// Create a clientconstchatClient=awaitcreateClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);// Initialize request argument(s)constrequest={// Replace SPACE_NAME and THREAD_NAME herename:'users/me/spaces/SPACE_NAME/threads/THREAD_NAME/threadReadState'};// Make the requestconstresponse=awaitchatClient.getThreadReadState(request);// Handle the responseconsole.log(response);}main().catch(console.error);
لتشغيل هذا العيّنة، استبدِل ما يلي:
SPACE_NAME: رقم التعريف من
name المساحة
يمكنك الحصول على المعرّف من خلال استدعاء الوسيطة
ListSpaces()
أو من عنوان URL للمساحة.
THREAD_NAME: رقم التعريف من
name سلسلة المحادثات
يمكنك الحصول على رقم التعريف من نص الاستجابة الذي يتم إرجاعه بعد إنشاء
رسالة بشكل غير متزامن باستخدام Chat API، أو باستخدام
الاسم المخصّص
الذي تمّ تعيينه للرسالة عند إنشائها.
تحصل Google Chat API على حالة قراءة سلسلة المحادثات المحدّدة وتُرجِع
مثيلًا من
ThreadReadState.
تاريخ التعديل الأخير: 2025-05-30 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-05-30 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis guide explains how to use the \u003ccode\u003eget()\u003c/code\u003e method to retrieve a user's read state within a Google Chat message thread using the Google Chat API.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eThreadReadState\u003c/code\u003e resource provides details about a user's last read message in a thread.\u003c/p\u003e\n"],["\u003cp\u003eTo get the thread read state, you need a Google Workspace account, a configured Google Cloud project with the Google Chat API enabled, and the Node.js Cloud Client Library installed.\u003c/p\u003e\n"],["\u003cp\u003eYou must use the \u003ccode\u003echat.users.readstate\u003c/code\u003e or \u003ccode\u003echat.users.readstate.readonly\u003c/code\u003e authorization scope and call the \u003ccode\u003eGetThreadReadState()\u003c/code\u003e method, specifying the thread read state's name.\u003c/p\u003e\n"],["\u003cp\u003eThe API returns a \u003ccode\u003eThreadReadState\u003c/code\u003e instance containing the user's read state information.\u003c/p\u003e\n"]]],["This guide details retrieving a user's read state within a Google Chat message thread using the `get()` method on the `ThreadReadState` resource. Key actions involve setting up a Google Cloud project, enabling the Chat API, and obtaining OAuth credentials. The process requires specifying either the `chat.users.readstate` or `chat.users.readstate.readonly` authorization scope, then calling `GetThreadReadState()` with the thread read state's `name`, including a user ID/alias and space ID. The method returns a `ThreadReadState` instance.\n"],null,["# Get details about a user's thread read state\n\nThis guide explains how to use the\n[`get()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetThreadReadState)\nmethod on the `ThreadReadState` resource of the Google Chat API to get details\nabout a user's read state within a message thread. To get the read state of a\nmessage in a space, see\n[Get details about a user's space read state](/workspace/chat/get-space-read-state).\n\nThe\n[`ThreadReadState` resource](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ThreadReadState)\nis a singleton resource that represents details about a\nspecified user's last read message in a Google Chat message thread.\n\nPrerequisites\n-------------\n\n\n### Node.js\n\n- A Business or Enterprise [Google Workspace](https://support.google.com/a/answer/6043576) account with access to [Google Chat](https://workspace.google.com/products/chat/).\n\n\u003c!-- --\u003e\n\n- Set up your environment:\n - [Create a Google Cloud project](/workspace/guides/create-project).\n - [Configure the OAuth consent screen](/workspace/guides/configure-oauth-consent).\n - [Enable and configure the Google Chat API](/workspace/chat/configure-chat-api) with a name, icon, and description for your Chat app.\n - Install the Node.js [Cloud Client Library](/workspace/chat/libraries?tab=nodejs#cloud-client-libraries).\n - [Create OAuth client ID credentials](/workspace/chat/authenticate-authorize-chat-user#step-2:) for a desktop application. To run the sample in this guide, save the credentials as a JSON file named `credentials.json` to your local directory.\n\n For guidance, complete the steps for setting up your environment in this [quickstart](/workspace/chat/api/guides/quickstart/nodejs\n #set-up-environment).\n- [Choose an authorization scope](/workspace/chat/authenticate-authorize#asynchronous-chat-calls) that supports user authentication.\n\n\n| The code samples in this page use the gRPC API interface with the Google Cloud client libraries. Alternatively, you can use the REST API interface. For more information about the gRPC and REST interfaces, see [Google Chat API overview](/workspace/chat/api/reference).\n\n\u003cbr /\u003e\n\nGet the calling user's thread read state\n----------------------------------------\n\nTo get details about a user's read state within a message thread, include the\nfollowing in your request:\n\n- Specify the `chat.users.readstate` or `chat.users.readstate.readonly` authorization scope.\n- Call the [`GetThreadReadState()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetThreadReadState) method, passing the `name` of the thread read state to get which includes a user ID or alias and a space ID. Getting thread read state only supports getting the read state of the calling user, which can be specified by setting one of the following:\n - The `me` alias. For example, `users/me/spaces/`\u003cvar translate=\"no\"\u003eSPACE\u003c/var\u003e`/threads/`\u003cvar translate=\"no\"\u003eTHREAD\u003c/var\u003e`/threadReadState`.\n - The calling user's Workspace email address. For example, `users/user@example.com/spaces/`\u003cvar translate=\"no\"\u003eSPACE\u003c/var\u003e`/threads/`\u003cvar translate=\"no\"\u003eTHREAD\u003c/var\u003e`/threadReadState`.\n - The calling user's user ID. For example, `users/`\u003cvar translate=\"no\"\u003eUSER\u003c/var\u003e`/spaces/`\u003cvar translate=\"no\"\u003eSPACE\u003c/var\u003e`/threads/`\u003cvar translate=\"no\"\u003eTHREAD\u003c/var\u003e`/threadReadState`.\n\nThe following example gets the calling user's thread read state: \n\n### Node.js\n\nchat/client-libraries/cloud/get-thread-read-state-user-cred.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/chat/client-libraries/cloud/get-thread-read-state-user-cred.js) \n\n```javascript\nimport {createClientWithUserCredentials} from './authentication-utils.js';\n\nconst USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.users.readstate.readonly'];\n\n// This sample shows how to get the thread read state for a space and calling user\nasync function main() {\n // Create a client\n const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);\n\n // Initialize request argument(s)\n const request = {\n // Replace SPACE_NAME and THREAD_NAME here\n name: 'users/me/spaces/SPACE_NAME/threads/THREAD_NAME/threadReadState'\n };\n\n // Make the request\n const response = await chatClient.getThreadReadState(request);\n\n // Handle the response\n console.log(response);\n}\n\nmain().catch(console.error);\n```\n\nTo run this sample, replace the following:\n\n- \u003cvar translate=\"no\"\u003eSPACE_NAME\u003c/var\u003e: the ID from the space's [`name`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Space.FIELDS.string.google.chat.v1.Space.name). You can obtain the ID by calling the [`ListSpaces()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListSpaces) method or from the space's URL.\n- \u003cvar translate=\"no\"\u003eTHREAD_NAME\u003c/var\u003e: the ID from the thread's [`name`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Thread.FIELDS.string.google.chat.v1.Thread.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](/workspace/chat/create-messages#name_a_created_message) assigned to the message at creation.\n\nThe Google Chat API gets the specified thread read state and returns\nan instance of\n[`ThreadReadState`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ThreadReadState).\n\nRelated topics\n--------------\n\n- [Update the calling user's space read state](/workspace/chat/update-space-read-state).\n- [Get the calling user's space read state](/workspace/chat/get-space-read-state)."]]