Pipecat C++ Client SDK 1.0.0
Connect native apps to Pipecat bots
Loading...
Searching...
No Matches
messages.h
Go to the documentation of this file.
1//
2// Copyright (c) 2024-2026, Daily
3//
4// SPDX-License-Identifier: BSD-2-Clause
5//
6
9
10#ifndef PIPECAT_RTVI_MESSAGES_H
11#define PIPECAT_RTVI_MESSAGES_H
12
13#include <nlohmann/json.hpp>
14
15#include <cstdint>
16#include <optional>
17#include <string>
18#include <vector>
19
29namespace pipecat::rtvi {
30
32inline constexpr const char* PROTOCOL_VERSION = "2.1.0";
33
35inline constexpr const char* MESSAGE_LABEL = "rtvi-ai";
36
75
77const char* to_string(MessageType type);
78
80std::optional<MessageType> parse_message_type(const std::string& type);
81
85 std::string library;
87 std::optional<std::string> library_version;
89 std::optional<std::string> platform;
91 std::optional<std::string> platform_version;
93 nlohmann::json platform_details;
94};
95
98
102 std::string type;
104 nlohmann::json data;
105};
106
110 std::optional<bool> run_immediately;
112 std::optional<bool> audio_response;
113};
114
118 std::string function_name;
120 std::string tool_call_id;
122 nlohmann::json arguments;
124 nlohmann::json result;
125};
126
130 std::string version;
132 nlohmann::json about;
133};
134
136struct ErrorData {
138 std::string error;
140 bool fatal = false;
141};
142
146 std::string text;
148 bool final = false;
150 std::string timestamp;
152 std::string user_id;
153};
154
156struct TextData {
158 std::string text;
159};
160
163
166
169
173 std::string accumulated_text;
175 std::string remaining_text;
176};
177
184 std::string text;
186 std::string aggregated_by;
188 std::optional<int64_t> segment_id;
190 std::optional<bool> will_be_spoken;
192 std::optional<std::string> spoken_status;
194 std::optional<SpokenProgressData> spoken_progress;
195};
196
200 std::string processor;
202 std::optional<std::string> model;
204 double value = 0;
205};
206
210 std::vector<MetricData> ttfb;
212 std::vector<MetricData> processing;
214 std::vector<MetricData> characters;
216 nlohmann::json raw;
217};
218
222 std::optional<std::string> function_name;
223};
224
228 std::optional<std::string> function_name;
230 std::string tool_call_id;
233 nlohmann::json arguments;
234};
235
239 std::optional<std::string> function_name;
241 std::string tool_call_id;
243 bool cancelled = false;
245 nlohmann::json result;
246};
247
251 std::string text;
253 std::vector<double> confidence;
254};
255
259 std::optional<std::string> site_uri;
261 std::optional<std::string> site_title;
263 std::vector<LLMSearchResult> results;
264};
265
269 std::optional<std::string> search_result;
271 std::optional<std::string> rendered_content;
273 std::vector<LLMSearchOrigin> origins;
274};
275
280struct Message {
282 std::string id;
284 std::string label = MESSAGE_LABEL;
286 std::string type;
288 nlohmann::json data;
289
291 Message() = default;
292
294 explicit Message(MessageType type, nlohmann::json data = nullptr);
295
298
301
303 static Message
304 client_message(const std::string& type, const nlohmann::json& data);
305
307 static Message
308 send_text(const std::string& content, const SendTextOptions& options = {});
309
311 static Message dtmf(const std::string& buttons);
312
316 );
317};
318
319//
320// JSON conversions, used by nlohmann::json (e.g. `data.get<BotOutputData>()`).
321//
322
324
325void to_json(nlohmann::json& j, const Message& message);
326void from_json(const nlohmann::json& j, Message& message);
327
328void to_json(nlohmann::json& j, const AboutClientData& data);
329void to_json(nlohmann::json& j, const SendTextOptions& options);
330void to_json(nlohmann::json& j, const LLMFunctionCallResultData& data);
331
332void to_json(nlohmann::json& j, const ClientMessageData& data);
333void from_json(const nlohmann::json& j, ClientMessageData& data);
334
335void from_json(const nlohmann::json& j, BotReadyData& data);
336void from_json(const nlohmann::json& j, ErrorData& data);
337void from_json(const nlohmann::json& j, TranscriptData& data);
338void from_json(const nlohmann::json& j, TextData& data);
339void from_json(const nlohmann::json& j, SpokenProgressData& data);
340void from_json(const nlohmann::json& j, BotOutputData& data);
341void from_json(const nlohmann::json& j, MetricData& data);
342void from_json(const nlohmann::json& j, MetricsData& data);
343void from_json(const nlohmann::json& j, LLMFunctionCallStartedData& data);
344void from_json(const nlohmann::json& j, LLMFunctionCallInProgressData& data);
345void from_json(const nlohmann::json& j, LLMFunctionCallStoppedData& data);
346void from_json(const nlohmann::json& j, LLMSearchResult& data);
347void from_json(const nlohmann::json& j, LLMSearchOrigin& data);
348void from_json(const nlohmann::json& j, BotLLMSearchResponseData& data);
349
351
352} // namespace pipecat::rtvi
353
354#endif
Definition messages.h:29
constexpr const char * PROTOCOL_VERSION
The RTVI protocol version this library speaks.
Definition messages.h:32
std::optional< MessageType > parse_message_type(const std::string &type)
The message type with an RTVI name, or std::nullopt if it's unknown.
constexpr const char * MESSAGE_LABEL
The label of every RTVI message.
Definition messages.h:35
const char * to_string(MessageType type)
The RTVI name of a message type, e.g. "bot-ready".
AboutClientData default_about_client()
Information about this library and the platform it runs on.
MessageType
Types of RTVI messages.
Definition messages.h:38
@ LLMFunctionCallInProgress
A function call is running.
@ ServerMessage
An app-defined message from the bot.
@ BotInterrupted
The bot was interrupted.
@ BotTTSStarted
The bot's text-to-speech started.
@ UserTranscription
What the user said.
@ BotLLMText
Text from the bot's LLM, as it streams.
@ UserLLMText
User text sent to the bot's LLM.
@ ClientMessage
An app-defined message to the bot.
@ UserStartedSpeaking
The user started speaking.
@ BotOutput
What the bot says or outputs.
@ LLMFunctionCallStarted
The bot's LLM started a function call.
@ DisconnectBot
Asks the bot to leave.
@ Error
An error in the bot.
@ BotStoppedSpeaking
The bot stopped speaking.
@ UserMuteStopped
The bot stopped ignoring user audio.
@ ErrorResponse
The bot couldn't handle a message.
@ BotTTSText
Text the bot is speaking.
@ LLMFunctionCallResult
The result of a function call.
@ UserMuteStarted
The bot started ignoring user audio.
@ UserStoppedSpeaking
The user stopped speaking.
@ LLMFunctionCallStopped
A function call finished.
@ ServerResponse
The bot's answer to a request.
@ BotStartedSpeaking
The bot started speaking.
@ SendText
Text for the bot's LLM.
@ BotTTSStopped
The bot's text-to-speech stopped.
@ ClientReady
The client is ready.
@ BotLLMStopped
The bot's LLM finished responding.
@ BotLLMStarted
The bot's LLM started responding.
@ BotLLMSearchResponse
Search results used by the bot's LLM.
@ Metrics
Performance metrics.
@ BotReady
The bot is ready.
Information about the client, sent to the bot when connecting.
Definition messages.h:83
std::optional< std::string > platform
Operating system, e.g. "Linux".
Definition messages.h:89
std::string library
Name of the library, e.g. "pipecat-client-cxx".
Definition messages.h:85
nlohmann::json platform_details
Any other details, as a JSON object. Null to leave them out.
Definition messages.h:93
std::optional< std::string > platform_version
Version of the OS.
Definition messages.h:91
std::optional< std::string > library_version
Version of the library.
Definition messages.h:87
Search results used by the bot's LLM.
Definition messages.h:267
std::vector< LLMSearchOrigin > origins
Where the results come from.
Definition messages.h:273
std::optional< std::string > search_result
Summary of the results.
Definition messages.h:269
std::optional< std::string > rendered_content
Results ready to show.
Definition messages.h:271
Definition messages.h:182
std::string text
The text.
Definition messages.h:184
std::optional< bool > will_be_spoken
Whether the bot will speak it.
Definition messages.h:190
std::optional< std::string > spoken_status
Where the bot is in speaking it: "new", "in-progress" or "completed".
Definition messages.h:192
std::string aggregated_by
What the text is, e.g. "word" or "sentence".
Definition messages.h:186
std::optional< SpokenProgressData > spoken_progress
How much of the text the bot has spoken. Only for text it speaks.
Definition messages.h:194
std::optional< int64_t > segment_id
ID shared by updates of a text.
Definition messages.h:188
Sent by the bot when it's ready.
Definition messages.h:128
nlohmann::json about
Information about the bot. Can be null.
Definition messages.h:132
std::string version
RTVI version of the bot.
Definition messages.h:130
An app-defined message between the client and the bot.
Definition messages.h:100
nlohmann::json data
Data of the message. Can be null.
Definition messages.h:104
std::string type
Type of the message, defined by your app.
Definition messages.h:102
An error.
Definition messages.h:136
bool fatal
Whether the error is fatal, e.g. the bot stopped.
Definition messages.h:140
std::string error
What went wrong.
Definition messages.h:138
A function call is running.
Definition messages.h:226
nlohmann::json arguments
Definition messages.h:233
std::string tool_call_id
ID of the function call.
Definition messages.h:230
std::optional< std::string > function_name
Name of the function, if the bot shares it.
Definition messages.h:228
The result of a function call, sent to the bot.
Definition messages.h:116
std::string tool_call_id
ID of the function call.
Definition messages.h:120
nlohmann::json result
The result.
Definition messages.h:124
std::string function_name
Name of the function.
Definition messages.h:118
nlohmann::json arguments
Arguments the function was called with.
Definition messages.h:122
The bot's LLM started a function call.
Definition messages.h:220
std::optional< std::string > function_name
Name of the function, if the bot shares it.
Definition messages.h:222
A function call finished or was cancelled.
Definition messages.h:237
std::optional< std::string > function_name
Name of the function, if the bot shares it.
Definition messages.h:239
nlohmann::json result
The result of the function, if the bot shares it. Can be null.
Definition messages.h:245
std::string tool_call_id
ID of the function call.
Definition messages.h:241
bool cancelled
Whether the call was cancelled.
Definition messages.h:243
Where search results come from, e.g. a website.
Definition messages.h:257
std::optional< std::string > site_title
Title of the site.
Definition messages.h:261
std::optional< std::string > site_uri
Address of the site.
Definition messages.h:259
std::vector< LLMSearchResult > results
Results from this site.
Definition messages.h:263
A search result.
Definition messages.h:249
std::string text
Text of the result.
Definition messages.h:251
std::vector< double > confidence
Confidence scores, from 0 to 1.
Definition messages.h:253
Definition messages.h:280
static Message disconnect_bot()
A message that asks the bot to leave.
std::string label
Always "rtvi-ai".
Definition messages.h:284
std::string type
Type of the message, e.g. "bot-ready".
Definition messages.h:286
static Message dtmf(const std::string &buttons)
One or more DTMF keys (0-9, * and #), for bots on RTVI 2.1 or newer.
static Message client_ready(const AboutClientData &about)
A message that says the client is ready, with information about it.
static Message llm_function_call_result(const LLMFunctionCallResultData &data)
The result of a function call.
std::string id
ID of the message. Answers have the request's ID.
Definition messages.h:282
Message(MessageType type, nlohmann::json data=nullptr)
A message of type with data, and a new random ID.
static Message client_message(const std::string &type, const nlohmann::json &data)
An app-defined message to the bot.
Message()=default
An empty message.
nlohmann::json data
Data of the message. Null if it has none.
Definition messages.h:288
static Message send_text(const std::string &content, const SendTextOptions &options={})
Text for the bot's LLM.
A single measurement.
Definition messages.h:198
std::string processor
What was measured, e.g. a service in the bot.
Definition messages.h:200
std::optional< std::string > model
The AI model used, if any.
Definition messages.h:202
double value
The measured value, e.g. a time in seconds.
Definition messages.h:204
Performance metrics from the bot.
Definition messages.h:208
std::vector< MetricData > characters
Characters sent to be spoken.
Definition messages.h:214
nlohmann::json raw
All the metrics, including those without a field above.
Definition messages.h:216
std::vector< MetricData > ttfb
Times to first byte, in seconds.
Definition messages.h:210
std::vector< MetricData > processing
Processing times, in seconds.
Definition messages.h:212
Options for sending text to the bot.
Definition messages.h:108
std::optional< bool > run_immediately
Whether the bot responds right away. Defaults to true.
Definition messages.h:110
std::optional< bool > audio_response
Whether the bot responds with audio. Defaults to true.
Definition messages.h:112
How much of a text the bot has spoken.
Definition messages.h:171
std::string remaining_text
Text not spoken yet.
Definition messages.h:175
std::string accumulated_text
Text spoken so far, including the current word.
Definition messages.h:173
Some text.
Definition messages.h:156
std::string text
The text.
Definition messages.h:158
What the user said.
Definition messages.h:144
std::string text
The words.
Definition messages.h:146
std::string timestamp
When it was said, as an ISO 8601 date.
Definition messages.h:150
std::string user_id
ID of the user who spoke.
Definition messages.h:152