fix: suggestion and talk keyword improvements
All checks were successful
BotServer CI / build (push) Successful in 13m59s
All checks were successful
BotServer CI / build (push) Successful in 13m59s
This commit is contained in:
parent
0db08fbf39
commit
6c139fdf63
3 changed files with 23 additions and 7 deletions
|
|
@ -311,8 +311,13 @@ fn add_tool_suggestion(
|
|||
params: Option<Vec<String>>,
|
||||
button_text: &str,
|
||||
) -> Result<(), Box<rhai::EvalAltResult>> {
|
||||
info!(
|
||||
"ADD_SUGGESTION_TOOL called: tool={}, button={}",
|
||||
tool_name, button_text
|
||||
);
|
||||
if let Some(cache_client) = cache {
|
||||
let redis_key = format!("suggestions:{}:{}", user_session.user_id, user_session.id);
|
||||
info!("Adding suggestion to Redis key: {}", redis_key);
|
||||
|
||||
// Create action object and serialize it to JSON string
|
||||
let action_obj = json!({
|
||||
|
|
@ -345,9 +350,7 @@ fn add_tool_suggestion(
|
|||
Ok(length) => {
|
||||
info!(
|
||||
"Added tool suggestion '{}' to session {}, total: {}",
|
||||
tool_name,
|
||||
user_session.id,
|
||||
length
|
||||
tool_name, user_session.id, length
|
||||
);
|
||||
}
|
||||
Err(e) => error!("Failed to add tool suggestion to Redis: {}", e),
|
||||
|
|
@ -394,8 +397,13 @@ pub fn get_suggestions(
|
|||
let suggestion = crate::core::shared::models::Suggestion {
|
||||
text: json["text"].as_str().unwrap_or("").to_string(),
|
||||
context: json["context"].as_str().map(|s| s.to_string()),
|
||||
action: json.get("action").and_then(|v| serde_json::to_string(v).ok()),
|
||||
icon: json.get("icon").and_then(|v| v.as_str()).map(|s| s.to_string()),
|
||||
action: json
|
||||
.get("action")
|
||||
.and_then(|v| serde_json::to_string(v).ok()),
|
||||
icon: json
|
||||
.get("icon")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.to_string()),
|
||||
};
|
||||
suggestions.push(suggestion);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::core::shared::message_types::MessageType;
|
||||
use crate::core::shared::models::{BotResponse, UserSession};
|
||||
use crate::core::shared::state::AppState;
|
||||
use log::{error, trace};
|
||||
use log::{error, info, trace};
|
||||
use rhai::{Dynamic, Engine};
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
@ -12,11 +12,13 @@ pub async fn execute_talk(
|
|||
user_session: UserSession,
|
||||
message: String,
|
||||
) -> Result<BotResponse, Box<dyn std::error::Error + Send + Sync>> {
|
||||
info!("TALK called with message: {}", message);
|
||||
let mut suggestions = Vec::new();
|
||||
|
||||
if let Some(redis_client) = &state.cache {
|
||||
if let Ok(mut conn) = redis_client.get_multiplexed_async_connection().await {
|
||||
let redis_key = format!("suggestions:{}:{}", user_session.user_id, user_session.id);
|
||||
info!("TALK: Fetching suggestions from Redis key: {}", redis_key);
|
||||
|
||||
let suggestions_json: Result<Vec<String>, _> = redis::cmd("LRANGE")
|
||||
.arg(redis_key.as_str())
|
||||
|
|
@ -26,12 +28,17 @@ pub async fn execute_talk(
|
|||
.await;
|
||||
|
||||
if let Ok(suggestions_list) = suggestions_json {
|
||||
info!("TALK: Got {} suggestions from Redis", suggestions_list.len());
|
||||
suggestions = suggestions_list
|
||||
.into_iter()
|
||||
.filter_map(|s| serde_json::from_str(&s).ok())
|
||||
.collect();
|
||||
} else {
|
||||
info!("TALK: No suggestions found in Redis");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
info!("TALK: No cache configured");
|
||||
}
|
||||
|
||||
let channel = user_session
|
||||
|
|
|
|||
|
|
@ -170,7 +170,8 @@ pub async fn run_axum_server(
|
|||
.route(ApiUrls::SESSIONS, get(crate::core::session::get_sessions))
|
||||
.route(ApiUrls::SESSION_HISTORY, get(crate::core::session::get_session_history))
|
||||
.route(ApiUrls::SESSION_START, post(crate::core::session::start_session))
|
||||
.route(ApiUrls::WS, get(crate::core::bot::websocket_handler));
|
||||
.route(ApiUrls::WS, get(crate::core::bot::websocket_handler))
|
||||
.route("/ws/:bot_name", get(crate::core::bot::websocket_handler_with_bot));
|
||||
|
||||
#[cfg(feature = "drive")]
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue