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?   ## 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>
This commit is contained in:
committed by
GitHub
parent
cc8866a84e
commit
c42dd8a23e
@@ -5,7 +5,7 @@ class LlmFormatter::ConversationLlmFormatter < LlmFormatter::DefaultLlmFormatter
|
|||||||
sections << "Channel: #{@record.inbox.channel.name}"
|
sections << "Channel: #{@record.inbox.channel.name}"
|
||||||
sections << 'Message History:'
|
sections << 'Message History:'
|
||||||
sections << if @record.messages.any?
|
sections << if @record.messages.any?
|
||||||
build_messages
|
build_messages(config)
|
||||||
else
|
else
|
||||||
'No messages in this conversation'
|
'No messages in this conversation'
|
||||||
end
|
end
|
||||||
@@ -23,11 +23,16 @@ class LlmFormatter::ConversationLlmFormatter < LlmFormatter::DefaultLlmFormatter
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def build_messages
|
def build_messages(config = {})
|
||||||
return "No messages in this conversation\n" if @record.messages.empty?
|
return "No messages in this conversation\n" if @record.messages.empty?
|
||||||
|
|
||||||
message_text = ''
|
message_text = ''
|
||||||
@record.messages.chat.order(created_at: :asc).each do |message|
|
messages = @record.messages.where.not(message_type: :activity).order(created_at: :asc)
|
||||||
|
|
||||||
|
messages.each do |message|
|
||||||
|
# Skip private messages unless explicitly included in config
|
||||||
|
next if message.private? && !config[:include_private_messages]
|
||||||
|
|
||||||
message_text << format_message(message)
|
message_text << format_message(message)
|
||||||
end
|
end
|
||||||
message_text
|
message_text
|
||||||
@@ -35,6 +40,7 @@ class LlmFormatter::ConversationLlmFormatter < LlmFormatter::DefaultLlmFormatter
|
|||||||
|
|
||||||
def format_message(message)
|
def format_message(message)
|
||||||
sender = message.message_type == 'incoming' ? 'User' : 'Support agent'
|
sender = message.message_type == 'incoming' ? 'User' : 'Support agent'
|
||||||
|
sender = "[Private Note] #{sender}" if message.private?
|
||||||
"#{sender}: #{message.content}\n"
|
"#{sender}: #{message.content}\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class Captain::Tools::Copilot::GetConversationService < Captain::Tools::BaseServ
|
|||||||
conversation = Conversation.find_by(display_id: conversation_id, account_id: @assistant.account_id)
|
conversation = Conversation.find_by(display_id: conversation_id, account_id: @assistant.account_id)
|
||||||
return 'Conversation not found' if conversation.blank?
|
return 'Conversation not found' if conversation.blank?
|
||||||
|
|
||||||
conversation.to_llm_text
|
conversation.to_llm_text(include_private_messages: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def active?
|
def active?
|
||||||
|
|||||||
@@ -128,6 +128,29 @@ RSpec.describe Captain::Tools::Copilot::GetConversationService do
|
|||||||
expect(result).to eq(conversation.to_llm_text)
|
expect(result).to eq(conversation.to_llm_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'includes private messages in the llm text format' do
|
||||||
|
# Create a regular message
|
||||||
|
create(:message,
|
||||||
|
conversation: conversation,
|
||||||
|
message_type: 'outgoing',
|
||||||
|
content: 'Regular message',
|
||||||
|
private: false)
|
||||||
|
|
||||||
|
# Create a private message
|
||||||
|
create(:message,
|
||||||
|
conversation: conversation,
|
||||||
|
message_type: 'outgoing',
|
||||||
|
content: 'Private note content',
|
||||||
|
private: true)
|
||||||
|
|
||||||
|
result = service.execute({ 'conversation_id' => conversation.display_id })
|
||||||
|
|
||||||
|
# Verify that the result includes both regular and private messages
|
||||||
|
expect(result).to include('Regular message')
|
||||||
|
expect(result).to include('Private note content')
|
||||||
|
expect(result).to include('[Private Note]')
|
||||||
|
end
|
||||||
|
|
||||||
context 'when conversation belongs to different account' do
|
context 'when conversation belongs to different account' do
|
||||||
let(:other_account) { create(:account) }
|
let(:other_account) { create(:account) }
|
||||||
let(:other_inbox) { create(:inbox, account: other_account) }
|
let(:other_inbox) { create(:inbox, account: other_account) }
|
||||||
|
|||||||
Reference in New Issue
Block a user