Invia eventi

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

Per le opzioni complete di formattazione e valore, consulta la documentazione di riferimento di phones.agentEvents.

Per informazioni dettagliate sugli eventi webhook che il tuo agente riceve dalla piattaforma RBM, vedi Ricevere eventi.

L'agente invia un evento READ

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

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

L'agente invia un evento IS_TYPING

Per gli utenti, questo evento viene visualizzato come 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 20 secondi) o quando il dispositivo dell'utente riceve un nuovo messaggio dal tuo agente. L'agente può inviare più eventi IS_TYPING per reimpostare il timer di scadenza dell'indicatore di digitazione.

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 campione 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 campione 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 campione 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 campione RBM.