Correção do panic quando não encontra a bot transfer message
This commit is contained in:
17
src/main.rs
17
src/main.rs
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user