يشرح هذا الدليل كيفية استخدام
update()
طريقة على المصدر Message
في Google Chat API لتعديل نص أو بطاقة
رسالة في مساحة. يمكنك تعديل رسالة لتغيير سماتها، مثل
أو محتوى بطاقة. يمكنك أيضًا إضافة رسالة نصية في البداية في
أو إلحاق بطاقة برسالة نصية.
في Chat API، يتم تمثيل رسالة Chat باستخدام موارد
Message
.
يمكن لمستخدمي Chat إرسال الرسائل التي تحتوي على نصوص فقط،
يمكن لتطبيقات Chat استخدام العديد من ميزات المراسلة الأخرى، بما في ذلك
تعرض واجهات مستخدم ثابتة أو تفاعلية، تجمع المعلومات من
والمستخدمين، وتسليم الرسائل بشكل خاص. لمعرفة المزيد من المعلومات عن المراسلة
الميزات المتوفرة في Chat API، يمكنك الاطّلاع على
نظرة عامة على رسائل Google Chat
المتطلبات الأساسية
Node.js
- نشاط تجاري أو مؤسسة حساب Google Workspace لديه إذن بالوصول إلى Google Chat
- إعداد البيئة:
- أنشِئ مشروعًا على Google Cloud.
- إعداد شاشة طلب الموافقة المتعلّقة ببروتوكول OAuth
- فعِّل Google Chat API وضبطها باستخدام اسم و رمز ووصف لتطبيق Chat.
- تثبيت Node.js Cloud Client Library.
- أنشئ بيانات اعتماد الوصول استنادًا إلى الطريقة التي تريد المصادقة بها في طلب Google Chat API:
- لمصادقة مستخدم Chat،
أنشئ بيانات اعتماد معرّف العميل لبروتوكول OAuth
واحفظ بيانات الاعتماد كملف JSON باسم
client_secrets.json
في الدليل المحلي. - لمصادقة تطبيق Chat،
أنشئ بيانات اعتماد
حساب الخدمة واحفظ بيانات الاعتماد كملف JSON باسم
credentials.json
.
- لمصادقة مستخدم Chat،
أنشئ بيانات اعتماد معرّف العميل لبروتوكول OAuth
واحفظ بيانات الاعتماد كملف JSON باسم
- اختر نطاق تفويض استنادًا إلى ما إذا كنت تريد المصادقة كمستخدم أو تطبيق Chat
Python
- نشاط تجاري أو مؤسسة حساب Google Workspace لديه إذن بالوصول إلى Google Chat
- إعداد بيئتك:
- أنشئ مشروعًا على Google Cloud.
- إعداد شاشة طلب الموافقة المتعلّقة ببروتوكول OAuth
- فعِّل Google Chat API وضبطها باستخدام اسم و رمز ووصف لتطبيق Chat.
- ثبِّت مكتبة Cloud Client Library لـ Python.
- أنشئ بيانات اعتماد الوصول استنادًا إلى الطريقة التي تريد المصادقة بها في طلب Google Chat API:
- لمصادقة مستخدم Chat،
أنشئ بيانات اعتماد معرّف العميل لبروتوكول OAuth
واحفظ بيانات الاعتماد كملف JSON باسم
client_secrets.json
في الدليل المحلي. - لمصادقة تطبيق Chat،
أنشئ بيانات اعتماد
حساب الخدمة واحفظ بيانات الاعتماد كملف JSON باسم
credentials.json
.
- لمصادقة مستخدم Chat،
أنشئ بيانات اعتماد معرّف العميل لبروتوكول OAuth
واحفظ بيانات الاعتماد كملف JSON باسم
- اختر نطاق تفويض استنادًا إلى ما إذا كنت تريد المصادقة كمستخدم أو تطبيق Chat
Java
- نشاط تجاري أو مؤسسة حساب Google Workspace لديه إذن بالوصول إلى Google Chat
- إعداد بيئتك:
- أنشِئ مشروعًا على Google Cloud.
- ضبط شاشة موافقة OAuth
- فعِّل Google Chat API وضبطها باستخدام اسم و رمز ووصف لتطبيق Chat.
- ثبِّت مكتبة Cloud Client Library لـ Java.
- إنشاء بيانات اعتماد الوصول استنادًا إلى طريقة المصادقة في Google Chat API
الطلب:
- لمصادقة مستخدم Chat،
أنشئ بيانات اعتماد معرّف العميل لبروتوكول OAuth
واحفظ بيانات الاعتماد كملف JSON باسم
client_secrets.json
في الدليل المحلي. - للمصادقة كتطبيق Chat، اتّبِع الخطوات التالية:
إنشاء حساب خدمة
بيانات الاعتماد وحفظ بيانات الاعتماد كملف JSON
credentials.json
- لمصادقة مستخدم Chat،
أنشئ بيانات اعتماد معرّف العميل لبروتوكول OAuth
واحفظ بيانات الاعتماد كملف JSON باسم
- اختَر نطاق التفويض استنادًا إلى ما إذا كنت تريد المصادقة بصفتك مستخدمًا أو تطبيق Chat.
برمجة تطبيقات
- حساب على Google Workspace من فئة Business أو Enterprise يتيح الوصول إلى Google Chat
- إعداد البيئة:
- أنشئ مشروعًا على Google Cloud.
- ضبط شاشة موافقة OAuth
- فعِّل Google Chat API وضبطها باستخدام اسم و رمز ووصف لتطبيق Chat.
- أنشئ مشروعًا مستقلاً في Apps Script، وفعِّل خدمة Chat المتقدّمة.
- في هذا الدليل، يجب عليك استخدام أي من أو مصادقة التطبيقات للمصادقة بصفتك تطبيق Chat، أنشئ بيانات اعتماد حساب الخدمة. لمعرفة الخطوات، يُرجى الاطّلاع على المصادقة والتفويض تطبيق Google Chat
- اختر نطاق تفويض استنادًا إلى ما إذا كنت تريد المصادقة كمستخدم أو تطبيق Chat
تعديل رسالة نيابةً عن مستخدم
من خلال مصادقة المستخدم، يمكن تعديل نص الرسالة فقط.
لتعديل رسالة بمصادقة المستخدم، عليك ضبط ما يلي في الطلب:
- حدِّد نطاق تفويض
chat.messages
. - استخدِم الطريقة
UpdateMessage()
. - تجاوز
message
كمثيل لـMessage
مع ما يلي:- حقل
name
الذي تم ضبطه على الرسالة المطلوب تعديلها، والذي يتضمّن معرّف مساحة ومعرّف رسالة - تم ضبط الحقل
text
باستخدام النص الجديد.
- حقل
- نقْل
updateMask
بالقيمةtext
.
إذا كانت الرسالة المعدَّلة هي رسالة بطاقة، يتمّ وضع النص في بداية البطاقات (التي تستمر في العرض).
إليك كيفية تعديل رسالة أو إضافة رسالة نصية في المقدمة في رسالة بطاقة من خلال مصادقة المستخدم:
Node.js
Python
Java
برمجة تطبيقات
لتشغيل هذا العيّنة، استبدِل ما يلي:
SPACE_NAME
: رقم التعريف الوارد في المساحةname
يمكنك الحصول على المعرّف من خلال استدعاء الأسلوبListSpaces()
أو من عنوان URL للمساحة.MESSAGE_NAME
: المعرّف منname
الرسالة يمكنك الحصول على رقم التعريف من نص الاستجابة الذي يتم إرجاعه بعد إنشاء رسالة بشكل غير متزامن باستخدام Chat API، أو باستخدام الاسم المخصّص الذي تمّ تعيينه للرسالة عند إنشائها.
تعرض Chat API مثيلًا من
Message
الذي يوضّح تفاصيل الرسالة التي تم تعديلها.
تعديل رسالة باسم تطبيق Chat
من خلال مصادقة التطبيقات، يمكن تحديث كل من النص وبطاقات الرسالة.
لتعديل رسالة باستخدام مصادقة التطبيق، أرسِل ما يلي في طلبك:
- حدِّد نطاق تفويض
chat.bot
. - عليك استدعاء
UpdateMessage()
. - تجاوز
message
كمثيل لـMessage
مع ما يلي:- تم ضبط الحقل
name
على الرسالة المطلوب تعديلها، وهي تتضمّن رقم تعريف مساحة. ومعرِّف الرسالة. - تم ضبط الحقل
text
باستخدام النص الجديد إذا كان يحتاج إلى تعديل. - تم ضبط الحقل
cardsV2
باستخدام البطاقات الجديدة إذا كانت بحاجة إلى تعديل.
- تم ضبط الحقل
- نقْل
updateMask
مع قائمة الحقول إلى تعديلات مثلtext
cardsV2
إذا كانت الرسالة المعدَّلة هي رسالة بطاقة وتم تعديل النص، يتمّ وضع النص المعدَّل في بداية البطاقات (التي يستمر عرضها). إذا كانت الرسالة المُحدَّثة الرسالة النصية والبطاقات يتم تحديث البطاقات، يتم إلحاق البطاقات المُحدَّثة بالنصّ (الذي يستمر العرض).
إليك كيفية تحديث النص والبطاقات في رسالة باستخدام مصادقة التطبيقات:
Node.js
Python
Java
برمجة تطبيقات
لتشغيل هذا النموذج، استبدل ما يلي:
-
SPACE_NAME
: المعرّف منname
المساحة ويمكنك الحصول على المعرّف من خلال استدعاءListSpaces()
أو من عنوان URL الخاص بالمساحة. MESSAGE_NAME
: المعرف من معرف الرسالةname
يمكنك الحصول على المعرّف من نص الاستجابة الذي تم إرجاعه بعد إنشاء بشكل غير متزامن مع Chat API، أو من خلال اسم مخصّص المخصص للرسالة عند الإنشاء.
تعرض واجهة برمجة التطبيقات Chat مثيلاً من
Message
يوضح بالتفصيل الرسالة التي يتم تحديثها.