Invia eventi

L'agente invia eventi di stato al dispositivo dell'utente per simulare le interazioni umane. Per gli utenti, questi eventi vengono visualizzati come conferme di lettura o indicatori di digitazione, assicurando loro che i loro messaggi vengono elaborati.

Per le opzioni complete di formattazione e valori, consulta il riferimento phones.agentEvents.

Per informazioni dettagliate sugli eventi webhook che l'agente riceve dalla piattaforma RBM, consulta Ricevi eventi.

L'agente invia un evento READ

Per gli utenti, questo evento viene visualizzato come conferma di lettura di un messaggio specifico. In questo modo, l'utente sa che la piattaforma RBM ha recapitato il suo messaggio e che l'agente lo sta elaborando.

Gli eventi READ vengono mantenuti e archiviati per 30 giorni. Se l'utente ha attivato RCS, ma non è raggiungibile, l'evento viene messo in coda. Se non hanno attivato RCS, la piattaforma RCS for Business restituisce un errore NOT_FOUND (HTTP 404).

Il seguente codice invia un evento READ per un messaggio con un messageId corrispondente.

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentEvents?eventId=EVENT_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 "{
  'eventType': 'READ',
  'messageId': 'MESSAGE_ID'
}"

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);
Questo codice è un estratto di un agente RBM di esempio.

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");
Questo codice è un estratto di un agente di esempio 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)
Questo codice è un estratto di un agente RBM di esempio.

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");
Questo codice è un estratto di un agente RBM di esempio.

L'agente invia un evento IS_TYPING

Per gli utenti, questo evento viene visualizzato come un indicatore di digitazione e li informa che l'agente sta componendo un messaggio. L'indicatore di digitazione scade dopo un breve periodo di tempo (circa 5 secondi per impostazione predefinita) o quando il dispositivo dell'utente riceve un nuovo messaggio dall'agente. L'agente può inviare più eventi IS_TYPING per reimpostare il timer di scadenza dell'indicatore di digitazione.

Gli eventi IS_TYPING sono temporanei e non vengono messi in coda.

Il seguente codice invia un evento IS_TYPING.

cURL

curl -X POST "https://REGION-rcsbusinessmessaging.googleapis.com/v1/phones/PHONE_NUMBER/agentEvents?eventId=EVENT_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 "{
  'eventType': 'IS_TYPING',
}"

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!');
});
Questo codice è un estratto di un agente di esempio 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");
Questo codice è un estratto di un agente di esempio 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')
Questo codice è un estratto di un agente di esempio 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");
Questo codice è un estratto di un agente RBM di esempio.