ajuste no capitao para fazer pix conversacional
This commit is contained in:
parent
9a6eedc7e8
commit
04ae95e778
@ -24,6 +24,14 @@ module Captain
|
||||
return msg
|
||||
end
|
||||
|
||||
ensure_conversation_context!
|
||||
|
||||
unless @conversation && @conversation.inbox
|
||||
msg = "Erro Crítico: Contexto de conversa não disponível (Conversation/Inbox nil). Params: #{actual_params}"
|
||||
File.open(Rails.root.join('log/tool_debug.log'), 'a') { |f| f.puts "[#{Time.now}] FAILURE: #{msg}" }
|
||||
return msg
|
||||
end
|
||||
|
||||
unit = infer_unit
|
||||
unless unit
|
||||
msg = 'Erro: Unidade não encontrada para esta conversa.'
|
||||
@ -55,8 +63,13 @@ module Captain
|
||||
|
||||
private
|
||||
|
||||
# Helper to ensure we have a conversation object
|
||||
def ensure_conversation_context!
|
||||
return if @conversation.present?
|
||||
end
|
||||
|
||||
def infer_unit
|
||||
@conversation.inbox.captain_inbox&.unit
|
||||
@conversation&.inbox&.captain_inbox&.unit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -32,9 +32,17 @@ module Captain
|
||||
return msg
|
||||
end
|
||||
|
||||
ensure_conversation_context!
|
||||
|
||||
unless @conversation && @conversation.inbox
|
||||
msg = "Erro Crítico: Contexto de conversa não disponível (Conversation/Inbox nil). Params: #{actual_params}"
|
||||
File.open(Rails.root.join('log/tool_debug.log'), 'a') { |f| f.puts "[#{Time.now}] FAILURE: #{msg}" }
|
||||
return msg
|
||||
end
|
||||
|
||||
unit = infer_unit
|
||||
unless unit
|
||||
msg = 'Erro: Unidade não encontrada para esta conversa.'
|
||||
msg = 'Erro: Unidade não encontrada para esta conversa. Verifique se o Inbox está conectado a uma Unidade.'
|
||||
File.open(Rails.root.join('log/tool_debug.log'), 'a') { |f| f.puts "[#{Time.now}] RETURN: #{msg}" }
|
||||
return msg
|
||||
end
|
||||
@ -71,8 +79,17 @@ module Captain
|
||||
|
||||
private
|
||||
|
||||
# Helper to ensure we have a conversation object, even if passed differently
|
||||
def ensure_conversation_context!
|
||||
# Se @conversation for nulo mas tivermos um ID nos params ou args, podemos tentar buscar
|
||||
return if @conversation.present?
|
||||
|
||||
# Tentativa de fallback (ex: se o runner passar conversation_id via params)
|
||||
# Implementação futura se necessário. Por enquanto, focamos em validar o que temos.
|
||||
end
|
||||
|
||||
def infer_unit
|
||||
@conversation.inbox.captain_inbox&.unit
|
||||
@conversation&.inbox&.captain_inbox&.unit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -16,6 +16,13 @@ module Captain
|
||||
|
||||
return 'Erro: Nenhum dado fornecido.' if name.blank? && cpf.blank?
|
||||
|
||||
ensure_conversation_context!
|
||||
|
||||
unless @conversation && @conversation.contact
|
||||
msg = "Erro Crítico: Contexto de conversa ou contato não disponível. Params: #{actual_params}"
|
||||
return msg
|
||||
end
|
||||
|
||||
if @conversation.contact
|
||||
@conversation.contact.name = name if name.present?
|
||||
@conversation.contact.custom_attributes['cpf'] = cpf if cpf.present?
|
||||
@ -29,6 +36,13 @@ module Captain
|
||||
'Erro: Contato não encontrado para esta conversa.'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Helper to ensure we have a conversation object
|
||||
def ensure_conversation_context!
|
||||
return if @conversation.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user