أنشئ بيانات اعتماد معرِّف عميل OAuth لتطبيق على جهاز كمبيوتر. لتشغيل النموذج في هذا الدليل، احفظ بيانات الاعتماد كملف JSON باسم credentials.json في دليلك المحلي.
للحصول على إرشادات، أكمل خطوات إعداد بيئتك في هذا
البدء السريع.
حدِّد نطاق التفويض chat.messages.reactions.create أو chat.messages.reactions أو chat.messages.
استدعِ طريقة
CreateReaction()
، مع تمرير parent كاسم المورد للرسالة التي تريد التفاعل معها، وreaction كمثيل من
Reaction
يكون فيه الحقل 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 الخاص بالمساحة
يمكنك الحصول على المعرّف من خلال استدعاء الطريقة
ListSpaces()
أو من عنوان URL الخاص بالمساحة.
MESSAGE_NAME: المعرّف من name الخاص بالرسالة
يمكنك الحصول على المعرّف من نص الرد الذي يتم إرجاعه بعد إنشاء رسالة بشكل غير متزامن باستخدام Chat API، أو باستخدام الاسم المخصّص الذي تم تعيينه للرسالة عند إنشائها.
تعرض Chat API مثيلاً من
Reaction
يتضمّن تفاصيل التفاعل الذي تم إنشاؤه.
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-07-25 (حسب التوقيت العالمي المتفَّق عليه)"],[[["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"]]