feat: Standardise the external channel user id and user name (#8802)
* feat: Standardize the external channel id and user name * chore: add specs * chore: add name space `social`
This commit is contained in:
@@ -24,7 +24,9 @@ class Instagram::WebhooksBaseService
|
|||||||
def update_instagram_profile_link(user)
|
def update_instagram_profile_link(user)
|
||||||
return unless user['username']
|
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_profiles': { 'instagram': user['username'] } })
|
||||||
|
@contact.additional_attributes = @contact.additional_attributes.merge({ 'social_instagram_user_name': user['username'] })
|
||||||
@contact.save
|
@contact.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -139,7 +139,14 @@ class Line::IncomingMessageService
|
|||||||
def contact_attributes
|
def contact_attributes
|
||||||
{
|
{
|
||||||
name: line_contact_info['displayName'],
|
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
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -78,8 +78,11 @@ class Telegram::IncomingMessageService
|
|||||||
|
|
||||||
def additional_attributes
|
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,
|
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
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ describe Webhooks::InstagramEventsJob do
|
|||||||
instagram_inbox.reload
|
instagram_inbox.reload
|
||||||
|
|
||||||
expect(instagram_inbox.contacts.count).to be 1
|
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.conversations.count).to be 1
|
||||||
expect(instagram_inbox.messages.count).to be 1
|
expect(instagram_inbox.messages.count).to be 1
|
||||||
expect(instagram_inbox.messages.last.content_attributes['is_unsupported']).to be_nil
|
expect(instagram_inbox.messages.last.content_attributes['is_unsupported']).to be_nil
|
||||||
@@ -59,7 +59,7 @@ describe Webhooks::InstagramEventsJob do
|
|||||||
instagram_inbox.reload
|
instagram_inbox.reload
|
||||||
|
|
||||||
expect(instagram_inbox.contacts.count).to be 1
|
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.conversations.count).to be 1
|
||||||
expect(instagram_inbox.messages.count).to be 1
|
expect(instagram_inbox.messages.count).to be 1
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ describe Webhooks::InstagramEventsJob do
|
|||||||
instagram_inbox.reload
|
instagram_inbox.reload
|
||||||
|
|
||||||
expect(instagram_inbox.contacts.count).to be 1
|
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.conversations.count).to be 1
|
||||||
expect(instagram_inbox.messages.count).to be 1
|
expect(instagram_inbox.messages.count).to be 1
|
||||||
expect(instagram_inbox.messages.last.content_attributes['is_unsupported']).to be true
|
expect(instagram_inbox.messages.last.content_attributes['is_unsupported']).to be true
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ describe Line::IncomingMessageService do
|
|||||||
described_class.new(inbox: line_channel.inbox, params: params).perform
|
described_class.new(inbox: line_channel.inbox, params: params).perform
|
||||||
expect(line_channel.inbox.conversations).not_to eq(0)
|
expect(line_channel.inbox.conversations).not_to eq(0)
|
||||||
expect(Contact.all.first.name).to eq('LINE Test')
|
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')
|
expect(line_channel.inbox.messages.first.content).to eq('Hello, world')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -204,6 +205,7 @@ describe Line::IncomingMessageService do
|
|||||||
described_class.new(inbox: line_channel.inbox, params: image_params).perform
|
described_class.new(inbox: line_channel.inbox, params: image_params).perform
|
||||||
expect(line_channel.inbox.conversations).not_to eq(0)
|
expect(line_channel.inbox.conversations).not_to eq(0)
|
||||||
expect(Contact.all.first.name).to eq('LINE Test')
|
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.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_type).to eq('image')
|
||||||
expect(line_channel.inbox.messages.first.attachments.first.file.blob.filename.to_s).to eq('media-354718.png')
|
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
|
described_class.new(inbox: line_channel.inbox, params: video_params).perform
|
||||||
expect(line_channel.inbox.conversations).not_to eq(0)
|
expect(line_channel.inbox.conversations).not_to eq(0)
|
||||||
expect(Contact.all.first.name).to eq('LINE Test')
|
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.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_type).to eq('video')
|
||||||
expect(line_channel.inbox.messages.first.attachments.first.file.blob.filename.to_s).to eq('media-354718.mp4')
|
expect(line_channel.inbox.messages.first.attachments.first.file.blob.filename.to_s).to eq('media-354718.mp4')
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ describe Telegram::IncomingMessageService do
|
|||||||
described_class.new(inbox: telegram_channel.inbox, params: params).perform
|
described_class.new(inbox: telegram_channel.inbox, params: params).perform
|
||||||
expect(telegram_channel.inbox.conversations.count).not_to eq(0)
|
expect(telegram_channel.inbox.conversations.count).not_to eq(0)
|
||||||
expect(Contact.all.first.name).to eq('Sojan Jose')
|
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')
|
expect(telegram_channel.inbox.messages.first.content).to eq('test')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -105,6 +107,8 @@ describe Telegram::IncomingMessageService do
|
|||||||
described_class.new(inbox: telegram_channel.inbox, params: params).perform
|
described_class.new(inbox: telegram_channel.inbox, params: params).perform
|
||||||
expect(telegram_channel.inbox.conversations.count).not_to eq(0)
|
expect(telegram_channel.inbox.conversations.count).not_to eq(0)
|
||||||
expect(Contact.all.first.name).to eq('Sojan Jose')
|
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')
|
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('audio')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -277,6 +281,7 @@ describe Telegram::IncomingMessageService do
|
|||||||
described_class.new(inbox: telegram_channel.inbox, params: params).perform
|
described_class.new(inbox: telegram_channel.inbox, params: params).perform
|
||||||
expect(telegram_channel.inbox.conversations.count).not_to eq(0)
|
expect(telegram_channel.inbox.conversations.count).not_to eq(0)
|
||||||
expect(Contact.all.first.name).to eq('Sojan Jose')
|
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')
|
expect(telegram_channel.inbox.messages.first.content).to eq('Option 1')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user