Restructure omni services and add Chatwoot research snapshot

This commit is contained in:
Ruslan Bakiev
2026-02-21 11:11:27 +07:00
parent edea7a0034
commit b73babbbf6
7732 changed files with 978203 additions and 32 deletions

View File

@@ -0,0 +1,9 @@
FactoryBot.define do
factory :channel_api, class: 'Channel::Api' do
webhook_url { 'http://example.com' }
account
after(:create) do |channel_api|
create(:inbox, channel: channel_api, account: channel_api.account)
end
end
end

View File

@@ -0,0 +1,38 @@
# frozen_string_literal: true
FactoryBot.define do
factory :channel_email, class: 'Channel::Email' do
sequence(:email) { |n| "care-#{n}@example.com" }
sequence(:forward_to_email) { |n| "forward-#{n}@chatwoot.com" }
account
after(:create) do |channel_email|
create(:inbox, channel: channel_email, account: channel_email.account)
end
trait :microsoft_email do
imap_enabled { true }
imap_address { 'outlook.office365.com' }
imap_port { 993 }
imap_login { 'email@example.com' }
imap_password { '' }
imap_enable_ssl { true }
provider_config do
{
expires_on: Time.zone.now + 3600,
access_token: SecureRandom.hex,
refresh_token: SecureRandom.hex
}
end
provider { 'microsoft' }
end
trait :imap_email do
imap_enabled { true }
imap_address { 'imap.gmail.com' }
imap_port { 993 }
imap_login { 'email@example.com' }
imap_password { 'random-password' }
imap_enable_ssl { true }
end
end
end

View File

@@ -0,0 +1,28 @@
FactoryBot.define do
factory :channel_instagram, class: 'Channel::Instagram' do
account
access_token { SecureRandom.hex(32) }
instagram_id { SecureRandom.hex(16) }
expires_at { 60.days.from_now }
updated_at { 25.hours.ago }
before :create do |channel|
WebMock::API.stub_request(:post, "https://graph.instagram.com/v22.0/#{channel.instagram_id}/subscribed_apps")
.with(query: {
access_token: channel.access_token,
subscribed_fields: %w[messages message_reactions messaging_seen]
})
.to_return(status: 200, body: '', headers: {})
WebMock::API.stub_request(:delete, "https://graph.instagram.com/v22.0/#{channel.instagram_id}/subscribed_apps")
.with(query: {
access_token: channel.access_token
})
.to_return(status: 200, body: '', headers: {})
end
after(:create) do |channel|
create(:inbox, channel: channel, account: channel.account)
end
end
end

View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
FactoryBot.define do
factory :channel_line, class: 'Channel::Line' do
line_channel_id { SecureRandom.uuid }
line_channel_secret { SecureRandom.uuid }
line_channel_token { SecureRandom.uuid }
inbox
account
end
end

View File

@@ -0,0 +1,16 @@
FactoryBot.define do
factory :channel_sms, class: 'Channel::Sms' do
sequence(:phone_number) { |n| "+123456789#{n}1" }
account
provider_config do
{ 'account_id' => '1',
'application_id' => '1',
'api_key' => '1',
'api_secret' => '1' }
end
after(:create) do |channel_sms|
create(:inbox, channel: channel_sms, account: channel_sms.account)
end
end
end

View File

@@ -0,0 +1,16 @@
FactoryBot.define do
factory :channel_telegram, class: 'Channel::Telegram' do
bot_token { '2324234324' }
account
before(:create) do |channel_telegram|
# we are skipping some of the validation methods
channel_telegram.define_singleton_method(:ensure_valid_bot_token) { nil }
channel_telegram.define_singleton_method(:setup_telegram_webhook) { nil }
end
after(:create) do |channel_telegram|
create(:inbox, channel: channel_telegram, account: channel_telegram.account)
end
end
end

View File

@@ -0,0 +1,16 @@
# frozen_string_literal: true
FactoryBot.define do
factory :channel_tiktok, class: 'Channel::Tiktok' do
account
business_id { SecureRandom.hex(16) }
access_token { SecureRandom.hex(32) }
refresh_token { SecureRandom.hex(32) }
expires_at { 1.day.from_now }
refresh_token_expires_at { 30.days.from_now }
after(:create) do |channel|
create(:inbox, channel: channel, account: channel.account)
end
end
end

View File

@@ -0,0 +1,21 @@
# frozen_string_literal: true
FactoryBot.define do
factory :channel_voice, class: 'Channel::Voice' do
sequence(:phone_number) { |n| "+155512345#{n.to_s.rjust(2, '0')}" }
provider_config do
{
account_sid: "AC#{SecureRandom.hex(16)}",
auth_token: SecureRandom.hex(16),
api_key_sid: SecureRandom.hex(8),
api_key_secret: SecureRandom.hex(16),
twiml_app_sid: "AP#{SecureRandom.hex(16)}"
}
end
account
after(:create) do |channel_voice|
create(:inbox, channel: channel_voice, account: channel_voice.account)
end
end
end

View File

@@ -0,0 +1,116 @@
FactoryBot.define do
factory :channel_whatsapp, class: 'Channel::Whatsapp' do
sequence(:phone_number) { |n| "+123456789#{n}1" }
account
provider_config { { 'api_key' => 'test_key', 'phone_number_id' => 'random_id' } }
message_templates do
[{ 'name' => 'sample_shipping_confirmation',
'status' => 'approved',
'category' => 'SHIPPING_UPDATE',
'language' => 'id',
'namespace' => '2342384942_32423423_23423fdsdaf',
'components' =>
[{ 'text' => 'Paket Anda sudah dikirim. Paket akan sampai dalam {{1}} hari kerja.', 'type' => 'BODY' },
{ 'text' => 'Pesan ini berasal dari bisnis yang tidak terverifikasi.', 'type' => 'FOOTER' }],
'rejected_reason' => 'NONE' },
{ 'name' => 'customer_yes_no',
'status' => 'approved',
'category' => 'SHIPPING_UPDATE',
'language' => 'ar',
'namespace' => '2342384942_32423423_23423fdsdaf23',
'components' =>
[{ 'text' => 'عميلنا العزيز الرجاء الرد على هذه الرسالة بكلمة *نعم* للرد على إستفساركم من قبل خدمة العملاء.',
'type' => 'BODY' }],
'rejected_reason' => 'NONE' },
{ 'name' => 'sample_shipping_confirmation',
'status' => 'approved',
'category' => 'SHIPPING_UPDATE',
'language' => 'en_US',
'namespace' => '23423423_2342423_324234234_2343224',
'components' =>
[{ 'text' => 'Your package has been shipped. It will be delivered in {{1}} business days.', 'type' => 'BODY' },
{ 'text' => 'This message is from an unverified business.', 'type' => 'FOOTER' }],
'rejected_reason' => 'NONE' },
{
'name' => 'ticket_status_updated',
'status' => 'APPROVED',
'category' => 'UTILITY',
'language' => 'en',
'namespace' => '23423423_2342423_324234234_2343224',
'components' => [
{ 'text' => "Hello {{name}}, Your support ticket with ID: \#{{ticket_id}} has been updated by the support agent.",
'type' => 'BODY',
'example' => { 'body_text_named_params' => [
{ 'example' => 'John', 'param_name' => 'name' },
{ 'example' => '2332', 'param_name' => 'ticket_id' }
] } }
],
'sub_category' => 'CUSTOM',
'parameter_format' => 'NAMED'
},
{
'name' => 'ticket_status_updated',
'status' => 'APPROVED',
'category' => 'UTILITY',
'language' => 'en_US',
'components' => [
{ 'text' => "Hello {{last_name}}, Your support ticket with ID: \#{{ticket_id}} has been updated by the support agent.",
'type' => 'BODY',
'example' => { 'body_text_named_params' => [
{ 'example' => 'Dale', 'param_name' => 'last_name' },
{ 'example' => '2332', 'param_name' => 'ticket_id' }
] } }
],
'sub_category' => 'CUSTOM',
'parameter_format' => 'NAMED'
},
{
'name' => 'test_no_params_template',
'status' => 'APPROVED',
'category' => 'UTILITY',
'language' => 'en',
'namespace' => 'ed41a221_133a_4558_a1d6_192960e3aee9',
'id' => '9876543210987654',
'length' => 1,
'parameter_format' => 'POSITIONAL',
'previous_category' => 'MARKETING',
'sub_category' => 'CUSTOM',
'components' => [
{
'text' => 'Thank you for contacting us! Your request has been processed successfully. Have a great day! 🙂',
'type' => 'BODY'
}
],
'rejected_reason' => 'NONE'
}]
end
message_templates_last_updated { Time.now.utc }
transient do
sync_templates { true }
validate_provider_config { true }
end
before(:create) do |channel_whatsapp, options|
# since factory already has the required message templates, we just need to bypass it getting updated
channel_whatsapp.define_singleton_method(:sync_templates) { nil } unless options.sync_templates
channel_whatsapp.define_singleton_method(:validate_provider_config) { nil } unless options.validate_provider_config
if channel_whatsapp.provider == 'whatsapp_cloud'
# Add 'source' => 'embedded_signup' to skip after_commit :setup_webhooks callback in tests
# The callback is for manual setup flow; embedded signup handles webhook setup explicitly
# Only set source if not already provided (allows tests to override)
default_config = {
'api_key' => 'test_key',
'phone_number_id' => '123456789',
'business_account_id' => '123456789'
}
default_config['source'] = 'embedded_signup' unless channel_whatsapp.provider_config.key?('source')
channel_whatsapp.provider_config = channel_whatsapp.provider_config.merge(default_config)
end
end
after(:create) do |channel_whatsapp|
create(:inbox, channel: channel_whatsapp, account: channel_whatsapp.account)
end
end
end

View File

@@ -0,0 +1,12 @@
# frozen_string_literal: true
FactoryBot.define do
factory :channel_widget, class: 'Channel::WebWidget' do
sequence(:website_url) { |n| "https://example-#{n}.com" }
sequence(:widget_color, &:to_s)
account
after(:create) do |channel_widget|
create(:inbox, channel: channel_widget, account: channel_widget.account)
end
end
end

View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
FactoryBot.define do
factory :channel_facebook_page, class: 'Channel::FacebookPage' do
page_access_token { SecureRandom.uuid }
user_access_token { SecureRandom.uuid }
page_id { SecureRandom.uuid }
inbox
account
end
end

View File

@@ -0,0 +1,14 @@
# frozen_string_literal: true
FactoryBot.define do
factory :channel_instagram_fb_page, class: 'Channel::FacebookPage' do
page_access_token { SecureRandom.uuid }
user_access_token { SecureRandom.uuid }
page_id { SecureRandom.uuid }
account
before :create do |_channel|
WebMock::API.stub_request(:post, 'https://graph.facebook.com/v3.2/me/subscribed_apps')
end
end
end

View File

@@ -0,0 +1,21 @@
FactoryBot.define do
factory :channel_twilio_sms, class: 'Channel::TwilioSms' do
auth_token { SecureRandom.uuid }
account_sid { SecureRandom.uuid }
messaging_service_sid { "MG#{Faker::Number.hexadecimal(digits: 32)}" }
medium { :sms }
account
after(:build) do |channel|
channel.inbox ||= create(:inbox, account: channel.account)
end
trait :with_phone_number do
sequence(:phone_number) { |n| "+123456789#{n}1" }
messaging_service_sid { nil }
end
trait :whatsapp do
medium { :whatsapp }
end
end
end

View File

@@ -0,0 +1,10 @@
# frozen_string_literal: true
FactoryBot.define do
factory :channel_twitter_profile, class: 'Channel::TwitterProfile' do
twitter_access_token { SecureRandom.uuid }
twitter_access_token_secret { SecureRandom.uuid }
profile_id { SecureRandom.uuid }
account
end
end