Correção do panic quando não encontra a bot transfer message

This commit is contained in:
2025-12-17 05:26:02 -03:00
parent 3f727b4583
commit 72d02a08d4

View File

@@ -358,8 +358,13 @@ fn main() -> anyhow::Result<()> {
});
// Find first agent message sent after the last bot message
let (pos, transfer_message) =
bot_transfer_message.expect("Failed to get the transfer bot message position");
// let (pos, transfer_message) =
// bot_transfer_message.expect("Failed to get the transfer bot message position");
let (pos, transfer_message) = match bot_transfer_message {
Some((pos, msg)) => (pos, msg),
None => return "".to_string(), // Retorna string vazia em vez de panic
};
let msg = talk_histories
.as_array()
@@ -374,10 +379,11 @@ fn main() -> anyhow::Result<()> {
})
.take(1)
.collect_vec();
// Se não encontrar mensagem do agente, retorna string vazia
if msg.is_empty() {
return "".to_string();
}
//if msg[0] {
// return None;
//}
let agent_first_message = msg[0];
// Calculate time difference between bot message and agent message
@@ -425,6 +431,7 @@ fn main() -> anyhow::Result<()> {
name, id, response_time, bot_transfer_date, user_response_date
)
})
.filter(|s| !s.is_empty()) // Filtra strings vazias
.reduce(|acc, e| format!("{}\n{}", acc, e))
.unwrap_or("".to_string());