fix(captain): apply Instagram limit to Messenger DMs

This commit is contained in:
aakashb95
2026-07-22 12:47:23 +05:30
parent 097c7215ab
commit 9bba75f4b6
3 changed files with 8 additions and 4 deletions
@@ -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)
@@ -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
@@ -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)