chatwoot-develop/enterprise/lib/captain/tools/add_contact_note_tool.rb

28 lines
806 B
Ruby
Executable File

class Captain::Tools::AddContactNoteTool < Captain::Tools::BasePublicTool
description 'Add a note to a contact profile'
param :note, type: 'string', desc: 'The note content to add to the contact'
def perform(tool_context, args = {})
note = args[:note] || args['note']
contact = find_contact(resolve_context(tool_context))
return 'Contact not found' unless contact
return 'Note content is required' if note.blank?
log_tool_usage('add_contact_note', { contact_id: contact.id, note_length: note.length })
create_contact_note(contact, note)
"Note added successfully to contact #{contact.name} (ID: #{contact.id})"
end
private
def create_contact_note(contact, note)
contact.notes.create!(content: note)
end
def permissions
%w[contact_manage]
end
end