feat: Read/Delivery status for Whatsapp Cloud API (#5157)
Process field statuses received in webhook WhatsApp cloud API ref: #1021 Co-authored-by: Sojan <sojan@pepalo.com> Co-authored-by: Nithin David <1277421+nithindavid@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
a397f01692
commit
edcbd53425
@@ -7,11 +7,38 @@ class Whatsapp::IncomingMessageBaseService
|
||||
def perform
|
||||
processed_params
|
||||
|
||||
perform_statuses
|
||||
|
||||
set_contact
|
||||
return unless @contact
|
||||
|
||||
set_conversation
|
||||
|
||||
perform_messages
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def perform_statuses
|
||||
return if @processed_params[:statuses].blank?
|
||||
|
||||
status = @processed_params[:statuses].first
|
||||
@message = Message.find_by(source_id: status[:id])
|
||||
return unless @message
|
||||
|
||||
update_message_with_status(@message, status)
|
||||
end
|
||||
|
||||
def update_message_with_status(message, status)
|
||||
message.status = status[:status]
|
||||
if status[:status] == 'failed' && status[:errors].present?
|
||||
error = status[:errors]&.first
|
||||
message.external_error = "#{error[:code]}: #{error[:title]}"
|
||||
end
|
||||
message.save!
|
||||
end
|
||||
|
||||
def perform_messages
|
||||
return if @processed_params[:messages].blank? || unprocessable_message_type?
|
||||
|
||||
@message = @conversation.messages.build(
|
||||
@@ -27,8 +54,6 @@ class Whatsapp::IncomingMessageBaseService
|
||||
@message.save!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def processed_params
|
||||
@processed_params ||= params
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user