קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
במדריך הזה מוסבר איך להשתמש בשיטה get() במשאב ThreadReadState של Google Chat API כדי לקבל פרטים על סטטוס הקריאה של משתמש בשרשור הודעות. כדי לקבל את סטטוס הקריאה של הודעה במרחב, אפשר לעיין במאמר בנושא קבלת פרטים על סטטוס הקריאה של משתמש במרחב.
ThreadReadState המשאב הוא משאב יחיד שמייצג פרטים על ההודעה האחרונה שמשתמש מסוים קרא בשרשור הודעות ב-Google Chat.
יצירת פרטי כניסה של מזהה לקוח OAuth לאפליקציה למחשב. כדי להריץ את הדוגמה במדריך הזה, צריך לשמור את פרטי הכניסה כקובץ JSON בשם credentials.json בספרייה המקומית.
כדי לקבל הנחיות, מבצעים את השלבים להגדרת הסביבה במדריך למתחילים הזה.
כדי לקבל פרטים על סטטוס הקריאה של משתמש בשרשור הודעות, צריך לכלול בבקשה את הפרטים הבאים:
מציינים את היקף ההרשאות של chat.users.readstate או chat.users.readstate.readonly.
קוראים לשיטה
GetThreadReadState()
ומעבירים את 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.
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-09-10 (שעון UTC)."],[[["\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,[]]