Chore: Release Fixes (#3011)

- Fix super admin crashing
- Fix error on telegram group messages

fixes: #2856
This commit is contained in:
Sojan Jose 2021-09-14 15:54:57 +05:30 committed by GitHub
parent 2c381d726d
commit 946a09928e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 10 deletions

View file

@ -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

View file

@ -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

View file

@ -53,10 +53,6 @@ It renders the `_table` partial to display details about the resources.
<div class="metric"><%= @conversations_count %></div>
<div>Conversations</div>
</div>
<div class="report-card">
<div class="metric"><%= @messages_count %></div>
<div>Messages</div>
</div>
</div>
<div class="chart--container" style="height:500px">

View file

@ -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