diff --git a/enterprise/lib/captain/tools/add_contact_note_tool.rb b/enterprise/lib/captain/tools/add_contact_note_tool.rb index d39b53c8a..f5df3c339 100644 --- a/enterprise/lib/captain/tools/add_contact_note_tool.rb +++ b/enterprise/lib/captain/tools/add_contact_note_tool.rb @@ -1,39 +1,37 @@ class Captain::Tools::AddContactNoteTool < Captain::Tools::BaseAgentTool description 'Add a note to a contact profile' - param :contact_id, type: 'string', desc: 'The ID of the contact (optional if conversation_id is provided)' - param :conversation_id, type: 'string', desc: 'The display ID of the conversation to find the contact (optional if contact_id is provided)' + param :contact_id, type: 'string', desc: 'The ID of the contact' param :note, type: 'string', desc: 'The note content to add to the contact' - def perform(_tool_context, note:, contact_id: nil, conversation_id: nil) - log_tool_usage('add_contact_note', { contact_id: contact_id, conversation_id: conversation_id, note_length: note.length }) + def perform(_tool_context, note:, contact_id:) + log_tool_usage('add_contact_note', { contact_id: contact_id, note_length: note.length }) - return 'Missing required parameters: need either contact_id or conversation_id, and note' if note.blank? - return 'Must provide either contact_id or conversation_id' if contact_id.blank? && conversation_id.blank? + return 'Missing required parameters: contact_id and note are required' if note.blank? || contact_id.blank? - contact = nil + contact = find_contact(contact_id) + return contact if contact.is_a?(String) # Error message - if contact_id.present? - contact = account_scoped(::Contact).find_by(id: contact_id) - return 'Contact not found' if contact.nil? - elsif conversation_id.present? - conversation = account_scoped(::Conversation).find_by(display_id: conversation_id) - return 'Conversation not found' if conversation.nil? + create_contact_note(contact, note) + "Note added successfully to contact #{contact.name} (ID: #{contact.id})" + end - contact = conversation.contact - end + private - # Create contact note + def find_contact(contact_id) + contact = account_scoped(::Contact).find_by(id: contact_id) + contact || 'Contact not found' + end + + def create_contact_note(contact, note) contact.notes.create!( account: @assistant.account, contact: contact, content: note, user: @user ) - - "Note added successfully to contact #{contact.name} (ID: #{contact.id})" end def active? user_has_permission('contact_manage') end -end \ No newline at end of file +end