Create message

Post messages to any chat on behalf of a customer
Written by Alexander Shpilka
Updated 9 months ago

With this endpoint you can send messages on behalf of a customer and get response in the same request

  • Key Concepts:

    1. Publishing a new message without specifying a chatId will result in the creation of a new chat.
    In the response, you will receive the chatId of the newly created chat.
    This chatId can be used for future interactions with the chat, such as sending additional/follow-up messages.


    2. If a chatId is specified, the new message will be added to the existing chat. The chat history will be utilized to generate a more contextually accurate response.

    3. You have the option to provide your own messagesHistory which will be taken into account during the generation of the answer.
    However
    , please note that if a chatId is already provided, your custom chatHistory will be disregarded.

➡️ Request

URL https://www.ribbo.ai/api/v1/messages
Method POST
Headers

Authorization: Bearer <your_api_key>

Accept: application/json

Content-Type: application/json

Read more about authentication headers here.

➡️ Parameters

Parameter Type Description
message string The question to ask the bot.

required

1 to 1000 characters

applicationId string

The ID of the chat application. You can find it in your application Settings tab.

required
chatId string

The ID of the chat to publish follow up question.

If not specified, new chat will be created

optional

return_sources boolean Whether to return the sources that were used for answer generation

optional

default: false

format string

How to format the answer.

Can be markdown or text.

optional

default: markdown

messagesHistory array

The chat history array.

Required format:
[
{"author":"user", "content": {"value":"message text"}}
]

optional

default: []

user_data object

A user identification object with metadata about the the user. 

Required format:

{
 "name": "user name", "email": "user email",
 "phone": "user phone"
}

optional

➡️ Example of request body

{
    "message": "What is the cheapest plan you offer?",
    "applicationId": "68G4zk6jieG6Z6Nbw6ns",
    "format": "text",
    "return_sources": true,
    "user_data": {"name": "Alex", "email":"[email protected]", "phone": "239847"}
}

➡️ Example of request (cURL)

curl --location 'https://www.ribbo.ai/api/v1/messages' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <API_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
    "message": "what is the cheapest pricing option you offer?",
    "applicationId": "O8G6666688ZbNbwDns",
    "format": "text",
    "return_sources": true,
    "user_data": {"name": "Alex", "email":"[email protected]", "phone": "239847"},
    "messagesHistory" : [
      {"author":"user", "content": {"value":"Hey how much for Enterprise plan?"}}, 
      {"author":"operator", "content": {"value":"Hi! Can you clarify what features you need from Enterprise plan?"}}
    ]
}'

➡️ Example of request (NodeJs)

const axios = require('axios');

const API_TOKEN = '<API_TOKEN>'; // Replace with your actual API token

const data = {
  message: "what is the cheapest pricing option you offer?",
  applicationId: "O8G6666688ZbNbwDns",
  format: "text",
  return_sources: true,
  user_data: {"name": "Alex", "email":"[email protected]", "phone": "239847"},
  messagesHistory : [
    {"author":"user", "content": {"value":"Hey how much for Enterprise plan?"}}, 
    {"author":"operator", "content": {"value":"Hi! Can you clarify what features you need from Enterprise plan?"}}
  ]
};

axios({
  method: 'post',
  url: 'https://www.ribbo.ai/api/v1/messages',
  headers: {
    'Accept': 'application/json',
    'Authorization': `Bearer ${API_TOKEN}`,
    'Content-Type': 'application/json'
  },
  data: data
}).then(response => {
  console.log(response.data);
}).catch(error => {
  console.error(error);
});

➡️ Example of response 

{
  "statusCode":200,
  "data":{
    "answer":"The cheapest pricing option we offer is the Small plan, which costs $19.99 per month.",
    "chatId":"FVGwIwukDfvg6MHzzkNA",
    "sources":[
      {"title":"Pricing | LiveReacting", "url":"https://www.livereacting.com/pricing"},
    ]
  }
}
You can utilize the chatId for your next requests for follow-up questions. By doing so, the existing chat history will be reused to generate more accurate responses.

Did this answer your question?