Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

1.0 KB
Raw Blame
class Captain::Tools::AddPrivateNoteTool < Captain::Tools::BasePublicTool
  description 'Add a private note to a conversation'
  parameter :note, type: 'string', description: 'The private note content'

  def perform(tool_context, note:)
    conversation = find_conversation(tool_context.state)
    return failure_result('Conversation not found', tool_context.state) unless conversation

    return failure_result('Note content is required', tool_context.state) if note.blank?

    log_tool_usage('add_private_note', { conversation_id: conversation.id, note_length: note.length })
    create_private_note(conversation, note)

    'Private note added successfully'
  end

  private

  def create_private_note(conversation, note)
    conversation.messages.create!(
      account: @assistant.account,
      inbox: conversation.inbox,
      sender: @assistant,
      message_type: :outgoing,
      content: note,
      private: true
    )
  end

  def permissions
    %w[conversation_manage conversation_unassigned_manage conversation_participating_manage]
  end
end