6#ifndef _USE_MATH_DEFINES
7#define _USE_MATH_DEFINES
25using namespace std::chrono_literals;
31std::string GoogleDialogFlowCxChatBot::_getRandSession_() {
34 for(
int i = 0; i<16; i++) {
35 session += std::to_string(
rand() % 10);
46#ifdef USE_DISPLAY_NAME
47 if(!config.
check(
"display_name"))
55 google::cloud::dialogflow_cx::AgentsClient
agentsClient(google::cloud::dialogflow_cx::MakeAgentsConnection(
m_location));
57 dialogFlow_cx_v3::ListAgentsRequest request;
59 std::string parent =
"projects/"+
m_project;
60 request.set_parent(parent);
65 google::cloud::Options
opt;
70 std::this_thread::sleep_for(30s);
72 m_agentId =
agent->name();
79 m_sessionId = m_agentId +
"/sessions/" + _getRandSession_();
80 m_channel = grpc::CreateChannel(
"dialogflow.googleapis.com", grpc::GoogleDefaultCredentials());
81 m_sessionStub = dialogFlow_cx_v3::Sessions::NewStub(m_channel);
84 std::string message{
"*"};
104 dialogFlow_cx_v3::DetectIntentRequest req;
108 auto parameters =
query_input.mutable_language_code();
119 grpc::ClientContext context;
120 dialogFlow_cx_v3::DetectIntentResponse response;
126 if (response.has_query_result()) {
127 m_currentPage = response.query_result().current_page().display_name();
128 const dialogFlow_cx_v3::QueryResult&
query_result = response.query_result();
135 messageOut =
query_result.response_messages().Get(0).text().text().Get(0);
163 status = m_currentPage;
170 m_sessionId = m_agentId +
"/sessions/" + _getRandSession_();
const yarp::os::LogComponent & GOOGLEDIALOGFLOWCXBOT()
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
std::string m_language_code
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue interact(const std::string &messageIn, std::string &messageOut) override
Sends a message to the chatbot.
yarp::dev::ReturnValue getLanguage(std::string &language) override
Gets the current chatbot language.
yarp::dev::ReturnValue getStatus(std::string &status) override
Gets the current status of the bot.
yarp::dev::ReturnValue resetBot() override
Resets the chatbot.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue setLanguage(const std::string &language) override
Sets the chat bot language.
@ return_value_error_generic
Method was successfully executed.
A mini-server for performing network communication in the background.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
#define yCError(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.