יצירת פרטי כניסה של מזהה לקוח OAuth לאפליקציה למחשב. כדי להריץ את הדוגמה במדריך הזה, שומרים את פרטי הכניסה כקובץ JSON בשם client_secrets.json בספרייה המקומית.
להדרכה, יש לבצע את השלבים להגדרת הסביבה שמפורטים במדריך למתחילים הזה.
כדי ליצור תגובה להודעה, צריך להעביר את הפרטים הבאים בבקשה:
מציינים את היקף ההרשאה chat.messages.reactions.create, chat.messages.reactions או chat.messages.
קוראים לשיטה CreateReaction(), מעבירים את parent בתור שם המשאב של ההודעה שאליה רוצים להגיב, ואת reaction בתור מכונה של Reaction שבה השדה unicode הוא אמוג'י רגיל שמיוצג על ידי מחרוזת Unicode.
import{createClientWithUserCredentials}from'./authentication-utils.js';constUSER_AUTH_OAUTH_SCOPES=['https://www.googleapis.com/auth/chat.messages.reactions.create'];// This sample shows how to create reaction to a message with user credentialasyncfunctionmain(){// Create a clientconstchatClient=awaitcreateClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);// Initialize request argument(s)constrequest={// Replace SPACE_NAME and MESSAGE_NAME here.parent:'spaces/SPACE_NAME/messages/MESSAGE_NAME',reaction:{// A standard emoji represented by a unicode string.emoji:{unicode:'😀'}}};// Make the requestconstresponse=awaitchatClient.createReaction(request);// Handle the responseconsole.log(response);}main().catch(console.error);
כדי להריץ את הדוגמה הזו, מחליפים את הפרטים הבאים:
SPACE_NAME: המזהה מ-name של המרחב המשותף.
אפשר לקבל את המזהה על ידי קריאה ל-method ListSpaces() או מכתובת ה-URL של המרחב המשותף.
MESSAGE_NAME: המזהה מ-name של ההודעה.
אפשר לקבל את המזהה מגוף התגובה שמוחזר אחרי יצירת הודעה באופן אסינכררוני באמצעות Chat API, או באמצעות השם המותאם אישית שהוקצה להודעה בזמן היצירה.
Chat API מחזיר מופע של Reaction עם פרטי התגובה שנוצרה.
[[["התוכן קל להבנה","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-02-14 (שעון UTC)."],[[["This guide demonstrates how to add emoji reactions (👍, 🚲, 🌞) to Google Chat messages using the `create()` method of the Google Chat API."],["It requires a Google Workspace account, a configured Google Cloud project with the Chat API enabled, and the Node.js Cloud Client Library."],["To add a reaction, call the `CreateReaction()` method, providing the message's resource name and the desired emoji's unicode representation."],["A sample Node.js code snippet is included, illustrating the process of creating a reaction using user credentials."],["You need to replace placeholders for space and message names within the code with your specific values to execute the sample successfully."]]],["To add a reaction to a message using the Google Chat API, utilize the `CreateReaction()` method. Specify the message's resource name as the `parent` and provide a `Reaction` instance with a Unicode emoji string in the `unicode` field. Ensure you have the `chat.messages.reactions.create`, `chat.messages.reactions`, or `chat.messages` authorization scope. You must have a Google Workspace account, a configured Google Cloud project, and have set up the Node.js environment, including OAuth client ID credentials. The API returns the created `Reaction` details.\n"]]