Wydarzenia

W przykładach poniżej rbm_api_helper.js (nieużywane w przypadku Pythona) zakłada, że plik, w którym pracujesz, znajduje się w katalogu o jeden poziom niżej niż główny folder aplikacji. W zależności od konfiguracji projektu może być konieczne dostosowanie lokalizacji.

Odczytywanie zdarzeń

Zdarzenia odczytu informują użytkownika, że agent otrzymał wiadomość, i dają pewność, że platforma RCS Business Messaging dostarczyła wiadomość. Poniższy kod wysyła zdarzenie odczytu do urządzenia z biblioteką klienta.

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

// Send the device an event to indicate that messageId has been read
rbmApiHelper.sendReadMessage('+12223334444', messageId);
Ten kod to fragment przykładowego agenta RBM.

Java

import com.google.rbm.RbmApiHelper;


// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper();

// Send the device an event to indicate that messageId has been read
rbmApiHelper.sendReadMessage(messageId, "+12223334444");
Ten kod to fragment przykładowego agenta RBM.

Python

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service

# Send the device an event to indicate that message_id was read
rbm_service.send_read_event('+12223334444', message_id)
Ten kod to fragment przykładowego agenta RBM.

C#

using RCSBusinessMessaging;


// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                                 projectId);

// Send the device an event to indicate that messageId has been read
rbmApiHelper.SendReadMessage(messageId, "+12223334444");
Ten kod to fragment przykładowego agenta RBM.

Wydarzenia związane z pisaniem

Zdarzenia pisania informują użytkownika, że agent pisze wiadomość. Poniższy kod wysyła zdarzenie pisania na urządzenie z biblioteką klienta.

Node.js

// Reference to RBM API helper
const rbmApiHelper = require('@google/rcsbusinessmessaging');

// Send the device an event to indicate that the agent is typing
rbmApiHelper.sendIsTypingMessage('+12223334444', function() {
    console.log('Typing event sent!');
});
Ten kod to fragment przykładowego agenta RBM.

Java

import com.google.rbm.RbmApiHelper;


// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper();

// Send the device an event to indicate that the agent is typing
rbmApiHelper.sendIsTypingMessage("+12223334444");
Ten kod to fragment przykładowego agenta RBM.

Python

# Reference to RBM Python client helper and messaging object structure
from rcs_business_messaging import rbm_service

# Send the device an event to indicate that the agent is typing
rbm_service.send_is_typing_event('+12223334444')
Ten kod to fragment przykładowego agenta RBM.

C#

using RCSBusinessMessaging;


// Create an instance of the RBM API helper
RbmApiHelper rbmApiHelper = new RbmApiHelper(credentialsFileLocation,
                                                 projectId);

// Send the device an event to indicate that the agent is typing
rbmApiHelper.SendIsTypingMessage(messageId, "+12223334444");
Ten kod to fragment przykładowego agenta RBM.