Files
leadchat/enterprise/app/services/captain/tools/copilot/get_conversation_service.rb
Tanmay Deep Sharma c42dd8a23e feat: captain should be able to access private notes (#11768)
# Pull Request Template

## Linear task: 

https://linear.app/chatwoot/issue/CW-4482/captain-should-be-able-to-access-private-notes-only-on-copilot

## Description

Captain should be able to access private notes (only on copilot)

## Type of change

- [x] New feature (non-breaking change which adds functionality)

## How Has This Been Tested?


![image](https://github.com/user-attachments/assets/b25cf81f-85eb-4adb-a1eb-57e1156b9b9e)


![image](https://github.com/user-attachments/assets/20051b31-cbce-41d9-84d9-13bc71687323)


## Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules

---------

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2025-06-24 19:00:20 -07:00

42 lines
1.1 KiB
Ruby

class Captain::Tools::Copilot::GetConversationService < Captain::Tools::BaseService
def name
'get_conversation'
end
def description
'Get details of a conversation including messages and contact information'
end
def parameters
{
type: 'object',
properties: {
conversation_id: {
type: 'number',
description: 'The ID of the conversation to retrieve'
}
},
required: %w[conversation_id]
}
end
def execute(arguments)
conversation_id = arguments['conversation_id']
Rails.logger.info "#{self.class.name}: Conversation ID: #{conversation_id}"
return 'Missing required parameters' if conversation_id.blank?
conversation = Conversation.find_by(display_id: conversation_id, account_id: @assistant.account_id)
return 'Conversation not found' if conversation.blank?
conversation.to_llm_text(include_private_messages: true)
end
def active?
user_has_permission('conversation_manage') ||
user_has_permission('conversation_unassigned_manage') ||
user_has_permission('conversation_participating_manage')
end
end