diff --git a/app/services/instagram/webhooks_base_service.rb b/app/services/instagram/webhooks_base_service.rb index 26e2e486f..419270d70 100644 --- a/app/services/instagram/webhooks_base_service.rb +++ b/app/services/instagram/webhooks_base_service.rb @@ -24,7 +24,9 @@ class Instagram::WebhooksBaseService def update_instagram_profile_link(user) return unless user['username'] + # TODO: Remove this once we show the social_instagram_user_name in the UI instead of the username @contact.additional_attributes = @contact.additional_attributes.merge({ 'social_profiles': { 'instagram': user['username'] } }) + @contact.additional_attributes = @contact.additional_attributes.merge({ 'social_instagram_user_name': user['username'] }) @contact.save end end diff --git a/app/services/line/incoming_message_service.rb b/app/services/line/incoming_message_service.rb index 121ba1ce2..2d6988476 100644 --- a/app/services/line/incoming_message_service.rb +++ b/app/services/line/incoming_message_service.rb @@ -139,7 +139,14 @@ class Line::IncomingMessageService def contact_attributes { name: line_contact_info['displayName'], - avatar_url: line_contact_info['pictureUrl'] + avatar_url: line_contact_info['pictureUrl'], + additional_attributes: additional_attributes + } + end + + def additional_attributes + { + social_line_user_id: line_contact_info['userId'] } end diff --git a/app/services/telegram/incoming_message_service.rb b/app/services/telegram/incoming_message_service.rb index d4eeb53d5..d18994a00 100644 --- a/app/services/telegram/incoming_message_service.rb +++ b/app/services/telegram/incoming_message_service.rb @@ -78,8 +78,11 @@ class Telegram::IncomingMessageService def additional_attributes { + # TODO: Remove this once we show the social_telegram_user_name in the UI instead of the username username: telegram_params_username, - language_code: telegram_params_language_code + language_code: telegram_params_language_code, + social_telegram_user_id: telegram_params_from_id, + social_telegram_user_name: telegram_params_username } end diff --git a/spec/jobs/webhooks/instagram_events_job_spec.rb b/spec/jobs/webhooks/instagram_events_job_spec.rb index e77d654cc..84bff722b 100644 --- a/spec/jobs/webhooks/instagram_events_job_spec.rb +++ b/spec/jobs/webhooks/instagram_events_job_spec.rb @@ -43,7 +43,7 @@ describe Webhooks::InstagramEventsJob do instagram_inbox.reload expect(instagram_inbox.contacts.count).to be 1 - expect(instagram_inbox.contacts.last.additional_attributes['social_profiles']['instagram']).to eq 'some_user_name' + expect(instagram_inbox.contacts.last.additional_attributes['social_instagram_user_name']).to eq 'some_user_name' expect(instagram_inbox.conversations.count).to be 1 expect(instagram_inbox.messages.count).to be 1 expect(instagram_inbox.messages.last.content_attributes['is_unsupported']).to be_nil @@ -59,7 +59,7 @@ describe Webhooks::InstagramEventsJob do instagram_inbox.reload expect(instagram_inbox.contacts.count).to be 1 - expect(instagram_inbox.contacts.last.additional_attributes['social_profiles']['instagram']).to eq 'some_user_name' + expect(instagram_inbox.contacts.last.additional_attributes['social_instagram_user_name']).to eq 'some_user_name' expect(instagram_inbox.conversations.count).to be 1 expect(instagram_inbox.messages.count).to be 1 @@ -170,7 +170,7 @@ describe Webhooks::InstagramEventsJob do instagram_inbox.reload expect(instagram_inbox.contacts.count).to be 1 - expect(instagram_inbox.contacts.last.additional_attributes['social_profiles']['instagram']).to eq 'some_user_name' + expect(instagram_inbox.contacts.last.additional_attributes['social_instagram_user_name']).to eq 'some_user_name' expect(instagram_inbox.conversations.count).to be 1 expect(instagram_inbox.messages.count).to be 1 expect(instagram_inbox.messages.last.content_attributes['is_unsupported']).to be true diff --git a/spec/services/line/incoming_message_service_spec.rb b/spec/services/line/incoming_message_service_spec.rb index 0547cfbd0..037aa18fa 100644 --- a/spec/services/line/incoming_message_service_spec.rb +++ b/spec/services/line/incoming_message_service_spec.rb @@ -157,6 +157,7 @@ describe Line::IncomingMessageService do described_class.new(inbox: line_channel.inbox, params: params).perform expect(line_channel.inbox.conversations).not_to eq(0) expect(Contact.all.first.name).to eq('LINE Test') + expect(Contact.all.first.additional_attributes['social_line_user_id']).to eq('U4af4980629') expect(line_channel.inbox.messages.first.content).to eq('Hello, world') end end @@ -204,6 +205,7 @@ describe Line::IncomingMessageService do described_class.new(inbox: line_channel.inbox, params: image_params).perform expect(line_channel.inbox.conversations).not_to eq(0) expect(Contact.all.first.name).to eq('LINE Test') + expect(Contact.all.first.additional_attributes['social_line_user_id']).to eq('U4af4980629') expect(line_channel.inbox.messages.first.content).to be_nil expect(line_channel.inbox.messages.first.attachments.first.file_type).to eq('image') expect(line_channel.inbox.messages.first.attachments.first.file.blob.filename.to_s).to eq('media-354718.png') @@ -233,6 +235,7 @@ describe Line::IncomingMessageService do described_class.new(inbox: line_channel.inbox, params: video_params).perform expect(line_channel.inbox.conversations).not_to eq(0) expect(Contact.all.first.name).to eq('LINE Test') + expect(Contact.all.first.additional_attributes['social_line_user_id']).to eq('U4af4980629') expect(line_channel.inbox.messages.first.content).to be_nil expect(line_channel.inbox.messages.first.attachments.first.file_type).to eq('video') expect(line_channel.inbox.messages.first.attachments.first.file.blob.filename.to_s).to eq('media-354718.mp4') diff --git a/spec/services/telegram/incoming_message_service_spec.rb b/spec/services/telegram/incoming_message_service_spec.rb index c169f33fc..795202894 100644 --- a/spec/services/telegram/incoming_message_service_spec.rb +++ b/spec/services/telegram/incoming_message_service_spec.rb @@ -65,6 +65,8 @@ describe Telegram::IncomingMessageService do described_class.new(inbox: telegram_channel.inbox, params: params).perform expect(telegram_channel.inbox.conversations.count).not_to eq(0) expect(Contact.all.first.name).to eq('Sojan Jose') + expect(Contact.all.first.additional_attributes['social_telegram_user_id']).to eq(23) + expect(Contact.all.first.additional_attributes['social_telegram_user_name']).to eq('sojan') expect(telegram_channel.inbox.messages.first.content).to eq('test') end end @@ -105,6 +107,8 @@ describe Telegram::IncomingMessageService do described_class.new(inbox: telegram_channel.inbox, params: params).perform expect(telegram_channel.inbox.conversations.count).not_to eq(0) expect(Contact.all.first.name).to eq('Sojan Jose') + expect(Contact.all.first.additional_attributes['social_telegram_user_id']).to eq(23) + expect(Contact.all.first.additional_attributes['social_telegram_user_name']).to eq('sojan') expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('audio') end end @@ -277,6 +281,7 @@ describe Telegram::IncomingMessageService do described_class.new(inbox: telegram_channel.inbox, params: params).perform expect(telegram_channel.inbox.conversations.count).not_to eq(0) expect(Contact.all.first.name).to eq('Sojan Jose') + expect(Contact.all.first.additional_attributes['social_telegram_user_id']).to eq(5_171_248) expect(telegram_channel.inbox.messages.first.content).to eq('Option 1') end end