chore: Message API improvements (#2396)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Sojan Jose
2021-06-08 01:11:06 +05:30
committed by GitHub
parent 1ebab21cfa
commit 0a087c95fd
5 changed files with 39 additions and 6 deletions

View File

@@ -39,7 +39,17 @@ class Messages::MessageBuilder
end
def sender
message_type == 'outgoing' ? @user : @conversation.contact
message_type == 'outgoing' ? (message_sender || @user) : @conversation.contact
end
def external_created_at
@params[:external_created_at].present? ? { external_created_at: @params[:external_created_at] } : {}
end
def message_sender
return if @params[:sender_type] != 'AgentBot'
AgentBot.where(account_id: [nil, @conversation.account.id]).find_by(id: @params[:sender_id])
end
def message_params
@@ -54,6 +64,6 @@ class Messages::MessageBuilder
items: @items,
in_reply_to: @in_reply_to,
echo_id: @params[:echo_id]
}
}.merge(external_created_at)
end
end

View File

@@ -152,7 +152,10 @@ export default {
return !messageType ? 'left' : 'right';
},
readableTime() {
return this.messageStamp(this.data.created_at, 'LLL d, h:mm a');
return this.messageStamp(
this.contentAttributes.external_created_at || this.data.created_at,
'LLL d, h:mm a'
);
},
isBubble() {
return [0, 1, 3].includes(this.data.message_type);
@@ -205,7 +208,7 @@ export default {
},
isSentByBot() {
if (this.isPending) return false;
return !this.sender.type || this.sender.type === 'bot';
return !this.sender.type || this.sender.type === 'agent_bot';
},
},
};

View File

@@ -55,7 +55,10 @@ class Message < ApplicationRecord
# [:submitted_email, :items, :submitted_values] : Used for bot message types
# [:email] : Used by conversation_continuity incoming email messages
# [:in_reply_to] : Used to reply to a particular tweet in threads
store :content_attributes, accessors: [:submitted_email, :items, :submitted_values, :email, :in_reply_to, :deleted], coder: JSON
# [:deleted] : Used to denote whether the message was deleted by the agent
# [:external_created_at] : Can specify if the message was created at a different timestamp externally
store :content_attributes, accessors: [:submitted_email, :items, :submitted_values, :email, :in_reply_to, :deleted,
:external_created_at], coder: JSON
store :external_source_ids, accessors: [:slack], coder: JSON, prefix: :external_source_id

View File

@@ -1,5 +1,5 @@
json.id resource.id
json.name resource.name
json.description resource.description
json.outgoing_url resource.name
json.outgoing_url resource.outgoing_url
json.account_id resource.account_id