REST example

This example shows how you can use the EngageOne™ Communicate API endpoints to trigger email sending in Communicate. In this example, to email the user a transcript of their conversation with the chatbot.

There are three actions and one message interaction.

Example of action interactions in a chatbot

Example of action interactions

Note: See API Usage for details of the Communicate API.

Get Chat History action

This action configures the bot to make an HTML transcript of the messages sent between the bot and the user available in the current session (the context object):
context.chatHistory = system.getChatHistory();

A Set Variable action type is used for this.

EOCM Token action

This action configures the bot to request a machine to machine authentication token from Communicate.

Action type REST
Endpoint https://usersapi.communicate.engageone.co/authenticate
Method POST
Body Pass the credentials for your Communicate account. You obtain these from the Company Management page in Communicate. For example:
{
  "client_id": "1234567@communicate.pb.com",
  "secret": "secret",
  "customer_id": "customerID"
}
Variable Name Stores the authorization token returned by Communicate in the session.

EOCM Send Email action

This action configures the bot to trigger Communicate to send an email to the user set in the body of the request.

Action type REST
Endpoint https://api.us-east-1.communicate.engageone.co
Method POST
Authorization The authorization token acquired from Communicate. For example:
Bearer {my-variable}
Headers Your Communicate customer ID:
  • Header Name is always PB-Customer-Id
  • Value is your customer ID
Body The data required by the communication in Communicate. The data must conform to the schema of the data source selected for the communication. For example:
{
    "communication": "Thanks",
    "dataset": [{
        "name": "Henry",
        "email": "an-email-address",
        "chatHistory": "{{chatHistory}}"
    }],
    "email_json_path": "$[*].email",
    "sender": "eocommunicate-dev@pb.com",
    "subject": "Thanks for contacting us today",
    "ignore_missing_fields": true,
    "project": "my-project"
}