Compare commits
32
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aef9f05b9d | ||
|
|
8c922fd8df | ||
|
|
ec283f6657 | ||
|
|
4c6954fefc | ||
|
|
9ef93fda87 | ||
|
|
bca3d98268 | ||
|
|
95cd68813f | ||
|
|
ac85ccf2cf | ||
|
|
78a4dce5b9 | ||
|
|
28c1dd0a26 | ||
|
|
377aeb8087 | ||
|
|
117a1405e5 | ||
|
|
1f8ac8a59c | ||
|
|
78855afe8b | ||
|
|
2566155e04 | ||
|
|
ce6ae2cc47 | ||
|
|
9ecb847d9b | ||
|
|
fdffc39663 | ||
|
|
ac5aee3c8d | ||
|
|
94ede8a654 | ||
|
|
07a7c1eb8b | ||
|
|
b125ac1ad6 | ||
|
|
ecfa19bb1a | ||
|
|
733a851607 | ||
|
|
8c4b13b737 | ||
|
|
1c73aa9ef4 | ||
|
|
bafaf9c786 | ||
|
|
75dd77a92d | ||
|
|
ffbc7cb846 | ||
|
|
d88d195e73 | ||
|
|
27c51a0bdf | ||
|
|
822411d804 |
@@ -62,6 +62,7 @@ Metrics/ModuleLength:
|
|||||||
Exclude:
|
Exclude:
|
||||||
- lib/seeders/message_seeder.rb
|
- lib/seeders/message_seeder.rb
|
||||||
- spec/support/slack_stubs.rb
|
- spec/support/slack_stubs.rb
|
||||||
|
- app/mailboxes/mailbox_helper.rb
|
||||||
Rails/ApplicationController:
|
Rails/ApplicationController:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'app/controllers/api/v1/widget/messages_controller.rb'
|
- 'app/controllers/api/v1/widget/messages_controller.rb'
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
# for contact inbox logic it uses the contact inbox builder
|
# for contact inbox logic it uses the contact inbox builder
|
||||||
|
|
||||||
class ContactInboxWithContactBuilder
|
class ContactInboxWithContactBuilder
|
||||||
|
include ContactHelper
|
||||||
pattr_initialize [:inbox!, :contact_attributes!, :source_id, :hmac_verified]
|
pattr_initialize [:inbox!, :contact_attributes!, :source_id, :hmac_verified]
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
@@ -49,8 +50,12 @@ class ContactInboxWithContactBuilder
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_contact
|
def create_contact
|
||||||
|
# TODO: Consider name as first_name and we will change the name to full_name in the future
|
||||||
|
name, middle_name, last_name = extract_name_parts
|
||||||
account.contacts.create!(
|
account.contacts.create!(
|
||||||
name: contact_attributes[:name] || ::Haikunator.haikunate(1000),
|
name: name,
|
||||||
|
middle_name: middle_name,
|
||||||
|
last_name: last_name,
|
||||||
phone_number: contact_attributes[:phone_number],
|
phone_number: contact_attributes[:phone_number],
|
||||||
email: contact_attributes[:email],
|
email: contact_attributes[:email],
|
||||||
identifier: contact_attributes[:identifier],
|
identifier: contact_attributes[:identifier],
|
||||||
@@ -59,6 +64,20 @@ class ContactInboxWithContactBuilder
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def extract_name_parts
|
||||||
|
# Return a generated name if name attribute is blank
|
||||||
|
return [::Haikunator.haikunate(1000), '', ''] if contact_attributes[:name].blank?
|
||||||
|
|
||||||
|
# Return the all name parts if middle_name or last_name is present
|
||||||
|
if contact_attributes[:middle_name].present? || contact_attributes[:last_name].present?
|
||||||
|
return [contact_attributes[:name], contact_attributes[:middle_name], contact_attributes[:last_name]]
|
||||||
|
end
|
||||||
|
|
||||||
|
# If name is present, split it into first and last name
|
||||||
|
name_parts = parse_name(contact_attributes[:name])
|
||||||
|
[name_parts[:first_name], name_parts[:middle_name], name_parts[:last_name]]
|
||||||
|
end
|
||||||
|
|
||||||
def find_contact
|
def find_contact
|
||||||
contact = find_contact_by_identifier(contact_attributes[:identifier])
|
contact = find_contact_by_identifier(contact_attributes[:identifier])
|
||||||
contact ||= find_contact_by_email(contact_attributes[:email])
|
contact ||= find_contact_by_email(contact_attributes[:email])
|
||||||
|
|||||||
@@ -104,7 +104,8 @@ class Messages::Facebook::MessageBuilder < Messages::Messenger::MessageBuilder
|
|||||||
|
|
||||||
def process_contact_params_result(result)
|
def process_contact_params_result(result)
|
||||||
{
|
{
|
||||||
name: "#{result['first_name'] || 'John'} #{result['last_name'] || 'Doe'}",
|
name: result['first_name'] || 'John',
|
||||||
|
last_name: result['last_name'] || 'Doe',
|
||||||
account_id: @inbox.account_id,
|
account_id: @inbox.account_id,
|
||||||
avatar_url: result['profile_pic']
|
avatar_url: result['profile_pic']
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ module ContactHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def valid_number?(full_name)
|
def valid_number?(full_name)
|
||||||
full_name.gsub(/\s+/, '').match?(/\A\+?\d+\z/)
|
TelephoneNumber.parse(full_name).valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
def single_word_name_hash(full_name)
|
def single_word_name_hash(full_name)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
module MailboxHelper
|
module MailboxHelper
|
||||||
|
include ContactHelper
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_message
|
def create_message
|
||||||
@@ -96,11 +98,17 @@ module MailboxHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_contact
|
def create_contact
|
||||||
|
name_parts = parse_name(identify_contact_name)
|
||||||
|
first_name = name_parts[:first_name]
|
||||||
|
middle_name = name_parts[:middle_name]
|
||||||
|
last_name = name_parts[:last_name]
|
||||||
@contact_inbox = ::ContactInboxWithContactBuilder.new(
|
@contact_inbox = ::ContactInboxWithContactBuilder.new(
|
||||||
source_id: processed_mail.original_sender,
|
source_id: processed_mail.original_sender,
|
||||||
inbox: @inbox,
|
inbox: @inbox,
|
||||||
contact_attributes: {
|
contact_attributes: {
|
||||||
name: identify_contact_name,
|
name: first_name,
|
||||||
|
middle_name: middle_name,
|
||||||
|
last_name: last_name,
|
||||||
email: processed_mail.original_sender,
|
email: processed_mail.original_sender,
|
||||||
additional_attributes: {
|
additional_attributes: {
|
||||||
source_id: "email:#{processed_mail.message_id}"
|
source_id: "email:#{processed_mail.message_id}"
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
class Channel::FacebookPage < ApplicationRecord
|
class Channel::FacebookPage < ApplicationRecord
|
||||||
include Channelable
|
include Channelable
|
||||||
include Reauthorizable
|
include Reauthorizable
|
||||||
|
include ContactHelper
|
||||||
|
|
||||||
self.table_name = 'channel_facebook_pages'
|
self.table_name = 'channel_facebook_pages'
|
||||||
|
|
||||||
@@ -37,10 +38,14 @@ class Channel::FacebookPage < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_contact_inbox(instagram_id, name)
|
def create_contact_inbox(instagram_id, name)
|
||||||
|
name_parts = parse_name(name)
|
||||||
|
first_name = name_parts[:first_name]
|
||||||
|
last_name = name_parts[:last_name]
|
||||||
|
middle_name = name_parts[:middle_name]
|
||||||
@contact_inbox = ::ContactInboxWithContactBuilder.new({
|
@contact_inbox = ::ContactInboxWithContactBuilder.new({
|
||||||
source_id: instagram_id,
|
source_id: instagram_id,
|
||||||
inbox: inbox,
|
inbox: inbox,
|
||||||
contact_attributes: { name: name }
|
contact_attributes: { name: first_name, last_name: last_name, middle_name: middle_name }
|
||||||
}).perform
|
}).perform
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,9 @@
|
|||||||
|
|
||||||
# rubocop:enable Layout/LineLength
|
# rubocop:enable Layout/LineLength
|
||||||
|
|
||||||
|
# Notes
|
||||||
|
# TODO: We are considering the "name" as "first_name". We will update it to "first_name" in the future.
|
||||||
|
|
||||||
class Contact < ApplicationRecord
|
class Contact < ApplicationRecord
|
||||||
include Avatarable
|
include Avatarable
|
||||||
include AvailabilityStatusable
|
include AvailabilityStatusable
|
||||||
|
|||||||
@@ -71,7 +71,8 @@ class Telegram::IncomingMessageService
|
|||||||
|
|
||||||
def contact_attributes
|
def contact_attributes
|
||||||
{
|
{
|
||||||
name: "#{telegram_params_first_name} #{telegram_params_last_name}",
|
name: telegram_params_first_name,
|
||||||
|
last_name: telegram_params_last_name,
|
||||||
additional_attributes: additional_attributes
|
additional_attributes: additional_attributes
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
# https://developers.facebook.com/docs/whatsapp/api/media/
|
# https://developers.facebook.com/docs/whatsapp/api/media/
|
||||||
class Whatsapp::IncomingMessageBaseService
|
class Whatsapp::IncomingMessageBaseService
|
||||||
include ::Whatsapp::IncomingMessageServiceHelpers
|
include ::Whatsapp::IncomingMessageServiceHelpers
|
||||||
|
include ContactHelper
|
||||||
pattr_initialize [:inbox!, :params!]
|
pattr_initialize [:inbox!, :params!]
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
@@ -84,10 +84,17 @@ class Whatsapp::IncomingMessageBaseService
|
|||||||
|
|
||||||
waid = processed_waid(contact_params[:wa_id])
|
waid = processed_waid(contact_params[:wa_id])
|
||||||
|
|
||||||
|
name = contact_params.dig(:profile, :name)
|
||||||
|
name_parts = parse_name(name)
|
||||||
|
first_name = name_parts[:first_name]
|
||||||
|
middle_name = name_parts[:middle_name]
|
||||||
|
last_name = name_parts[:last_name]
|
||||||
|
|
||||||
contact_inbox = ::ContactInboxWithContactBuilder.new(
|
contact_inbox = ::ContactInboxWithContactBuilder.new(
|
||||||
source_id: waid,
|
source_id: waid,
|
||||||
inbox: inbox,
|
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, middle_name: middle_name,
|
||||||
|
phone_number: "+#{@processed_params[:messages].first[:from]}" }
|
||||||
).perform
|
).perform
|
||||||
|
|
||||||
@contact_inbox = contact_inbox
|
@contact_inbox = contact_inbox
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ describe ContactInboxWithContactBuilder do
|
|||||||
inbox: inbox,
|
inbox: inbox,
|
||||||
contact_attributes: {
|
contact_attributes: {
|
||||||
name: 'Contact',
|
name: 'Contact',
|
||||||
|
last_name: '1',
|
||||||
phone_number: '+1234567890',
|
phone_number: '+1234567890',
|
||||||
email: 'testemail@example.com'
|
email: 'testemail@example.com'
|
||||||
}
|
}
|
||||||
@@ -27,6 +28,7 @@ describe ContactInboxWithContactBuilder do
|
|||||||
inbox: inbox,
|
inbox: inbox,
|
||||||
contact_attributes: {
|
contact_attributes: {
|
||||||
name: 'Contact',
|
name: 'Contact',
|
||||||
|
last_name: '1',
|
||||||
phone_number: '+1234567890',
|
phone_number: '+1234567890',
|
||||||
email: 'testemail@example.com',
|
email: 'testemail@example.com',
|
||||||
custom_attributes: { test: 'test' }
|
custom_attributes: { test: 'test' }
|
||||||
@@ -35,6 +37,7 @@ describe ContactInboxWithContactBuilder do
|
|||||||
|
|
||||||
expect(contact_inbox.contact.id).not_to eq(contact.id)
|
expect(contact_inbox.contact.id).not_to eq(contact.id)
|
||||||
expect(contact_inbox.contact.name).to eq('Contact')
|
expect(contact_inbox.contact.name).to eq('Contact')
|
||||||
|
expect(contact_inbox.contact.last_name).to eq('1')
|
||||||
expect(contact_inbox.contact.custom_attributes).to eq({ 'test' => 'test' })
|
expect(contact_inbox.contact.custom_attributes).to eq({ 'test' => 'test' })
|
||||||
expect(contact_inbox.inbox_id).to eq(inbox.id)
|
expect(contact_inbox.inbox_id).to eq(inbox.id)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ describe Messages::Facebook::MessageBuilder do
|
|||||||
contact = facebook_channel.inbox.contacts.first
|
contact = facebook_channel.inbox.contacts.first
|
||||||
message = facebook_channel.inbox.messages.first
|
message = facebook_channel.inbox.messages.first
|
||||||
|
|
||||||
expect(contact.name).to eq('Jane Dae')
|
expect(contact.name).to eq('Jane')
|
||||||
|
expect(contact.last_name).to eq('Dae')
|
||||||
expect(message.content).to eq('facebook message')
|
expect(message.content).to eq('facebook message')
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -53,10 +54,11 @@ describe Messages::Facebook::MessageBuilder do
|
|||||||
|
|
||||||
contact = facebook_channel.inbox.contacts.first
|
contact = facebook_channel.inbox.contacts.first
|
||||||
# Refer: https://github.com/chatwoot/chatwoot/pull/3016 for this check
|
# Refer: https://github.com/chatwoot/chatwoot/pull/3016 for this check
|
||||||
default_name = 'John Doe'
|
default_name = 'John'
|
||||||
|
|
||||||
expect(facebook_channel.inbox.reload.contacts.count).to eq(1)
|
expect(facebook_channel.inbox.reload.contacts.count).to eq(1)
|
||||||
expect(contact.name).to eq(default_name)
|
expect(contact.name).to eq(default_name)
|
||||||
|
expect(contact.last_name).to eq('Doe')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ RSpec.describe ContactHelper do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'handle name with mobile number with spaces correctly' do
|
it 'handle name with mobile number with spaces correctly' do
|
||||||
full_name = '+1 234 567 890'
|
full_name = '+1 423-423-4234'
|
||||||
expected_result = { first_name: '+1 234 567 890', last_name: nil, middle_name: nil, prefix: nil, suffix: nil }
|
expected_result = { first_name: '+1 423-423-4234', last_name: nil, middle_name: nil, prefix: nil, suffix: nil }
|
||||||
expect(helper.parse_name(full_name)).to eq(expected_result)
|
expect(helper.parse_name(full_name)).to eq(expected_result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -89,9 +89,9 @@ RSpec.describe SupportMailbox do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'create a new contact as the sender of the email' do
|
it 'create a new contact as the sender of the email' do
|
||||||
email_sender = Mail::Address.new(support_mail.mail[:from].value).name
|
|
||||||
expect(conversation.messages.last.sender.email).to eq(support_mail.mail.from.first)
|
expect(conversation.messages.last.sender.email).to eq(support_mail.mail.from.first)
|
||||||
expect(conversation.contact.name).to eq(email_sender)
|
expect(conversation.contact.name).to eq('Sony')
|
||||||
|
expect(conversation.contact.last_name).to eq('Mathew')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'add the mail content as new message on the conversation' do
|
it 'add the mail content as new message on the conversation' do
|
||||||
@@ -178,10 +178,9 @@ RSpec.describe SupportMailbox do
|
|||||||
|
|
||||||
it 'create new contact with original sender' do
|
it 'create new contact with original sender' do
|
||||||
described_subject
|
described_subject
|
||||||
email_sender = Mail::Address.new(group_sender_support_mail.mail[:from].value).name
|
|
||||||
|
|
||||||
expect(conversation.contact.email).to eq(group_sender_support_mail.mail['X-Original-Sender'].value)
|
expect(conversation.contact.email).to eq(group_sender_support_mail.mail['X-Original-Sender'].value)
|
||||||
expect(conversation.contact.name).to eq(email_sender)
|
expect(conversation.contact.name).to eq('ACME')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -156,7 +156,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')
|
||||||
expect(Contact.all.first.additional_attributes['social_line_user_id']).to eq('U4af4980629')
|
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
|
||||||
@@ -177,7 +177,7 @@ describe Line::IncomingMessageService do
|
|||||||
)
|
)
|
||||||
described_class.new(inbox: line_channel.inbox, params: sticker_params).perform
|
described_class.new(inbox: line_channel.inbox, params: sticker_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')
|
||||||
expect(line_channel.inbox.messages.first.content).to eq('')
|
expect(line_channel.inbox.messages.first.content).to eq('')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -204,7 +204,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')
|
||||||
expect(Contact.all.first.additional_attributes['social_line_user_id']).to eq('U4af4980629')
|
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')
|
||||||
@@ -234,7 +234,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')
|
||||||
expect(Contact.all.first.additional_attributes['social_line_user_id']).to eq('U4af4980629')
|
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')
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ describe Telegram::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
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')
|
||||||
|
expect(Contact.all.first.last_name).to eq('Jose')
|
||||||
expect(telegram_channel.inbox.messages.first.content).to eq('test')
|
expect(telegram_channel.inbox.messages.first.content).to eq('test')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -64,7 +65,8 @@ describe Telegram::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
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')
|
||||||
|
expect(Contact.all.first.last_name).to eq('Jose')
|
||||||
expect(Contact.all.first.additional_attributes['social_telegram_user_id']).to eq(23)
|
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(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')
|
||||||
@@ -106,7 +108,7 @@ describe Telegram::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
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')
|
||||||
expect(Contact.all.first.additional_attributes['social_telegram_user_id']).to eq(23)
|
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(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')
|
||||||
@@ -127,7 +129,7 @@ describe Telegram::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
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')
|
||||||
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('image')
|
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('image')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -152,7 +154,7 @@ describe Telegram::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
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')
|
||||||
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('image')
|
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('image')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -174,7 +176,7 @@ describe Telegram::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
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')
|
||||||
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('video')
|
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('video')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -193,7 +195,7 @@ describe Telegram::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
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')
|
||||||
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
|
||||||
@@ -214,7 +216,7 @@ describe Telegram::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
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')
|
||||||
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('file')
|
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('file')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -252,7 +254,7 @@ describe Telegram::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
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')
|
||||||
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('location')
|
expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('location')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -280,7 +282,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')
|
||||||
|
expect(Contact.all.first.last_name).to eq('Jose')
|
||||||
expect(Contact.all.first.additional_attributes['social_telegram_user_id']).to eq(5_171_248)
|
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
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ describe Whatsapp::IncomingMessageService do
|
|||||||
it 'creates appropriate conversations, message and contacts' do
|
it 'creates appropriate conversations, message and contacts' do
|
||||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
expect(whatsapp_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')
|
||||||
|
expect(Contact.all.first.last_name).to eq('Jose')
|
||||||
expect(whatsapp_channel.inbox.messages.first.content).to eq('Test')
|
expect(whatsapp_channel.inbox.messages.first.content).to eq('Test')
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -178,7 +179,7 @@ describe Whatsapp::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
expect(whatsapp_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')
|
||||||
expect(whatsapp_channel.inbox.messages.first.content).to eq('First Button')
|
expect(whatsapp_channel.inbox.messages.first.content).to eq('First Button')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -196,7 +197,7 @@ describe Whatsapp::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
expect(whatsapp_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')
|
||||||
expect(whatsapp_channel.inbox.messages.first.content).to eq('Yes this is a button')
|
expect(whatsapp_channel.inbox.messages.first.content).to eq('Yes this is a button')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -219,7 +220,7 @@ describe Whatsapp::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
expect(whatsapp_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')
|
||||||
expect(whatsapp_channel.inbox.messages.first.content).to eq('Check out my product!')
|
expect(whatsapp_channel.inbox.messages.first.content).to eq('Check out my product!')
|
||||||
expect(whatsapp_channel.inbox.messages.first.attachments.present?).to be true
|
expect(whatsapp_channel.inbox.messages.first.attachments.present?).to be true
|
||||||
end
|
end
|
||||||
@@ -240,7 +241,7 @@ describe Whatsapp::IncomingMessageService do
|
|||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
expect(whatsapp_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')
|
||||||
location_attachment = whatsapp_channel.inbox.messages.first.attachments.first
|
location_attachment = whatsapp_channel.inbox.messages.first.attachments.first
|
||||||
expect(location_attachment.file_type).to eq('location')
|
expect(location_attachment.file_type).to eq('location')
|
||||||
expect(location_attachment.fallback_title).to eq('Bay Bridge, San Francisco, CA, USA')
|
expect(location_attachment.fallback_title).to eq('Bay Bridge, San Francisco, CA, USA')
|
||||||
@@ -290,7 +291,8 @@ describe Whatsapp::IncomingMessageService do
|
|||||||
it 'creates appropriate conversations, message and contacts if contact does not exit' do
|
it 'creates appropriate conversations, message and contacts if contact does not exit' do
|
||||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
expect(whatsapp_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')
|
||||||
|
expect(Contact.all.first.last_name).to eq('Jose')
|
||||||
expect(whatsapp_channel.inbox.messages.first.content).to eq('Test')
|
expect(whatsapp_channel.inbox.messages.first.content).to eq('Test')
|
||||||
expect(whatsapp_channel.inbox.contact_inboxes.first.source_id).to eq(wa_id)
|
expect(whatsapp_channel.inbox.contact_inboxes.first.source_id).to eq(wa_id)
|
||||||
end
|
end
|
||||||
@@ -337,7 +339,7 @@ describe Whatsapp::IncomingMessageService do
|
|||||||
it 'creates contact inbox with the incoming waid' do
|
it 'creates contact inbox with the incoming waid' do
|
||||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
expect(whatsapp_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')
|
||||||
expect(whatsapp_channel.inbox.messages.first.content).to eq('Test')
|
expect(whatsapp_channel.inbox.messages.first.content).to eq('Test')
|
||||||
expect(whatsapp_channel.inbox.contact_inboxes.first.source_id).to eq(wa_id)
|
expect(whatsapp_channel.inbox.contact_inboxes.first.source_id).to eq(wa_id)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ describe Whatsapp::IncomingMessageWhatsappCloudService do
|
|||||||
|
|
||||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
expect(whatsapp_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')
|
||||||
|
expect(Contact.all.first.last_name).to eq('Jose')
|
||||||
expect(whatsapp_channel.inbox.messages.first.content).to eq('Check out my product!')
|
expect(whatsapp_channel.inbox.messages.first.content).to eq('Check out my product!')
|
||||||
expect(whatsapp_channel.inbox.messages.first.attachments.present?).to be true
|
expect(whatsapp_channel.inbox.messages.first.attachments.present?).to be true
|
||||||
end
|
end
|
||||||
@@ -60,7 +61,7 @@ describe Whatsapp::IncomingMessageWhatsappCloudService do
|
|||||||
|
|
||||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
expect(whatsapp_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')
|
||||||
expect(whatsapp_channel.inbox.messages.first.content).to eq('Check out my product!')
|
expect(whatsapp_channel.inbox.messages.first.content).to eq('Check out my product!')
|
||||||
expect(whatsapp_channel.inbox.messages.first.attachments.present?).to be false
|
expect(whatsapp_channel.inbox.messages.first.attachments.present?).to be false
|
||||||
expect(whatsapp_channel.authorization_error_count).to eq(1)
|
expect(whatsapp_channel.authorization_error_count).to eq(1)
|
||||||
@@ -100,7 +101,7 @@ describe Whatsapp::IncomingMessageWhatsappCloudService do
|
|||||||
it 'with attachment errors' do
|
it 'with attachment errors' do
|
||||||
described_class.new(inbox: whatsapp_channel.inbox, params: error_params).perform
|
described_class.new(inbox: whatsapp_channel.inbox, params: error_params).perform
|
||||||
expect(whatsapp_channel.inbox.conversations.count).not_to eq(0)
|
expect(whatsapp_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')
|
||||||
expect(whatsapp_channel.inbox.messages.count).to eq(0)
|
expect(whatsapp_channel.inbox.messages.count).to eq(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user