feat: set first and last name for WhatsApp

This commit is contained in:
Muhsin Keloth
2024-02-07 13:33:57 +05:30
parent 1c73aa9ef4
commit 8c4b13b737
2 changed files with 12 additions and 4 deletions
+5 -2
View File
@@ -38,9 +38,12 @@ class Channel::FacebookPage < ApplicationRecord
end
def create_contact_inbox(instagram_id, name)
first_name = split_first_and_last_name(name)[:first_name]
last_name = split_first_and_last_name(name)[:last_name]
name_parts = split_first_and_last_name(name)
first_name = name_parts[:first_name]
last_name = name_parts[:last_name]
@contact_inbox = ::ContactInboxWithContactBuilder.new({
name: first_name,
last_name: last_name,
source_id: instagram_id,
inbox: inbox,
contact_attributes: { name: first_name, last_name: last_name }
@@ -3,7 +3,7 @@
# https://developers.facebook.com/docs/whatsapp/api/media/
class Whatsapp::IncomingMessageBaseService
include ::Whatsapp::IncomingMessageServiceHelpers
include ContactHelper
pattr_initialize [:inbox!, :params!]
def perform
@@ -84,10 +84,15 @@ class Whatsapp::IncomingMessageBaseService
waid = processed_waid(contact_params[:wa_id])
name = contact_params.dig(:profile, :name)
name_parts = split_first_and_last_name(name)
first_name = name_parts[:first_name]
last_name = name_parts[:last_name]
contact_inbox = ::ContactInboxWithContactBuilder.new(
source_id: waid,
inbox: inbox,
contact_attributes: { name: contact_params.dig(:profile, :name), phone_number: "+#{@processed_params[:messages].first[:from]}" }
contact_attributes: { name: first_name, last_name: last_name, phone_number: "+#{@processed_params[:messages].first[:from]}" }
).perform
@contact_inbox = contact_inbox