Your first test in 5 minutes

In 5 minutes, you run a first conversation with your bot from a terminal and read its answers. Each step is one call to the Evaluation API, shown with the real answer of a test bot, shortened. Identifiers are cut with … in the examples.

How a conversation runs

The bot takes from 1 to 60 seconds to answer, so the API does not keep you waiting: it accepts each message at once, and you read the answer when it is ready.

Get a token, open a simulation, send a message, read the turn until it is completed, repeat for each message, then close

  • A simulation is one conversation with the bot.
  • A turn is the bot's answer to one of your messages: your first message gives turn 1, the next one turn 2, and so on.

Before you start

  • The client ID and the client secret of an application, given by a Manager of the bot: see Applications.
  • The address of the API: https://chatbot.viasay.io/api. If your Manager sees another address under API endpoints in Settings › Applications, take the part before /oauth/token.
  • A terminal with curl and jq, a tool that reads JSON. On a Mac: brew install jq.

Store these values once, between single quotes so that a ! or a $ in the secret is kept as is:

BASE='https://chatbot.viasay.io/api'
CLIENT_ID='paste-your-client-ID'
CLIENT_SECRET='paste-your-client-secret'

Step 1: Get a token

TOKEN=$(curl -s -X POST "$BASE/oauth/token" \
  -u "${CLIENT_ID}:${CLIENT_SECRET}" \
  -d grant_type=client_credentials | jq -r .access_token)
curl -s "$BASE/v1/evaluation/me" -H "Authorization: Bearer $TOKEN" | jq
{ "client_id": "eJ67c14T…", "name": "Partner CI", "scopes": ["evaluation:read", "evaluation:write"], "token_expires_in": 3600 }

The token is valid for 1 hour. If echo $TOKEN prints null, the client ID or the secret is wrong.

Note: a new token revokes the previous one that has the same scopes. Get one token and reuse it for the hour.

Step 2: Open a simulation

The simulation below talks to the whole bot ("type": "bot"), on the last saved version of its use cases ("version": "draft").

SIM=$(curl -s -X POST "$BASE/v1/evaluation/simulations" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{ "target": { "type": "bot" }, "version": "draft" }' | jq -r .simulation_id)
echo $SIM

It prints the identifier of the simulation, for example sim_784b7c9a…. A simulation expires after 15 minutes without a message.

Step 3: Send a message

Replace the text with a question your bot handles.

curl -s -X POST "$BASE/v1/evaluation/simulations/$SIM/messages" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{ "text": "I want to change the dates of my booking" }'
{ "turn": 1, "status": "pending" }

The API accepted the message: the bot is preparing turn 1.

Step 4: Read the bot's answer

Read turn 1. ?trace=none leaves out the trace of the turn (its steps, API calls and variables), which is long.

curl -s "$BASE/v1/evaluation/simulations/$SIM/turns/1?trace=none" \
  -H "Authorization: Bearer $TOKEN" | jq

While the bot prepares its answer, you get "status": "pending". Run the command again every 1 to 2 seconds: the answer usually comes within 15 seconds, 60 at most.

{
  "turn": 1,
  "status": "completed",
  "state": "awaiting_user",
  "answers": [ { "text": "To find your stay, I need your booking number and your last name.", "quick_replies": [], "buttons": [], "ai_generated": true } ],
  "handled_by": { "type": "use_case", "use_case_id": 5190, "name": "Post-Booking", "intent_record_id": 7907 },
  "waiting_for": { "question": "To find your stay, I need your booking number and your last name.", "expects": "free_text", "variable_name": "reply" },
  "duration_ms": 8473,
  "warnings": []
}

The table below says what each field of this turn tells you.

FieldWhat it tells you
statusthe turn is over (completed), or failed (timeout, error)
answersthe bot's bubbles, with their quick replies and buttons
handled_bywho answered: here the use case 5190, picked by the bot from your message
statewhere the conversation stands: awaiting_user means the bot waits for an answer
waiting_forthe question asked and the type of answer expected

Step 5: Reply, then close

Each message gives the next turn: your reply is turn 2.

curl -s -X POST "$BASE/v1/evaluation/simulations/$SIM/messages" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{ "text": "AB12CD34EF56, Martin" }'
curl -s "$BASE/v1/evaluation/simulations/$SIM/turns/2?trace=none" \
  -H "Authorization: Bearer $TOKEN" | jq

To click a quick reply or a button of the previous turn, send its label instead: { "click": "Yes" }. When the conversation is over, close the simulation:

curl -s -X DELETE "$BASE/v1/evaluation/simulations/$SIM" \
  -H "Authorization: Bearer $TOKEN" | jq .status

It prints "completed". The simulation stays readable until 90 days after it was opened, with GET /v1/evaluation/simulations/{id}.

If it does not work

Every error of /v1/evaluation/… gives a code and a request_id to send to the support team. /oauth/token answers in the OAuth format, {"error": "…", "error_description": "…"}.

  • $TOKEN is null, or 401 invalid_client on /oauth/token: the client ID or the secret is wrong. If the secret is lost, ask the Manager to regenerate it.
  • 401 invalid_token: the token expired after 1 hour, or it was revoked: by a newer token with the same scopes (the Test button of Settings › Applications included), or because the Manager regenerated the secret, removed a scope or deleted the application. Get a new token.
  • 403 insufficient_scope: the application lacks evaluation:write or evaluation:read. Ask the Manager to add it.
  • 409 turn_in_progress: the previous turn is still pending. Wait until it is over.
  • 409 simulation_closed or 410 simulation_expired: open a new simulation.
  • 422 use_case_not_published: with live, the use case was never published. Use draft, or publish it.

Next steps


Did this page help you?