Agenty RBM komunikują się z użytkownikami przez wysyłanie i odbieranie wiadomości. Aby wysyłać wiadomości do użytkowników, agent wysyła żądania wiadomości do interfejsu RCS Business Messages API. Pojedyncze żądanie może zawierać tekst, kartę informacyjną, obraz lub film, a także sugerowane odpowiedzi i działania.
Jeśli wyślesz wiadomość do użytkownika, którego urządzenie nie obsługuje RCS lub nie ma włączonego RCS, platforma RBM zwróci błąd 404. W takim przypadku możesz spróbować dotrzeć do użytkownika, korzystając z metod zastępczych zdefiniowanych w Twojej infrastrukturze.
Jeśli wyślesz wiadomość do użytkownika RCS w sieci, w której agent nie został jeszcze uruchomiony, lub w sieci, w której ruch RCS nie został włączony, platforma RBM zwróci błąd 403.
Jeśli wyślesz wiadomość z funkcjami, których urządzenie użytkownika nie obsługuje, platforma RBM zwróci błąd i nie dostarczy wiadomości.
Maksymalny rozmiar całego ciągu znaków AgentMessage to 250 KB.
Wysyłanie do użytkownika offline
Platforma RBM nadal akceptuje dostarczenie wiadomości, jeśli odbiorca jest offline. Otrzymasz 200 odpowiedzi OK, a platforma RBM blokuje wiadomość i próbuje ponownie ją dostarczyć przez 30 dni. Nie trzeba prosić RBM o ponowne wysłanie wiadomości.
RBM usuwa wszystkie niedostarczone wiadomości po 30 dniach od ich przesłania.
W zależności od przypadku użycia agenta możesz unieważnić niedostarczoną wiadomość przed upływem tego 30-dniowego limitu czasu. Odwołanie może zapobiec otrzymywaniu nieaktualnych wiadomości, gdy powrócą do trybu online. Wiadomość można anulować na kilka sposobów:
- Wyślij prośbę o unieważnienie, aby aktywować ją.
- Ustaw datę wygaśnięcia wiadomości, aby automatycznie ją unieważnić w odpowiednim momencie.
Ustawianie daty wygaśnięcia wiadomości
Czy Twój agent jest pilny? Na przykład hasła jednorazowe są ważne tylko przez krótki czas. Oferty ograniczone czasowo wygasną. Przypomnienia o spotkaniach nie mają znaczenia po dacie spotkania. Aby otrzymywać trafne i aktualne wiadomości, ustaw czas ich wygaśnięcia. Dzięki temu użytkownicy offline nie będą otrzymywać nieaktualnych treści, gdy powrócą do trybu online. Wygaśnięcie ważności jest również dobrym sposobem na wywołanie zastępczej strategii przesyłania wiadomości, dzięki czemu użytkownicy otrzymają potrzebne informacje na czas.
Aby ustawić datę wygaśnięcia wiadomości, w wiadomości agenta podaj jedno z tych pól:
expireTime
: dokładny czas wygaśnięcia wiadomości (w strefie czasowej UTC).ttl
(czas życia): czas, po którym wiadomość wygaśnie.
Opcje formatowania i wartości znajdziesz w sekcji AgentMessage
.
Gdy wiadomość wygaśnie, platforma RBM przestaje próbować dostarczyć wiadomość i zostaje automatycznie unieważniona. Jednak w rzadkich przypadkach może to się nie udać. Na przykład interfejs API może aktywować odwołanie, gdy platforma RBM była w trakcie dostarczania wiadomości. Aby sprawdzić, czy wygasła wiadomość została anulowana, RBM wyśle zdarzenie z powiadomieniem do webhooka.
Tekst
Najprostsze komunikaty składają się z tekstu. SMS-y najlepiej nadają się do przekazywania informacji bez użycia elementów wizualnych, skomplikowanej interakcji i reakcji.
Przykład
Poniższy kod powoduje wysłanie prostego SMS-a. Opcje formatowania i wartości znajdziesz tutaj: 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); });Ten kod jest fragmentem przykładowego agenta RBM.
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(); }Ten kod jest fragmentem przykładowego agenta RBM.
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')Ten kod jest fragmentem przykładowego agenta RBM.
C#
using RCSBusinessMessaging; … // Create an instance of the RBM API helper RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation, projectId); rbmApiHelper.SendTextMessage( "Hello, world!", "+12223334444", );Ten kod jest fragmentem przykładowego agenta RBM.
Podstawowa treść wiadomości – konwersja SMS-ów
Operatorzy wprowadziliśmy modele płatności, które umożliwiają przenoszenie SMS-ów do RBM. Wiadomość RBM zawierająca maksymalnie 160 znaków UTF-8 jest nazywana wiadomością podstawową.
Podczas tworzenia żądania wysyłania wiadomości podstawowej pamiętaj, że znaki mają jeden bajt (UTF-8). Jeśli wyślesz wiadomość zawierającą znaki specjalne, np. emotikon lub zestaw znaków wielobajtowych, każdy znak zostanie zliczony jako 2 znaki UTF-8.
Wpisz w polu tekst, aby sprawdzić jego długość:
Hasła jednorazowe do weryfikacji użytkowników
Za pomocą RBM możesz wysyłać hasła jednorazowe w celu automatycznej weryfikacji użytkowników za pomocą interfejsu SMS Retriever API. Więcej informacji o module odbioru SMS-ów i powiązanych z nim interfejsach API znajdziesz w dokumentacji modułu odbioru SMS-ów. Szczegółowe informacje o automatycznej weryfikacji użytkowników w aplikacjach zarejestrowanych przy użyciu interfejsu SMS Retriever API znajdziesz na tym schemacie przepływu.
W trakcie procesu weryfikacji interfejs SMS Retriever API nasłuchuje wiadomości RBM. Wiadomość musi zawierać hasło jednorazowe i hash, który identyfikuje aplikację. Po dopasowaniu skrótu do aplikacji hasło jednorazowe jest wyodrębniane i przekazywane do aplikacji w celu automatycznej weryfikacji użytkownika.
Oto przykładowy komunikat RBM na temat weryfikacji użytkownika: Twój kod to <OTP> <identyfikator aplikacji>.
Na przykład: Your code is 123456 M8tue43FGT.
Pliki multimedialne i PDF
Gdy wysyłasz wiadomość z obrazem, filmem lub plikiem PDF, agent musi podać publicznie dostępny adres URL treści lub bezpośrednio przesłać plik. W przypadku plików multimedialnych możesz też określić miniaturę, która umożliwia użytkownikom wyświetlenie podglądu treści przed jej kliknięciem.
Platforma RBM zapisuje pliki w pamięci podręcznej przez 60 dni, a interfejs API zwraca identyfikator pliku, który agent może dołączać do wiadomości do użytkowników. Po 60 dniach RBM usuwa pliki z pamięci podręcznej.
Zapoznaj się ze sprawdzonymi metodami, aby dowiedzieć się więcej o zalecanych rozmiarach plików i ich limitach.
Przykład adresu URL pliku
Ten kod wysyła obraz. Opcje formatowania i wartości znajdziesz tutaj: 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); });Ten kod jest fragmentem przykładowego agenta RBM.
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(); }Ten kod jest fragmentem przykładowego agenta RBM.
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')Ten kod jest fragmentem przykładowego agenta RBM.
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");Ten kod jest fragmentem przykładowego agenta RBM.
Możesz też przesłać multimedia przed wysłaniem ich w wiadomości w files.create
.
Przykład przesyłania pliku
Podany niżej kod przesyła plik wideo i plik miniatury, a potem wysyła oba pliki w wiadomości. Opcje formatowania i wartości znajdziesz w sekcjach files.create
i 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' } } }"
Obsługiwane typy multimediów
RBM obsługuje te typy multimediów:
Typ zawartości | Typ dokumentu | Rozszerzenie | Działa z kartami rozszerzonymi |
---|---|---|---|
aplikacja/pdf | PDF. | Nie | |
image/jpeg | JPEG | .jpeg, .jpg | Tak |
image/gif | GIF | .gif | Tak |
image/png | PNG | .png | Tak |
film/h263 | Film H263 | H263 | Tak |
wideo/M4V | wideo M4V | M4V | Tak |
video/mp4 | Film MP4 | .mp4 | Tak |
film/mpeg4 | Film MPEG-4 | .mp4, .m4p | Tak |
film/mpeg | Wideo MPEG | MPEG | Tak |
film/webm | Wideo w formacie WEBM | .webm, | Tak |
Sugerowane odpowiedzi
Sugerowane odpowiedzi pomagają użytkownikom w rozmowie, podając odpowiedzi, na które agent będzie wiedział, jak zareagować. Agent wysyła sugerowane odpowiedzi na listach elementów sugestii lub na kartach rozszerzonych.
Gdy użytkownik kliknie sugerowaną odpowiedź, agent otrzyma zdarzenie zawierające tekst odpowiedzi i dane wywołania zwrotnego.
Sugerowane odpowiedzi mogą mieć maksymalnie 25 znaków.
Przykład
Podany niżej kod wysyła tekst z 2 sugerowanymi odpowiedziami. Opcje formatowania i wartości znajdziesz w sekcji 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); });Ten kod jest fragmentem przykładowego agenta RBM.
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(); }Ten kod jest fragmentem przykładowego agenta RBM.
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')Ten kod jest fragmentem przykładowego agenta RBM.
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 );Ten kod jest fragmentem przykładowego agenta RBM.
Sugerowane działania
Sugerowane działania prowadzą użytkowników przez rozmowy, pozostawiając natywną funkcjonalność urządzeń. Agent może zasugerować użytkownikom wybranie numeru, otwarcie lokalizacji na mapie, udostępnienie lokalizacji, otwarcie adresu URL lub utworzenie wydarzenia w kalendarzu. Agent wysyła sugerowane działania na listach elementów sugestii lub na kartach rozszerzonych.
Gdy użytkownik kliknie sugerowane działanie, agent otrzyma zdarzenie zawierające dane dotyczące wywołania zwrotnego tego działania.
Sugerowane działania mogą mieć maksymalnie 25 znaków.
Opcje formatowania i wartości znajdziesz tutaj: SuggestedAction
.
Wybieranie numeru
Czynność Wybierz, aby użytkownik wskazał numer telefonu podany przez agenta. Numery telefonów muszą zawierać +
, kod kraju i numer kierunkowy na początku, ale nie powinny zawierać separatorów. Na przykład: +14155555555
.
Przykład
Ten kod powoduje wysłanie czynności umożliwiającej wybranie telefonu. Opcje formatowania i wartości znajdziesz tutaj: 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); });Ten kod jest fragmentem przykładowego agenta RBM.
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(); }Ten kod jest fragmentem przykładowego agenta RBM.
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')Ten kod jest fragmentem przykładowego agenta RBM.
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 );Ten kod jest fragmentem przykładowego agenta RBM.
Wyświetlanie lokalizacji
Działanie Wyświetl lokalizację pozwala wyświetlić lokalizację w domyślnej aplikacji z mapami użytkownika. Lokalizację możesz określić za pomocą szerokości i długości geograficznej lub za pomocą zapytania opartego na bieżącej lokalizacji użytkownika. Możesz też ustawić etykietę własną dla pinezki, która będzie wyświetlana w aplikacji do map.
Przykład
Ten kod wysyła działanie wyświetlenia lokalizacji. Opcje formatowania i wartości znajdziesz tutaj: 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); });Ten kod jest fragmentem przykładowego agenta RBM.
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(); }Ten kod jest fragmentem przykładowego agenta RBM.
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')Ten kod jest fragmentem przykładowego agenta RBM.
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 );Ten kod jest fragmentem przykładowego agenta RBM.
Udostępnianie lokalizacji
Działanie Udostępnij lokalizację pozwala użytkownikowi wysłać lokalizację do agenta. Lokalizacja podana przez użytkownika nie musi być jego lokalizacją.
Przykład
Ten kod wysyła działanie związane z udostępnianiem lokalizacji. Opcje formatowania i wartości znajdziesz tutaj: 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); });Ten kod jest fragmentem przykładowego agenta RBM.
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(); }Ten kod jest fragmentem przykładowego agenta RBM.
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')Ten kod jest fragmentem przykładowego agenta RBM.
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 );Ten kod jest fragmentem przykładowego agenta RBM.
Otwieranie adresu URL
Działanie „Otwórz URL” powoduje otwarcie określonego adresu URL w przeglądarce użytkownika. Jeśli aplikacja jest zarejestrowana jako domyślny moduł obsługi adresu URL, otwiera się ona w zamian, a ikona działania jest ikoną aplikacji.
Przykład
Ten kod wysyła działanie polegające na otwarciu adresu URL. Opcje formatowania i wartości znajdziesz tutaj: 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); });Ten kod jest fragmentem przykładowego agenta RBM.
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(); }Ten kod jest fragmentem przykładowego agenta RBM.
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')Ten kod jest fragmentem przykładowego agenta RBM.
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 );Ten kod jest fragmentem przykładowego agenta RBM.
Utwórz wydarzenie w kalendarzu
Czynność Utwórz wydarzenie w kalendarzu powoduje otwarcie aplikacji kalendarza użytkownika i rozpoczęcie tworzenia nowego wydarzenia z użyciem określonych informacji.
Przykład
Poniższy kod wysyła działanie tworzenia wydarzenia w kalendarzu. Opcje formatowania i wartości znajdziesz w sekcji 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); });Ten kod jest fragmentem przykładowego agenta RBM.
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(); }Ten kod jest fragmentem przykładowego agenta RBM.
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')Ten kod jest fragmentem przykładowego agenta RBM.
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 );Ten kod jest fragmentem przykładowego agenta RBM.
Lista elementów sugestii
Agent wysyła listy elementów sugestii z wiadomościami, aby pomóc użytkownikom w dalszych działaniach. Lista elementów jest wyświetlana tylko wtedy, gdy powiązana wiadomość znajduje się u dołu rozmowy. Wszystkie kolejne wiadomości w wątku (od użytkownika lub agenta) zastępują listę elementów.
Elementy na liście to sugerowane odpowiedzi i sugerowane działania.
Listy elementów mogą zawierać maksymalnie 11 elementów sugestii, a każda etykieta elementu może mieć maksymalnie 25 znaków.
Opcje formatowania i wartości znajdziesz tutaj: AgentContentMessage
.
Karty informacyjne
Jeśli chcesz wysłać fragment powiązanych informacji, multimediów lub sugestii, użyj karty informacyjnej. Karty informacyjne umożliwiają agentowi wysyłanie wielu jednostek informacji w jednej wiadomości.
Karty informacyjne mogą zawierać te elementy:
- Obraz/film
- Tekst tytułu
- Tekst opisu
- Lista sugerowanych odpowiedzi i sugerowanych działań (maksymalnie 4)
Karta informacyjna może zawierać wszystkie wymienione elementy, ale aby karta była poprawna, musi zawierać co najmniej obraz, film lub tytuł. Karta informacyjna może zawierać maksymalnie 4 sugerowane działania lub sugerowane odpowiedzi. Nie może zawierać kombinacji sugerowanych działań i sugerowanych odpowiedzi na jednej karcie.
Agent może wysłać wiele kart rozszerzonych w karuzeli kart rozszerzonych.
Wysokość karty
Karty rozwijają się w pionie, aby dopasować się do treści. Karty rozszerzone mają minimalną wysokość 112 DP, a maksymalną 344 DP. Jeśli zawartość karty nie jest wystarczająco duża, aby wypełnić minimalną wysokość, karta rozwinie się i wypełnia dodatkowy obszar odstępem.
Pliki multimedialne na kartach rozszerzonych muszą mieć jeden z 3 formatów:
- Krótki: 112 DP
- Średnia: 168 DP
- Wysoki: 264 DP
Jeśli multimedia nie mieszczą się w wymiarach na karcie dla wybranej wysokości, podgląd multimediów jest wybierany przez powiększenie i przycięcie multimediów.
Przykład
Podany niżej kod wysyła kartę informacyjną z obrazem i sugerowanymi odpowiedziami. Opcje formatowania i wartości znajdziesz tutaj: 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); });Ten kod jest fragmentem przykładowego agenta RBM.
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(); }Ten kod jest fragmentem przykładowego agenta RBM.
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')Ten kod jest fragmentem przykładowego agenta RBM.
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");Ten kod jest fragmentem przykładowego agenta RBM.
Karuzele kart rozszerzonych
Jeśli chcesz przedstawić użytkownikowi kilka opcji do wyboru, użyj karuzeli kart informacyjnych. Karuzele są łączone ze sobą wiele kart rozszerzonych, co umożliwia użytkownikom porównywanie elementów i reagowanie na każdą z nich z osobna.
Karuzele może zawierać od 2 do 10 kart rozszerzonych. Karty informacyjne w karuzeli muszą być zgodne z ogólnymi wymaganiami dotyczącymi kart rozszerzonych w zakresie treści i wysokości.
Obcinanie
Tak jak w przypadku kart rozszerzonych, na sposób wyświetlania kart wpływa wiele czynników (takich jak rozdzielczość ekranu, gęstość pikseli i preferencje użytkownika). Wysokość kilku pierwszych kart w karuzeli określa jednak wysokość wszystkich kart w karuzeli, a wysokość kart ma wpływ na tytuł i opis oraz na skrócenie sugestii.
Jeśli urządzenie nie może wyświetlić wszystkich elementów karty z powodu ograniczeń w wyświetlaniu lub wysokości karty, RBM obcina kartę do czasu, aż będzie mogła zostać wyświetlona na urządzeniu. Obowiązują następujące zasady:
- Skróć tekst reklamy do jednego wiersza.
- Skróć tytuł do jednego wiersza.
- Pomiń sugestie, które nie mieszczą się na karcie, zaczynając od końca zdefiniowanej listy.
- Pomiń opis.
- Pomiń tytuł.
Aby uniknąć obcięcia tytułów, używaj jak najkrótszych tytułów i opisów. W przypadku długich multimediów użyj tytułu i opisu lub jednej sugestii. W mediach multimedialnych możesz użyć maksymalnie 2 sugestii. W przypadku krótkich multimediów możesz użyć maksymalnie 3 sugestii. Aby zmieścić 4 sugestie, na karcie nie umieszczaj multimediów.
Karty powinny być mniej więcej jednakowe pod względem rozmiaru i długości. W razie potrzeby umieść karuzelę z większymi kartami z wyprzedzeniem, aby uniknąć obcięcia kolejnych kart.
Przykład
Poniższy kod wysyła karuzelę kart rozszerzonych. Opcje formatowania i wartości znajdziesz tutaj: 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); });Ten kod jest fragmentem przykładowego agenta RBM.
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(); }Ten kod jest fragmentem przykładowego agenta RBM.
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')Ten kod jest fragmentem przykładowego agenta RBM.
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);Ten kod jest fragmentem przykładowego agenta RBM.