diff --git a/app/controllers/super_admin/dashboard_controller.rb b/app/controllers/super_admin/dashboard_controller.rb index b5f3d34eb..56d19d563 100644 --- a/app/controllers/super_admin/dashboard_controller.rb +++ b/app/controllers/super_admin/dashboard_controller.rb @@ -3,10 +3,9 @@ class SuperAdmin::DashboardController < SuperAdmin::ApplicationController def index @data = Conversation.unscoped.group_by_day(:created_at, range: 30.days.ago..2.seconds.ago).count.to_a - @accounts_count = number_with_delimiter(Account.all.length) - @users_count = number_with_delimiter(User.all.length) - @inboxes_count = number_with_delimiter(Inbox.all.length) - @conversations_count = number_with_delimiter(Conversation.all.length) - @messages_count = number_with_delimiter(Message.all.length) + @accounts_count = number_with_delimiter(Account.count) + @users_count = number_with_delimiter(User.count) + @inboxes_count = number_with_delimiter(Inbox.count) + @conversations_count = number_with_delimiter(Conversation.count) end end diff --git a/app/services/telegram/incoming_message_service.rb b/app/services/telegram/incoming_message_service.rb index 0e47f2813..ac1459887 100644 --- a/app/services/telegram/incoming_message_service.rb +++ b/app/services/telegram/incoming_message_service.rb @@ -1,8 +1,14 @@ +# Find the various telegram payload samples here: https://core.telegram.org/bots/webhooks#testing-your-bot-with-updates +# https://core.telegram.org/bots/api#available-types + class Telegram::IncomingMessageService include ::FileTypeHelper pattr_initialize [:inbox!, :params!] def perform + # chatwoot doesn't support group conversations at the moment + return unless private_message? + set_contact update_contact_avatar set_conversation @@ -20,6 +26,10 @@ class Telegram::IncomingMessageService private + def private_message? + params.dig(:message, :chat, :type) == 'private' + end + def account @account ||= inbox.account end diff --git a/app/views/super_admin/dashboard/index.html.erb b/app/views/super_admin/dashboard/index.html.erb index 967c00e55..0121a8a75 100644 --- a/app/views/super_admin/dashboard/index.html.erb +++ b/app/views/super_admin/dashboard/index.html.erb @@ -53,10 +53,6 @@ It renders the `_table` partial to display details about the resources.
<%= @conversations_count %>
Conversations
-
-
<%= @messages_count %>
-
Messages
-
diff --git a/spec/services/telegram/incoming_message_service_spec.rb b/spec/services/telegram/incoming_message_service_spec.rb index 79e361c79..9a1433794 100644 --- a/spec/services/telegram/incoming_message_service_spec.rb +++ b/spec/services/telegram/incoming_message_service_spec.rb @@ -18,10 +18,28 @@ describe Telegram::IncomingMessageService do } }.with_indifferent_access described_class.new(inbox: telegram_channel.inbox, params: params).perform - expect(telegram_channel.inbox.conversations).not_to eq(0) + expect(telegram_channel.inbox.conversations.count).not_to eq(0) expect(Contact.all.first.name).to eq('Sojan Jose') expect(telegram_channel.inbox.messages.first.content).to eq('test') end end + + context 'when group messages' do + it 'doesnot create conversations, message and contacts' do + params = { + 'update_id' => 2_342_342_343_242, + 'message' => { + 'message_id' => 1, + 'from' => { + 'id' => 23, 'is_bot' => false, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'language_code' => 'en' + }, + 'chat' => { 'id' => 23, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'type' => 'group' }, + 'date' => 1_631_132_077, 'text' => 'test' + } + }.with_indifferent_access + described_class.new(inbox: telegram_channel.inbox, params: params).perform + expect(telegram_channel.inbox.conversations.count).to eq(0) + end + end end end