chore: Enable an echo id for message create end points
This commit is contained in:
parent
afc062537c
commit
739c062676
3 changed files with 15 additions and 6 deletions
|
@ -3,12 +3,11 @@ class Messages::MessageBuilder
|
|||
attr_reader :message
|
||||
|
||||
def initialize(user, conversation, params)
|
||||
@content = params[:content]
|
||||
@params = params
|
||||
@private = params[:private] || false
|
||||
@conversation = conversation
|
||||
@user = user
|
||||
@message_type = params[:message_type] || 'outgoing'
|
||||
@content_type = params[:content_type]
|
||||
@items = params.to_unsafe_h&.dig(:content_attributes, :items)
|
||||
@attachments = params[:attachments]
|
||||
@in_reply_to = params.to_unsafe_h&.dig(:content_attributes, :in_reply_to)
|
||||
|
@ -48,12 +47,13 @@ class Messages::MessageBuilder
|
|||
account_id: @conversation.account_id,
|
||||
inbox_id: @conversation.inbox_id,
|
||||
message_type: message_type,
|
||||
content: @content,
|
||||
content: @params[:content],
|
||||
private: @private,
|
||||
sender: sender,
|
||||
content_type: @content_type,
|
||||
content_type: @params[:content_type],
|
||||
items: @items,
|
||||
in_reply_to: @in_reply_to
|
||||
in_reply_to: @in_reply_to,
|
||||
echo_id: @params[:echo_id]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,6 +48,7 @@ class Api::V1::Widget::MessagesController < Api::V1::Widget::BaseController
|
|||
sender: @contact,
|
||||
content: permitted_params[:message][:content],
|
||||
inbox_id: conversation.inbox_id,
|
||||
echo_id: permitted_params[:message][:echo_id],
|
||||
message_type: :incoming
|
||||
}
|
||||
end
|
||||
|
@ -116,7 +117,7 @@ class Api::V1::Widget::MessagesController < Api::V1::Widget::BaseController
|
|||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(:id, :before, :website_token, contact: [:email], message: [:content, :referer_url, :timestamp])
|
||||
params.permit(:id, :before, :website_token, contact: [:email], message: [:content, :referer_url, :timestamp, :echo_id])
|
||||
end
|
||||
|
||||
def set_message
|
||||
|
|
|
@ -36,6 +36,9 @@ class Message < ApplicationRecord
|
|||
validates :conversation_id, presence: true
|
||||
validates_with ContentAttributeValidator
|
||||
|
||||
# when you have a temperory id in your frontend and want it echoed back via action cable
|
||||
attr_accessor :echo_id
|
||||
|
||||
enum message_type: { incoming: 0, outgoing: 1, activity: 2, template: 3 }
|
||||
enum content_type: {
|
||||
text: 0,
|
||||
|
@ -89,7 +92,12 @@ class Message < ApplicationRecord
|
|||
message_type: message_type_before_type_cast,
|
||||
conversation_id: conversation.display_id
|
||||
)
|
||||
data.merge!(echo_id: echo_id) if echo_id.present?
|
||||
data.merge!(attachments: attachments.map(&:push_event_data)) if attachments.present?
|
||||
merge_sender_attributes(data)
|
||||
end
|
||||
|
||||
def merge_sender_attributes(data)
|
||||
data.merge!(sender: sender.push_event_data) if sender && !sender.is_a?(AgentBot)
|
||||
data.merge!(sender: sender.push_event_data(inbox)) if sender&.is_a?(AgentBot)
|
||||
data
|
||||
|
|
Loading…
Reference in a new issue