refactor: filter keyord logic

This commit is contained in:
Jelson Stoelben Rodrigues
2025-09-25 10:57:19 -03:00
parent 324af05c54
commit 8689534235
2 changed files with 18 additions and 60 deletions

10
FILTER.txt Normal file
View File

@@ -0,0 +1,10 @@
https://novanet.portal.7az.com.br/login
Esse atendimento está sendo encerrado devido a inexistência de diálogo
ATENÇÃO CLIENTE COM NOTIFICAÇÃO DE PARADA ATIVA
setor de redes
trocar a senha
troca de senha
troca senha
alterar senha
altera senha
Transbordo automático para a fila [NovaNet -> Atendimento -> Suporte], pois não havia agentes disponíveis na fila [NovaNet -> Atendimento -> Comercial]

View File

@@ -175,6 +175,8 @@ fn main() -> anyhow::Result<()> {
// Read system prompt // Read system prompt
let prompt = std::fs::read_to_string("PROMPT.txt").unwrap(); let prompt = std::fs::read_to_string("PROMPT.txt").unwrap();
let filter_file_contents = std::fs::read_to_string("FILTER.txt").unwrap_or(String::new());
let filter_keywords = filter_file_contents.split("\n").collect::<Vec<&str>>();
let talks_array = get_piperun_chats_on_date(&PIPERUN_API_URL, &client, &access_token, formatted_day_before_at_midnight, formatted_day_before_at_23_59_59); let talks_array = get_piperun_chats_on_date(&PIPERUN_API_URL, &client, &access_token, formatted_day_before_at_midnight, formatted_day_before_at_23_59_59);
@@ -236,71 +238,17 @@ fn main() -> anyhow::Result<()> {
} }
}; };
// Filter chats that pass by multiple agents // Filter Bot finished chats
let number_of_agents_except_pipebot = talk_histories.as_array().expect("Wrong message type received from talk histories").into_iter() if json["agent"]["user"]["name"].as_str().unwrap_or("unknown_user") == "PipeBot" {return None;}
.map(|message| &message["user"]["name"])
.filter(|name| name.as_str().unwrap() != "PipeBot".to_string())
.unique()
.count();
if number_of_agents_except_pipebot > 1 {return None;}
// Filter stop notification active // Apply keyword based filtering
let found_stop_notification = talk_histories.as_array().expect("Wrong message type received from talk histories").into_iter().enumerate().find(|(pos, message_object)|{ let filter_keywords_found = talk_histories.as_array().expect("Wrong message type received from talk histories").into_iter().any(|message_object|{
let message = message_object["message"].as_str().expect("Failed to decode message as string"); let message = message_object["message"].as_str().expect("Failed to decode message as string");
let found = message.find("ATENÇÃO CLIENTE COM NOTIFICAÇÃO DE PARADA ATIVA"); let found = filter_keywords.iter().any(|keyword|{message.to_uppercase().find(&keyword.to_uppercase()).is_some()});
found.is_some()
});
if found_stop_notification.is_some() {return None;}
// Filter lack of dialogue
let lack_of_dialogue = talk_histories.as_array().expect("Wrong message type received from talk histories").into_iter().find(|message_object|{
let message = message_object["message"].as_str().expect("Failed to decode message as string");
let found = message.to_uppercase().find(&"Esse atendimento está sendo encerrado devido a inexistência de diálogo".to_uppercase());
found.is_some()
});
if lack_of_dialogue.is_some() {return None;}
// Filter is portal access
let portal_link_offer = talk_histories.as_array().expect("Wrong message type received from talk histories").into_iter().find(|message_object|{
let message = message_object["message"].as_str().expect("Failed to decode message as string");
let found = message.to_uppercase().find(&"https://novanet.portal.7az.com.br/login".to_uppercase());
found.is_some()
});
if portal_link_offer.is_some() {return None;}
// Filter no comercial agent available
let comercial_agents_unavailable = talk_histories.as_array().expect("Wrong message type received from talk histories").into_iter().find(|message_object|{
let message = message_object["message"].as_str().expect("Failed to decode message as string");
let found = message.to_uppercase().find(&"Transbordo automático para a fila [NovaNet -> Atendimento -> Suporte], pois não havia agentes disponíveis na fila [NovaNet -> Atendimento -> Comercial]".to_uppercase());
found.is_some()
});
if comercial_agents_unavailable.is_some() {return None;}
// Has network sector in any message
let network_sector_mentioned = talk_histories.as_array().expect("Wrong message type received from talk histories").into_iter().find(|message_object|{
let message = message_object["message"].as_str().expect("Failed to decode message as string");
let found = message.to_uppercase().find(&"setor de redes".to_uppercase());
found.is_some()
});
if network_sector_mentioned.is_some() {return None;}
// Password change ticket
let password_change_keywords = ["trocar a senha", "troca de senha", "troca senha", "alterar senha", "altera senha"];
let password_change_identified = talk_histories.as_array().expect("Wrong message type received from talk histories").into_iter().any(|message_object|{
let message = message_object["message"].as_str().expect("Failed to decode message as string");
let found = password_change_keywords.iter().any(|keyword|{message.to_uppercase().find(&keyword.to_uppercase()).is_some()});
found found
}); });
if password_change_identified {return None;} if filter_keywords_found {return None;}
// Filter Bot finished chats
if json["agent"]["user"]["name"].as_str().unwrap_or("unknown_user") == "PipeBot" {return None;}
return Some(json); return Some(json);
}); });