נציגי RBM מתקשרים עם משתמשים על ידי שליחה וקבלה של הודעות. כדי לשלוח הודעות למשתמשים, הנציג שולח בקשות שליחת הודעות ל-RCS Business Messaging API. בקשה אחת יכולה לכלול טקסט, כרטיס עשיר, תמונה או סרטון, וגם הצעות לתשובות ולפעולות.
אם שולחים הודעה למשתמש שהמכשיר שלו לא תומך ב-RCS או שה-RCS לא מופעל בו, פלטפורמת RBM מחזירה הודעת שגיאה מסוג 404. במקרה כזה, תוכלו לנסות להגיע למשתמש באמצעות שיטות החזרה לגיבוי שהוגדרו בתשתית.
אם שולחים הודעה למשתמש RCS ברשת שבה הנציג עדיין לא הופעל, או ברשת שלא הופעל בה תעבורת RCS, פלטפורמת RBM מחזירה שגיאה 403.
אם שולחים הודעה עם תכונות שלא נתמכות במכשיר של המשתמש, פלטפורמת RBM מחזירה הודעת שגיאה ולא מעבירה את ההודעה.
כחלק מאסטרטגיית שליחת ההודעות בכמה ערוצים, מומלץ לבטל הודעות שלא נשלחו לאחר פרק זמן סביר ולשלוח אותן דרך ערוץ אחר. כדי לבטל הודעות באופן אוטומטי בשעה מוגדרת מראש, צריך להגדיר תאריך תפוגה להודעה.
הנמען לא מחובר
פלטפורמת RBM עדיין מקבלת הודעות לשליחה גם אם הנמען אופליין. תקבלו תשובה מסוג 200 OK, ופלטפורמת RBM תחזיק את ההודעה ותנסה לשלוח אותה מחדש למשך 30 יום. אין צורך לבקש מ-RBM לשלוח את ההודעה שוב.
מערכת RBM מוחקת הודעות שלא נשלחו 30 יום אחרי שהן נשלחו.
בהתאם לתרחיש לדוגמה של הנציג, כדאי לבטל הודעה שלא נשלחה לפני הזמן הקצוב של 30 הימים. ביטול יכול למנוע ממשתמשים אופליין לקבל הודעה לא עדכנית כשהם חוזרים לאינטרנט. יש כמה דרכים לבטל הודעה:
- שולחים בקשת ביטול כדי להפעיל את הביטול.
- להגדיר תאריך תפוגה להודעה כדי לבטל אותה באופן אוטומטי בזמן המתאים.
הגדרת מועד תפוגה להודעה
האם ההודעה של הנציג דחופה? לדוגמה, קודי OTP תקפים לתקופה קצרה בלבד. תוקף המבצעים לזמן מוגבל פג. בנוסף, תזכורות לפגישות לא רלוונטיות אחרי תאריך הפגישה. כדי להבטיח שההודעות יהיו רלוונטיות ויתקבלו בזמן, כדאי להגדיר תאריך תפוגה להודעות. כך אפשר למנוע ממשתמשים אופליין לקבל תוכן לא עדכני כשהם חוזרים לאינטרנט. תאריך התפוגה הוא גם הזדמנות טובה להפעיל את אסטרטגיית שליחת ההודעות החלופית, כדי שהמשתמשים יקבלו את המידע הדרוש להם בזמן.
כדי להגדיר תאריך תפוגה להודעה, מציינים אחד מהשדות הבאים בהודעה של הסוכן:
expireTime
: השעה המדויקת לפי שעון UTC שבה תוקף ההודעה יפוג.ttl
(זמן חיים): משך הזמן עד לתפוגת התוקף של ההודעה.
אפשרויות עיצוב וערכים מפורטות במאמר AgentMessage
.
אחרי שתוקף ההודעה פג, פלטפורמת RBM מפסיקה לנסות להעביר אותה והיא מבוטלת באופן אוטומטי. עם זאת, יכול להיות שהפעולה הזו תיכשל במקרים נדירים. לדוגמה, ה-API יכול להפעיל את הביטול בזמן שפלטפורמת RBM הייתה בתהליך שליחת ההודעה. כדי לוודא שההודעת הזוכה בתוקף בוטלה, מערכת RBM תשלח אירוע ל-webhook שלכם.
הערך המקסימלי של ttl
ו-expireTime
הוא 15 ימים אחרי שליחת ההודעה.
מגבלות על גודל ההודעות
הגודל המקסימלי של כל AgentMessage שמומר למחרוזת הוא 250KB. כרטיסים עשירים ומדיה אחרת נכללים במגבלת הגודל הזו. לטקסט של ההודעה יש מגבלה משלו של 3,072 תווים.
הגודל המקסימלי של קובץ שאפשר לשלוח דרך RBM הוא 100MB. להודעת RBM אחת אפשר לצרף רק קובץ PDF אחד או קובץ מדיה אחד. מידע נוסף זמין במאמר קבצי מדיה וקבצי PDF.
טקסט
ההודעות הפשוטה ביותר מורכבות מטקסט. הודעות טקסט מתאימות במיוחד להעברת מידע ללא צורך ברכיבים חזותיים, באינטראקציה מורכבת או בתגובה.
דוגמה
הקוד הבא שולח הודעת טקסט רגילה. אפשר לעיין באפשרויות הפורמט והערך במאמר phones.agentMessages.create
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!' } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); let params = { messageText: 'Hello, world!', msisdn: '+12223334444', }; // Send a simple message to the device rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Send simple text message to user rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444" ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a simple RBM text message message_text = messages.TextMessage('Hello, world!') # Send text message to the device messages.MessageCluster().append_message(message_text).send_to_msisdn('+12223334444')
C#
using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", );
תוכן של הודעה בסיסית – המרה של SMS
ספקי הסלולר השיקו מודלים של חיוב כדי לתמוך בהעברת הודעות SMS ל-RBM. הודעה ב-RBM שמכילה עד 160 תווים ב-UTF-8 נקראת הודעה בסיסית.
כשיוצרים בקשה לשליחת הודעה בסיסית, חשוב לזכור שתווים נספרים כבייט אחד (UTF-8). אם שולחים הודעה שמכילה תווים מיוחדים כמו אמוג'י או קבוצת תווים של כמה בייטים, כל תו נספר כ-2 תווים ב-UTF-8.
מזינים טקסט בתיבת הטקסט כדי לבדוק את האורך שלו:
סיסמאות חד-פעמיות לאימות משתמשים
אפשר להשתמש ב-RBM כדי לשלוח סיסמאות חד-פעמיות (OTP) לאימות אוטומטי של משתמשים באמצעות SMS Retriever API. מידע נוסף על SMS Retriever ועל ממשקי ה-API הקשורים זמין במסמכי התיעוד של SMS Retriever. פרטים על אימות אוטומטי של משתמשים באפליקציות שנרשמו ל-SMS Retriever API מפורטים בתרשים התהליך הזה.
במהלך תהליך האימות, ממשק ה-API של SMS Retriever מקשיב להודעת RBM. ההודעה הזו חייבת לכלול סיסמה חד-פעמית (OTP) וגיבוב שמזהה את האפליקציה. אחרי שהגיבוב יתאים לאפליקציה, ה-OTP יופק ויישלח לאפליקציה לצורך אימות אוטומטי של המשתמש.
הנה דוגמה להודעת טקסט של RBM לאימות משתמשים: הקוד שלך הוא <OTP> <app hash>.
לדוגמה: Your code is 123456 M8tue43FGT.
קובצי מדיה וקובצי PDF
כששולחים הודעה עם תמונה, סרטון, קובץ אודיו או קובץ PDF, הנציג צריך לספק כתובת URL שזמינה לכולם לתוכן או להעלות את הקובץ ישירות. בקובצי מדיה, אפשר גם לציין תמונה ממוזערת שתאפשר למשתמשים לראות תצוגה מקדימה של התוכן לפני שהם לוחצים עליו. בקובצי אודיו, ווידג'ט האודיו שמוגדר כברירת מחדל משמש כסמל עזר.
פלטפורמת RBM שומרת קבצים במטמון למשך 60 יום, ו-API מחזיר מזהה קובץ שהנציג יכול לכלול בהודעות למשתמשים. אחרי 60 יום, המערכת מסירה את הקבצים מהמטמון.
כשמציינים קבצים לפי כתובת URL, מומלץ להגדיר את הערך של contentMessage.forceRefresh
כ-false
. הגדרת contentMessage.forceRefresh
ל-true
מאלצת את RBM לאחזר תוכן חדש מכתובת ה-URL שצוינה, גם אם תוכן כתובת ה-URL נשמר במטמון. כתוצאה מכך, משך הזמן להעברת ההודעות למשתמשים ארוך יותר.
כאן מפורטות המגבלות וההמלצות לגבי גודל הקובץ.
דוגמה לכתובת URL של קובץ
הקוד הבא שולח תמונה. אפשרויות עיצוב וערכים מפורטות במאמר AgentContentMessage
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'contentInfo': { 'fileUrl': 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif', 'forceRefresh': 'false' } } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); let params = { fileUrl: 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif', msisdn: '+12223334444', }; // Send an image/video to a device rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.AgentContentMessage; import com.google.api.services.rcsbusinessmessaging.v1.model.AgentMessage; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); String fileUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // create media only message AgentContentMessage agentContentMessage = new AgentContentMessage(); agentContentMessage.setContentInfo(new ContentInfo().setFileUrl(fileUrl)); // attach content to message AgentMessage agentMessage = new AgentMessage(); agentMessage.setContentMessage(agentContentMessage); rbmApiHelper.sendAgentMessage(agentMessage, "+12223334444"); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create media file attachment file_message = messages.FileMessage('http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif') messages.MessageCluster().append_message(file_message).send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); string fileUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // Create content info with the file url ContentInfo contentInfo = new ContentInfo { FileUrl = fileUrl }; // Attach content info to a message AgentContentMessage agentContentMessage = new AgentContentMessage { ContentInfo = contentInfo, }; // Attach content to message AgentMessage agentMessage = new AgentMessage { ContentMessage = agentContentMessage }; rbmApiHelper.SendAgentMessage(agentMessage, "+12223334444");
לחלופין, אפשר להעלות מדיה לפני ששולחים אותה בהודעה באמצעות files.create
.
דוגמה להעלאת קובץ
הקוד הבא מעלה קובץ וידאו וקובץ תמונה ממוזערת, ולאחר מכן שולח את שני הקובצים בהודעה. אפשרויות לעיצוב ולערכים מפורטות במאמרים files.create
וAgentContentMessage
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/upload/v1/files?agentId=AGENT_ID" \ -H "Content-Type: video/mp4" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ --upload-file "FULL_PATH_TO_VIDEO_MEDIA_FILE"
# Capture server-specified video file name from response body JSON
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/upload/v1/files?agentId=AGENT_ID" \ -H "Content-Type: image/jpeg" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ --upload-file "FULL_PATH_TO_THUMBNAIL_MEDIA_FILE"
# Capture server-specified image file name from response body JSON
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'uploadedRbmFile': { 'fileName': 'SERVER-SPECIFIED_VIDEO_FILE_NAME' 'thumbnailName': 'SERVER-SPECIFIED_THUMBNAIL_FILE_NAME' } } }"
סוגי המדיה הנתמכים
מערכת RBM תומכת בסוגי המדיה הבאים:
סוג מדיה | סוג המסמך | Extension | עובד עם כרטיסים מתקדמים |
---|---|---|---|
application/ogg | אודיו OGG | .ogx | לא |
application/pdf | .pdf | לא | |
audio/aac | אודיו מסוג AAC | .aac | לא |
audio/mp3 | אודיו MP3 | .mp3 | לא |
audio/mpeg | אודיו MPEG | .mpeg | לא |
audio/mpg | MPG audio | .mp3 | לא |
audio/mp4 | אודיו MP4 | .mp4 | לא |
audio/mp4-latm | אודיו בפורמט MP4-latm | .mp4 | לא |
audio/3gpp | אודיו 3GPP | .3gp | לא |
image/jpeg | JPEG | .jpeg, .jpg | כן |
image/gif | GIF | .gif | כן |
image/png | PNG | .png | כן |
video/h263 | וידאו H263 | .h263 | כן |
video/m4v | סרטון M4V | .m4v | כן |
video/mp4 | סרטון MP4 | .mp4 | כן |
video/mpeg4 | סרטון MPEG-4 | .mp4, .m4p | כן |
video/mpeg | וידאו MPEG | .mpeg | כן |
video/webm | סרטון WEBM | .webm | כן |
הצעות לתשובות
הצעות לתשובות יעזרו למשתמשים להתמצא בשיחות, על ידי מתן תשובות שהנציג יודע איך להגיב עליהן. הנציג שולח הצעות לתשובות ברשימות של צ'יפים של הצעות או בכרטיסים מתקדמים.
כשמשתמש מקייש על הצעת תשובה, הנציג מקבל אירוע שמכיל את הטקסט של התשובה ואת נתוני ההודעה החוזרת.
ההצעות לתשובות יכולות להכיל עד 25 תווים.
דוגמה
הקוד הבא שולח טקסט עם שתי הצעות לתשובות. אפשרויות עיצוב ואפשרויות ערך מפורטות במאמר SuggestedReply
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'reply': { 'text': 'Suggestion #1', 'postbackData': 'suggestion_1' } }, { 'reply': { 'text': 'Suggestion #2', 'postbackData': 'suggestion_2' } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); let suggestions = [ { reply: { 'text': 'Suggestion #1', 'postbackData': 'suggestion_1', }, }, { reply: { 'text': 'Suggestion #2', 'postbackData': 'suggestion_2', }, }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with suggestion chips to the device rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; import com.google.rbm.SuggestionHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); suggestions.add( new SuggestionHelper("Suggestion #1", "suggestion_1").getSuggestedReply()); suggestions.add( new SuggestionHelper("Suggestion #2", "suggestion_2").getSuggestedReply()); // Send simple text message to user rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggested replies for the message to send to the user cluster.append_suggestion_chip(messages.SuggestedReply('Suggestion #1', 'reply:suggestion_1')) cluster.append_suggestion_chip(messages.SuggestedReply('Suggestion #2', 'reply:suggestion_2')) # Send a simple message with suggestion chips to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); List<Suggestion> suggestions = new List<Suggestion> { // Create suggestion chips new SuggestionHelper("Suggestion #1", "suggestion_1").SuggestedReply(), new SuggestionHelper("Suggestion #2", "suggestion_2").SuggestedReply() }; // Send simple text message with suggestions to user rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
הצעות לפעולות
ההצעות לפעולות נותנות למשתמשים הנחיות לגבי השיחות, על סמך הפונקציונליות המובנית של המכשירים שלהם. הנציג יכול להציע למשתמשים להקיש על מספר, לפתוח מיקום במפה, לשתף מיקום, לפתוח כתובת URL או ליצור אירוע ביומן. הנציג שולח הצעות לפעולות ברשימות של צ'יפים של הצעות או בכרטיסים מתקדמים.
כשמשתמש מקייש על הצעה לביצוע פעולה, הנציג מקבל אירוע שמכיל את נתוני הדיווח החוזר על פעולה.
האורך המקסימלי של הצעות הפעולה הוא 25 תווים.
אפשרויות עיצוב וערכים מפורטות במאמר SuggestedAction
.
חיוג מספר
הפעולה 'חיוג' מנחה את המשתמש לחייג למספר הטלפון שצוין על ידי הנציג.
מספרי טלפון יכולים לכלול רק ספרות (0-9
), סימן פלוס (+
), כוכבית (*
) וסימן מספר (#
). הפורמט הבינלאומי E.164 (לדוגמה, +14155555555
) נתמך, אבל הוא לא נדרש. כלומר, גם הערך +14155555555
וגם הערך 1011
הם ערכים חוקיים.
דוגמה
הקוד הבא שולח פעולת חיוג. אפשרויות עיצוב וערכים מפורטות במאמר DialAction
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'action': { 'text': 'Call', 'postbackData': 'postback_data_1234', 'fallbackUrl': 'https://www.google.com/contact/', 'dialAction': { 'phoneNumber': '+15556667777' } } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define a dial suggested action let suggestions = [ { action: { text: 'Call', postbackData: 'postback_data_1234', dialAction: { phoneNumber: '+15556667777' } } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with a dial suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.DialAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a dial suggested action DialAction dialAction = new DialAction(); dialAction.setPhoneNumber("+15556667777"); // creating a suggested action based on a dial action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Call"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setDialAction(dialAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a dial suggested action suggestions = [ messages.DialAction('Call', 'reply:postback_data_1234', '+15556667777') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create a dial an agent suggested action DialAction dialAction = new DialAction { PhoneNumber = "+15556667777" }; // Creating a suggested action based on a dial action SuggestedAction suggestedAction = new SuggestedAction { Text = "Call", PostbackData = "postback_data_1234", DialAction = dialAction }; // Attach action to a suggestion Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
הצגת מיקום
הפעולה'הצגת המיקום' מציגה מיקום באפליקציית המפה שמוגדרת כברירת מחדל של המשתמש. אפשר לציין את המיקום לפי קו הרוחב ואורך הגלובוס או באמצעות שאילתה שמבוססת על המיקום הנוכחי של המשתמש. אפשר גם להגדיר תווית מותאמת אישית לסיכה שתוצג באפליקציית המפה.
דוגמה
הקוד הבא שולח פעולת הצגת מיקום. אפשר לעיין באפשרויות הפורמט והערך במאמר ViewLocationAction
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'action': { 'text': 'View map', 'postbackData': 'postback_data_1234', 'fallbackUrl': 'https://www.google.com/maps/@37.4220188,-122.0844786,15z', 'viewLocationAction': { 'latLong': { 'latitude': "37.4220188', 'longitude': "-122.0844786' }, 'label': 'Googleplex' } } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define a view location suggested action let suggestions = [ { action: { text: 'View map', postbackData: 'postback_data_1234', viewLocationAction: { latLong: { latitude: 37.4220188, longitude: -122.0844786 }, label: 'Googleplex' } } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with a view location suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.ViewLocationAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a view location suggested action ViewLocationAction viewLocationAction = new ViewLocationAction(); viewLocationAction.setQuery("Googleplex, Mountain View, CA"); // creating a suggested action based on a view location action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("View map"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setViewLocationAction(viewLocationAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a view location suggested action suggestions = [ messages.ViewLocationAction('View map', 'reply:postback_data_1234', query='Googleplex, Mountain View, CA') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // create an view location action ViewLocationAction viewLocationAction = new ViewLocationAction { Query = "Googleplex Mountain View, CA" }; // Attach the view location action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { ViewLocationAction = viewLocationAction, Text = "View map", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
שיתוף מיקום
הפעולה 'שיתוף מיקום' מאפשרת למשתמש לשלוח מיקום לנציג שלכם. המיקום שהמשתמש מציין לא בהכרח המיקום שלו.
דוגמה
הקוד הבא שולח פעולת שיתוף מיקום. אפשר לעיין באפשרויות הפורמט והערך במאמר ShareLocationAction
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'action': { 'text': 'Share your location', 'postbackData': 'postback_data_1234', 'shareLocationAction': {} } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define a share location suggested action let suggestions = [ { action: { text: 'Share your location', postbackData: 'postback_data_1234', shareLocationAction: { } } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with a share location suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.ShareLocationAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a share location suggested action ShareLocationAction shareLocationAction = new ShareLocationAction(); // creating a suggested action based on a share location action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Share location"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setShareLocationAction(shareLocationAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a share location suggested action suggestions = [ messages.ShareLocationAction('Share location', 'reply:postback_data_1234') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create a share location action ShareLocationAction shareLocationAction = new ShareLocationAction(); // Attach the share location action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { ShareLocationAction = shareLocationAction, Text = "Share location", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
פתיחת כתובת URL
הפעולה 'פתיחת כתובת URL' מאפשרת לכם להפנות משתמשים לדף אינטרנט שצוין על ידי הנציג שלכם. כברירת מחדל, דף האינטרנט נפתח בדפדפן של המשתמש. אם למשתמש מוגדרת אפליקציית ברירת מחדל לדף האינטרנט, האפליקציה הזו תיפתח במקום זאת. במקרה כזה, הסמל של לחצן הפעולה המוצע יהיה סמל האפליקציה.
הפעולה 'פתיחת כתובת URL' תומכת גם בתצוגות אינטרנט משולבות. מידע נוסף זמין במאמר פתיחת כתובת URL באמצעות תצוגת אינטרנט.
דוגמה
הקוד הבא שולח פעולת פתיחת כתובת URL. אפשרויות עיצוב וערכים מפורטות במאמר OpenUrlAction
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'action': { 'text': 'Open Google', 'postbackData': 'postback_data_1234', 'openUrlAction': { 'url': 'https://www.google.com' } } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define an open URL suggested action let suggestions = [ { action: { text: 'Open Google', postbackData: 'postback_data_1234', openUrlAction: { url: 'https://www.google.com' } } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with an open URL suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.OpenUrlAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating an open url suggested action OpenUrlAction openUrlAction = new OpenUrlAction(); openUrlAction.setUrl("https://www.google.com"); // creating a suggested action based on an open url action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Open Google"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setOpenUrlAction(openUrlAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create an open url suggested action suggestions = [ messages.OpenUrlAction('Open Google', 'reply:postback_data_1234', 'https://www.google.com') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create an open url action OpenUrlAction openUrlAction = new OpenUrlAction { Url = "https://www.google.com" }; // Attach the open url action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { OpenUrlAction = openUrlAction, Text = "Open Google", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
פתיחת כתובת URL באמצעות Webview
הפעולה 'פתיחת כתובת URL באמצעות Webview' טוענת את דף האינטרנט שצוין באפליקציית ההודעות באמצעות מנוע הרינדור של דפדפן ברירת המחדל. כך המשתמש יכול ליצור אינטראקציה עם דף האינטרנט בלי לצאת מהשיחה ב-RBM. כדי להפעיל תצוגות אינטרנט, אפשר לעיין במאמר OpenURLApplication
.
ל-Webviews יש שלושה מצבי תצוגה. אפשרויות עיצוב וערכים מפורטות במאמר WebviewViewMode
.
- מלא: דף האינטרנט תופס את המסך כולו
- חצי: דף האינטרנט תופס חצי מהמסך
- גבוה: דף האינטרנט תופס שלושה רבעים מהמסך
דוגמה
הקוד הבא שולח פעולת פתיחת כתובת URL עם תצוגת אינטרנט. אפשרויות עיצוב וערכים מפורטות במאמר OpenURLAction
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d '{ "contentMessage": { "text": "Hello, world!", "suggestions": [ { "action": { "text": "Open Google", "postbackData": "postback_data_1234", "openUrlAction": { "url": "https://www.google.com", "application": "WEBVIEW", "webviewViewMode": "FULL", "description": "Accessibility description" } } } ] } }'
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.OpenUrlAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { String URL = "https://www.google.com"; // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // Create suggestion to view webpage in full mode Suggestion viewInFullMode = getUrlActionInWebview(URL, "FULL") suggestions.add(viewInFullMode); // create suggestion to view webpage in half mode Suggestion viewInHalfMode = getUrlActionInWebview(URL, "HALF") suggestions.add(viewInHalfMode); // create suggestion to view webpage in tall mode Suggestion viewInTallMode = getUrlActionInWebview(URL, "TALL") suggestions.add(viewInTallMode); // Send simple text message with the suggested action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); } /** * Creates a suggested action to open URL in webview. * * @return a suggestion object for an open URL in webview action . */ private Suggestion getUrlActionInWebview(String url, String viewMode) { // create an open url action OpenUrlAction openUrlAction = new OpenUrlAction(); openUrlAction.setUrl(url); openUrlAction.setApplication("WEBVIEW"); openUrlAction.setWebviewViewMode(viewMode); openUrlAction.setDescription("Accessibility description"); // attach the open url action to a suggested action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setOpenUrlAction(openUrlAction); suggestedAction.setText('display_text'); suggestedAction.setPostbackData('postback_data_123'); // attach the action to a suggestion object Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); return suggestion; }
יצירת אירוע ביומן
הפעולה 'יצירת אירוע ביומן' פותחת את אפליקציית היומן של המשתמש ומתחילה ליצור אירוע חדש עם המידע שצוין.
דוגמה
הקוד הבא שולח פעולה ליצירת אירוע ביומן. אפשרויות עיצוב ואפשרויות ערך מפורטות במאמר CreateCalendarEventAction
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'action': { 'text': 'Save to calendar', 'postbackData': 'postback_data_1234', 'fallbackUrl': 'https://www.google.com/calendar', 'createCalendarEventAction': { 'startTime': '2020-06-30T19:00:00Z', 'endTime': '2020-06-30T20:00:00Z', 'title': 'My calendar event', 'description': 'Description of the calendar event' } } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define a create calendar event suggested action let suggestions = [ { action: { text: 'Save to calendar', postbackData: 'postback_data_1234', createCalendarEventAction: { startTime: '2020-06-30T19:00:00Z', endTime: '2020-06-30T20:00:00Z', title: 'My calendar event', description: 'Description of the calendar event', }, } }, ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with a create calendar event suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.CreateCalendarEventAction; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating a create calendar event suggested action CreateCalendarEventAction createCalendarEventAction = new CreateCalendarEventAction(); calendarEventAction.setTitle("My calendar event"); calendarEventAction.setDescription("Description of the calendar event"); calendarEventAction.setStartTime("2020-06-30T19:00:00Z"); calendarEventAction.setEndTime("2020-06-30T20:00:00Z"); // creating a suggested action based on a create calendar event action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Save to calendar"); suggestedAction.setPostbackData("postback_data_1234"); suggestedAction.setCreateCalendarEventAction(createCalendarEventAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); suggestions.add(suggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a calendar event suggested action suggestions = [ messages.CreateCalendarEventAction('Save to Calendar', 'reply:postback_data_1234', '2020-06-30T19:00:00Z', '2020-06-30T20:00:00Z', 'My calendar event', 'Description of the calendar event') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create a calendar event action CreateCalendarEventAction calendarEventAction = new CreateCalendarEventAction { Title = "My calendar event", Description = "Description of the calendar event", StartTime = "2020-06-30T19:00:00Z", EndTime = "2020-06-30T20:00:00Z" }; // Attach the calendar event action to a suggested action SuggestedAction suggestedAction = new SuggestedAction { CreateCalendarEventAction = calendarEventAction, Text = "Save to calendar", PostbackData = "postback_data_1234" }; // Attach the action to a suggestion object Suggestion suggestion = new Suggestion { Action = suggestedAction }; List<Suggestion> suggestions = new List<Suggestion> { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
כתיבת הודעות
הפעולה 'כתיבה' פותחת את אפליקציית ההודעות של המשתמש, כדי שהוא יוכל לשלוח הודעות למספר טלפון מוגדר מראש, כמו מספר של תמיכת לקוחות.
יש שלושה סוגים של פעולות Compose. דוגמאות חזותיות מפורטות במאמר כתיבת הודעות טקסט, אודיו או וידאו.
- כתיבת הודעת טקסט: פתיחת אפליקציית ההודעות עם טקסט מלא מראש, כדי שהמשתמש יוכל לשלוח אותו.
- כתיבת הודעה קולית: הפעולה הזו פותחת את אפליקציית ההודעות ומפעילה את המיקרופון כדי שהמשתמש יוכל להקליט אודיו.
- כתיבת הודעת וידאו: הפקודה הזו פותחת את אפליקציית ההודעות ומפעילה את המצלמה כדי שהמשתמש יוכל לצלם סרטון.
דוגמה
הקוד הבא שולח פעולת כתיבת אימייל. אפשרויות עיצוב וערכים מפורטות במאמר ComposeAction
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'text': 'Hello, world!', 'suggestions': [ { 'action': { 'text': 'Compose a text message', 'postbackData': 'postback_data_123', 'composeAction': { 'composeTextMessage': { 'phoneNumber': '+15556667777' 'text': 'Draft to go into the send message text field.' } } } },{ 'action': { 'text': 'Compose an audio message', 'postbackData': 'postback_data_456', 'composeAction': { 'composeRecordingMessage': { 'phoneNumber': '+15556667777' 'type': 'ACTION_TYPE_AUDIO' } } } },{ 'action': { 'text': 'Compose a video message', 'postbackData': 'postback_data_789', 'composeAction': { 'composeRecordingMessage': { 'phoneNumber': '+15556667777' 'type': 'ACTION_TYPE_VIDEO' } } } } ] } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Define a compose suggested action let suggestions = [ { action: { text: 'Compose a text message', postbackData: 'postback_data_123', 'composeAction': { 'composeTextMessage': { 'phoneNumber': '+15556667777' 'text': 'Draft to go into the send message text field.' } } } },{ action: { text: 'Compose an audio message', postbackData: 'postback_data_456', 'composeAction': { 'composeRecordingMessage': { 'phoneNumber': '+15556667777' 'type': 'ACTION_TYPE_AUDIO' } } } },{ action: { text: 'Compose a video message', postbackData: 'postback_data_789', 'composeAction': { 'composeRecordingMessage': { 'phoneNumber': '+15556667777' 'type': 'ACTION_TYPE_VIDEO' } } } } ]; let params = { messageText: 'Hello, world!', msisdn: '+12223334444', suggestions: suggestions, }; // Send a simple message with a dial suggested action rbmApiHelper.sendMessage(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.ComposeAction; import com.google.api.services.rcsbusinessmessaging.v1.model.ComposeRecordingMessage; import com.google.api.services.rcsbusinessmessaging.v1.model.ComposeTextMessage; import com.google.api.services.rcsbusinessmessaging.v1.model.SuggestedAction; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.RbmApiHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); // creating compose text suggested action Suggestion composeTextSuggestion = getComposeTextAction() suggestions.add(composeTextSuggestion); // creating compose audio suggested action Suggestion composeAudioSuggestion = getComposeAudioAction() suggestions.add(composeAudioSuggestion); // Send simple text message with the suggestion action rbmApiHelper.sendTextMessage( "Hello, world!", "+12223334444", suggestions ); } catch(Exception e) { e.printStackTrace(); } /** * Creates a compose text suggested action. * @return A suggestion object for a compose text action. */ private Suggestion getComposeTextAction() { // creating a compose text suggested action ComposeTextMessage message = new ComposeTextMessage(); message.setPhoneNumber("+12223334444"); message.setText("Draft to go into the send message text field."); ComposeAction composeAction = new ComposeAction(); composeAction.setComposeTextMessage(message); // creating a suggested action based on a compose text action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Send a text message"); suggestedAction.setPostbackData("postback_data_123"); suggestedAction.setComposeAction(composeAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); return suggestion; } /** * Creates a compose audio suggested action. * @return A suggestion object for a compose audio action. */ private Suggestion getComposeAudioAction() { // creating a compose audio suggested action ComposeRecordingMessage message = new ComposeRecordingMessage(); message.setPhoneNumber("+12223334444"); message.setType("ACTION_TYPE_AUDIO"); ComposeAction composeAction = new ComposeAction(); composeAction.setComposeRecordingMessage(message); // creating a suggested action based on a compose text action SuggestedAction suggestedAction = new SuggestedAction(); suggestedAction.setText("Send an audio message"); suggestedAction.setPostbackData("postback_data_456"); suggestedAction.setComposeAction(composeAction); // attaching action to a suggestion Suggestion suggestion = new Suggestion(); suggestion.setAction(suggestedAction); return suggestion; }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Create a dial suggested action suggestions = [ messages.ComposeTextMessageAction( 'Send a text message', 'postback_data_123', '+15556667777', '') messages.ComposeRecordingMessageAction( 'Send an audio message', 'postback_data_456', '+15556667777', 'ACTION_TYPE_AUDIO') ] # Create text message to send to user text_msg = messages.TextMessage('Hello, world!') cluster = messages.MessageCluster().append_message(text_msg) # Append suggestions for the message to send to the user for suggestion in suggestions: cluster.append_suggestion_chip(suggestion) # Send a simple message with suggested action to the device cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Create a compose text suggested action ComposeTextMessage composeTextMessage = new ComposeTextMessage{ PhoneNumber = "+15556667777" Text = "Draft to go into the send message text field." }; ComposeAction composeAction = new ComposeAction { ComposeTextMessage = composeTextMessage }; // Creating a suggested action based on a compose action SuggestedAction suggestedAction = new SuggestedAction { Text = "Send a text message", PostbackData = "postback_data_123", ComposeAction = composeAction }; // Attach action to a suggestion Suggestion suggestion = new Suggestion { Action = suggestedAction }; Listsuggestions = new List { suggestion }; rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", suggestions );
רשימת הצעות קשורות
הנציג שולח רשימות של צ'יפים עם הצעות, עם הודעות שיעזרו למשתמשים לבצע את הפעולות הבאות. רשימת הצ'יפים מוצגת רק כשההודעה המשויכת נמצאת בחלק התחתון של השיחה. כל הודעה נוספת בשיחה (ממשתמש או מהנציג שלכם) תגרום למחיקה של רשימת הצ'יפים.
הצ'יפים ברשימה הם הצעות לתשובות והצעות לפעולות.
רשימות צ'יפים מכילות עד 11 צ'יפים של הצעות, וכל תווית של צ'יפ יכולה להכיל עד 25 תווים.
אפשרויות עיצוב וערכים מפורטות במאמר AgentContentMessage
.
כרטיסים מתקדמים
כשצריך לשלוח כמות גדולה של מידע, מדיה או הצעות קשורות, כדאי לשלוח כרטיס מתקדם. כרטיסים מתקדמים מאפשרים לנציג לשלוח כמה יחידות מידע בהודעה אחת.
כרטיסים עשירים יכולים להכיל את הפריטים הבאים:
- תמונה או סרטון
- טקסט כותרת
- טקסט תיאור
- רשימה של הצעות לתשובות ולהצעות לפעולות (עד 4)
כרטיס עשיר יכול להכיל את כל הפריטים שצוינו, אבל כדי שהכרטיס יהיה תקף, הוא חייב להכיל לפחות תמונה, סרטון או כותרת. כרטיס עשיר יכול להכיל עד ארבע הצעות לפעולות או הצעות לתשובות. אי אפשר לכלול בשילוב כרטיס אחד הצעות לפעולות והצעות לתשובות.
הנציג יכול לשלוח כמה כרטיסים מתקדמים יחד בקרוסלה של כרטיסים מתקדמים.
הגודל המקסימלי של מטען נתונים של כרטיס עשיר הוא 250KB. כאן מפורטות ההמלצות והמגבלות לגבי גודל קובצי המדיה.
גובה הכרטיס
הכרטיסים מתרחבים אנכית בהתאם לתוכן שלהם. הגובה המינימלי של כרטיסים עשירים הוא 112 DP והגובה המקסימלי הוא 344 DP. אם התוכן של הכרטיס לא גדול מספיק כדי למלא את הגובה המינימלי של הכרטיס, הכרטיס יתרחב והגובה הנוסף יאוכלס במרחב לבן.
המדיה בכרטיסים עשירים חייבת להתאים לאחד משלושת הגבהים הבאים:
- קצר: 112 DP
- בינוני: 168 DP
- גבוה: 264 DP
אם המדיה לא מתאימה למימדים בכרטיס בהתאם לגובה שנבחר, התצוגה המקדימה של המדיה נבחרת על ידי הגדלת התצוגה וחיתוך המדיה.
דוגמה
הקוד הבא שולח כרטיס מתקדם עם תמונה ותשובות מוצעות. אפשרויות עיצוב וערכים מפורטות במאמר RichCard
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'richCard': { 'standaloneCard': { 'thumbnailImageAlignment': 'RIGHT', 'cardOrientation': 'VERTICAL', 'cardContent': { 'title': 'Hello, world!', 'description': 'RBM is awesome!', 'media': { 'height': 'TALL', 'contentInfo':{ 'fileUrl': 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif', 'forceRefresh': 'false' } }, 'suggestions': [ { 'reply': { 'text': 'Suggestion #1', 'postbackData': 'suggestion_1' } }, { 'reply': { 'text': 'Suggestion #2', 'postbackData': 'suggestion_2' } } ] } } } } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Suggested replies to be used in the card let suggestions = [ { reply: { 'text': 'Suggestion #1', 'postbackData': 'suggestion_1', }, }, { reply: { 'text': 'Suggestion #2', 'postbackData': 'suggestion_2', }, }, ]; // Image to be displayed by the card let imageUrl = 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif'; // Definition of the card parameters let params = { messageText: 'Hello, world!', messageDescription: 'RBM is awesome!', msisdn: '+12223334444', suggestions: suggestions, imageUrl: imageUrl, height: 'TALL', }; // Send rich card to device rbmApiHelper.sendRichCard(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.StandaloneCard; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.cards.CardOrientation; import com.google.rbm.cards.MediaHeight; import com.google.rbm.RbmApiHelper; import com.google.rbm.SuggestionHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); // Create suggestions for chip list List<Suggestion> suggestions = new ArrayList<Suggestion>(); suggestions.add( new SuggestionHelper("Suggestion #1", "suggestion_1").getSuggestedReply()); suggestions.add( new SuggestionHelper("Suggestion #2", "suggestion_2").getSuggestedReply()); String imageUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // Create a standalone rich card to send to the user StandaloneCard standaloneCard = rbmApiHelper.createStandaloneCard( "Hello, world!", "RBM is awesome!", imageUrl, MediaHeight.MEDIUM, CardOrientation.VERTICAL, suggestions ); rbmApiHelper.sendStandaloneCard(standaloneCard, "+12223334444"); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Suggested replies to be used in the card suggestions = [ messages.SuggestedReply('Suggestion #1', 'reply:suggestion_1'), messages.SuggestedReply('Suggestion #2', 'reply:suggestion_2') ] # Image to be displayed by the card image_url = 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif'; # Define rich card structure rich_card = messages.StandaloneCard('VERTICAL', 'Hello, world!', 'RBM is awesome!', suggestions, image_url, None, None, 'MEDIUM') # Append rich card and send to the user cluster = messages.MessageCluster().append_message(rich_card) cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; using RCSBusinessMessaging.Cards; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); List<Suggestion> suggestions = new List<Suggestion> { // Create suggestion chips new SuggestionHelper("Suggestion #1", "suggestion_1").SuggestedReply(), new SuggestionHelper("Suggestion #2", "suggestion_2").SuggestedReply() }; string imageUrl = "http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif"; // Create rich card with suggestions StandaloneCard standaloneCard = rbmApiHelper.CreateStandaloneCard( "Hello, world!", "RBM is awesome", imageUrl, MediaHeight.TALL, CardOrientation.VERTICAL, suggestions ); // Send rich card to user rbmApiHelper.SendStandaloneCard(standaloneCard, "+12223334444");
קרוסלות של כרטיסי תצוגה עשירה
כשצריך להציג למשתמש כמה אפשרויות לבחירה, כדאי להשתמש בקרוסלה של כרטיסים עשירים. קרוסלות הן שרשרת של כמה כרטיסים עשירים, שמאפשרת למשתמשים להשוות בין פריטים ולהגיב לכל אחד מהם בנפרד.
קרוסלות יכולות להכיל לפחות שני כרטיסים עשירים ולמעלה מעשרה כרטיסים עשירים. כרטיסים עשירים בקרוסלה חייבים לעמוד בדרישות הכלליות לגבי תוכן וגובה של כרטיסים עשירים.
הגודל המקסימלי של מטען נתונים (payload) של קרוסלה של כרטיסים עשירים הוא 250KB. כאן מפורטות ההמלצות והמגבלות לגבי גודל קובצי המדיה.
חיתוך
בדומה לכרטיסים עשירים, גורמים רבים (כמו רזולוציית המסך, צפיפות הפיקסלים והעדפות המשתמש) משפיעים על המראה של הכרטיסים למשתמשים קצה. לעומת זאת, בקרוסלה, הגובה של הכרטיסים הראשונים קובע את הגובה של כל הכרטיסים בקרוסלה, וגובה הכרטיס משפיע על חיתוך הכותרת, התיאור וההצעות.
אם במכשיר לא ניתן להציג את כל הרכיבים של כרטיס בגלל מגבלות תצוגה או גובה הכרטיס, מערכת RBM חותכת את הכרטיס עד שהוא יכול להופיע במכשיר, לפי הלוגיקה הבאה:
- יש לקצר את התיאור לשורה אחת.
- כדאי לצמצם את השם לשורה אחת.
- להשמיט הצעות שלא נכנסות לכרטיס, החל מסוף הרשימה שהוגדרה.
- להשמיט את התיאור.
- להשמיט את הכותרת.
כדי שהכותרות והתיאורים יוצגו במלואם, חשוב שהם יהיו קצרים ככל האפשר. במדיה אנכית, אפשר להשתמש בכותרת ובתיאור או בהצעה אחת. במדיה בגודל בינוני, אפשר להשתמש עד בשתי הצעות. בסרטונים קצרים, אפשר להשתמש בעד שלוש הצעות. כדי לכלול ארבע הצעות, אין לכלול מדיה בכרטיס.
כדאי שהכרטיסים יהיו דומים בגודל ובאורך התוכן, ואם צריך, כדאי להציב בחלק הקדמי של הקרוסלה כרטיסים גדולים יותר כדי למנוע קיצור של הכרטיסים הבאים.
דוגמה
הקוד הבא שולח קרוסלה של כרטיסים מתקדמים. אפשרויות עיצוב וערכים מפורטות במאמר RichCard
.
cURL
curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentMessages?messageId=MESSAGE_ID&agentId=AGENT_ID" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/rcs-business-messaging" \ -H "`oauth2l header --json PATH_TO_SERVICE_ACCOUNT_KEY rcsbusinessmessaging`" \ -d "{ 'contentMessage': { 'richCard': { 'carouselCard': { 'cardWidth':'MEDIUM', 'cardContents': [ { 'title':'Card #1', 'description':'The description for card #1', 'suggestions': [ { 'reply': { 'text':'Card #1', 'postbackData':'card_1' } } ], 'media': { 'height':'MEDIUM', 'contentInfo': { 'fileUrl':'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg', 'forceRefresh':'false' } } }, { 'title':'Card #2', 'description':'The description for card #2', 'suggestions': [ { 'reply': { 'text':'Card #2', 'postbackData':'card_2' } } ], 'media': { 'height':'MEDIUM', 'contentInfo': { 'fileUrl':'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg', 'forceRefresh': 'false' } } } ] } } } }"
Node.js
// Reference to RBM API helper const rbmApiHelper = require('@google/rcsbusinessmessaging'); // Images for the carousel cards let card1Image = 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg'; let card2Image = 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg'; // Define the card contents for a carousel with two cards, each with one suggested reply let cardContents = [ { title: 'Card #1', description: 'The description for card #1', suggestions: [ { reply: { text: 'Card #1', postbackData: 'card_1', } } ], media: { height: 'MEDIUM', contentInfo: { fileUrl: card1Image, forceRefresh: false, }, }, }, { title: 'Card #2', description: 'The description for card #2', suggestions: [ { reply: { text: 'Card #2', postbackData: 'card_2', } } ], media: { height: 'MEDIUM', contentInfo: { fileUrl: card2Image, forceRefresh: false, }, }, }, ]; // Definition of carousel card let params = { msisdn: '+12223334444', cardContents: cardContents, }; // Send the device the carousel card defined above rbmApiHelper.sendCarouselCard(params, function(response) { console.log(response); });
Java
import com.google.api.services.rcsbusinessmessaging.v1.model.CardContent; import com.google.api.services.rcsbusinessmessaging.v1.model.Suggestion; import com.google.rbm.cards.CardOrientation; import com.google.rbm.cards.CardWidth; import com.google.rbm.cards.MediaHeight; import com.google.rbm.RbmApiHelper; import com.google.rbm.SuggestionHelper; … try { // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(); List cardContents = new ArrayList(); // Images for the carousel cards String card1Image = "https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg"; // Create suggestions for first carousel card List card1Suggestions = new ArrayList(); card1Suggestions.add( new SuggestionHelper("Card #1", "card_1")); cardContents.add( new StandaloneCardHelper( "Card #1", "The description for card #1", card1Image, card1Suggestions) .getCardContent(MediaHeight.SHORT) ); // Images for the carousel cards String card2Image = "https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg"; // Create suggestions for second carousel card List card2Suggestions = new ArrayList(); card2Suggestions.add( new SuggestionHelper("Card #2", "card_2")); cardContents.add( new StandaloneCardHelper( "Card #2", "The description for card #2", card2Image, card2Suggestions) .getCardContent(MediaHeight.SHORT) ); // Send the carousel to the user rbmApiHelper.sendCarouselCards(cardContents, CardWidth.MEDIUM, "+12223334444"); } catch(Exception e) { e.printStackTrace(); }
Python
# Reference to RBM Python client helper and messaging object structure from rcs_business_messaging import rbm_service from rcs_business_messaging import messages # Images for the carousel cards card_image_1 = 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg'; card_image_2 = 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg'; # Suggested replies to be used in the cards suggestions1 = [ messages.SuggestedReply('Card #1', 'reply:card_1') ] suggestions2 = [ messages.SuggestedReply('Card #2', 'reply:card_2') ] # Define the card contents for a carousel with two cards, # each with one suggested reply card_contents = [] card_contents.append(messages.CardContent('Card #1', 'The description for card #1', card_image_1, 'MEDIUM', suggestions1)) card_contents.append(messages.CardContent('Card #2', 'The description for card #2', card_image_2, 'MEDIUM', suggestions2)) # Send the device the carousel card defined above carousel_card = messages.CarouselCard('MEDIUM', card_contents) cluster = messages.MessageCluster().append_message(carousel_card) cluster.send_to_msisdn('+12223334444')
C#
using Google.Apis.RCSBusinessMessaging.v1.Data; using RCSBusinessMessaging; using RCSBusinessMessaging.Cards; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); // Image references to be used in the carousel cards string card1Image = "https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg"; string card2Image = "https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg"; // Suggestion chip lists to be used in carousel cards List<Suggestion> suggestions1 = new List<Suggestion> { new SuggestionHelper("Card #1", "card_1").SuggestedReply() }; List<Suggestion> suggestions2 = new List<Suggestion> { new SuggestionHelper("Card #2", "card_2").SuggestedReply() }; // Create the card content for the carousel List<CardContent> cardContents = new List<CardContent> { // Add items as card content new StandaloneCardHelper( "Card #1", "The description for card #1", card1Image, suggestions1).GetCardContent(), new StandaloneCardHelper( "Card #2", "The description for card #2", card2Image, suggestions2).GetCardContent() }; // Send the carousel to the user rbmApiHelper.SendCarouselCards(cardContents, CardWidth.MEDIUM, msisdn);