diff --git a/enterprise/app/services/captain/assistant/agent_runner_service.rb b/enterprise/app/services/captain/assistant/agent_runner_service.rb index 271e201d6..e60260c3d 100644 --- a/enterprise/app/services/captain/assistant/agent_runner_service.rb +++ b/enterprise/app/services/captain/assistant/agent_runner_service.rb @@ -122,7 +122,7 @@ class Captain::Assistant::AgentRunnerService end def message_length_limit - @message_length_limit ||= Captain::MessageLengthLimit.for(@conversation&.inbox) + @message_length_limit ||= Captain::MessageLengthLimit.for(@conversation) end def error_response(error_message) diff --git a/enterprise/app/services/captain/assistant/runner_state_helper.rb b/enterprise/app/services/captain/assistant/runner_state_helper.rb index 3b43e5ecc..2ab1b902a 100644 --- a/enterprise/app/services/captain/assistant/runner_state_helper.rb +++ b/enterprise/app/services/captain/assistant/runner_state_helper.rb @@ -31,7 +31,7 @@ module Captain::Assistant::RunnerStateHelper def build_conversation_state(state) state[:conversation] = slice_attrs(@conversation, CONVERSATION_STATE_ATTRIBUTES) state[:channel_type] = @conversation.inbox&.channel_type - state[:message_length_limit] = Captain::MessageLengthLimit.for(@conversation.inbox) + state[:message_length_limit] = Captain::MessageLengthLimit.for(@conversation) state[:contact] = slice_attrs(@conversation.contact, CONTACT_STATE_ATTRIBUTES) if @conversation.contact state[:campaign] = slice_attrs(@conversation.campaign, CAMPAIGN_STATE_ATTRIBUTES) if @conversation.campaign state[:contact_inbox] = slice_attrs(@conversation.contact_inbox, CONTACT_INBOX_STATE_ATTRIBUTES) if @conversation.contact_inbox diff --git a/enterprise/lib/captain/message_length_limit.rb b/enterprise/lib/captain/message_length_limit.rb index 0d5918269..11703dfc8 100644 --- a/enterprise/lib/captain/message_length_limit.rb +++ b/enterprise/lib/captain/message_length_limit.rb @@ -1,5 +1,6 @@ class Captain::MessageLengthLimit DEFAULT = 10_000 + INSTAGRAM_DIRECT_MESSAGE = 'instagram_direct_message'.freeze CHANNEL_LIMITS = { 'Channel::FacebookPage' => 2_000, 'Channel::Instagram' => 1_000, @@ -14,8 +15,11 @@ class Captain::MessageLengthLimit 'whatsapp' => 1_600 }.freeze - def self.for(inbox) - return unless inbox + def self.for(conversation) + return unless conversation + + inbox = conversation.inbox + return CHANNEL_LIMITS.fetch('Channel::Instagram') if conversation.additional_attributes['type'] == INSTAGRAM_DIRECT_MESSAGE return TWILIO_LIMITS.fetch(inbox.channel.medium) if inbox.twilio? CHANNEL_LIMITS.fetch(inbox.channel_type, DEFAULT)