Skip to content

Commit

Permalink
Merge pull request #1694 from tactilenews/fix-1692
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwr18 authored Sep 6, 2023
2 parents 4c2ef5c + 3c207f2 commit 92f5039
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/adapters/telegram_adapter/inbound.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ def initialize_sender(telegram_message)
return sender
end

unless text
trigger(UNKNOWN_CONTRIBUTOR)
return nil
end

telegram_onboarding_token = text.delete_prefix('/start').strip.upcase
sender = Contributor.find_by(telegram_id: nil, telegram_onboarding_token: telegram_onboarding_token)

if sender
sender.username = username
sender.telegram_id = telegram_id
Expand Down
58 changes: 58 additions & 0 deletions spec/adapters/telegram_adapter/inbound_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@
describe '|message| block argument' do
subject { message }
it { should be_a(Message) }

describe 'given the payload does not have a caption nor text' do
let(:telegram_message) { telegram_message_from_spammer }

it { should be_nil }

describe 'when UNKNOWN_CONTRIBUTOR is registered' do
subject do
proc do |block|
adapter.on(TelegramAdapter::UNKNOWN_CONTRIBUTOR, &block)
adapter.consume(telegram_message)
end
end

it { should yield_control }
end
end
end

describe '|message|text' do
Expand Down Expand Up @@ -251,4 +268,45 @@
'width' => 460,
'height' => 460 }] }
end

let(:telegram_message_from_spammer) do
{
message_id: 25,
from: {
id: 5_521_147_309,
is_bot: false,
# rubocop:disable Layout/LineLength
first_name: "\u0423\u043c\u0438\u0440\u0430\u044e \u0438 \u0432\u0441\u0435 \u0440\u0430\u0434\u044b \u043a\u0430\u043a \u0438 \u044f)",
# rubocop:enable Layout/LineLength
username: 'Annazollo'
},
chat: {
id: -1_001_597_054_590,
title: "Milfa \u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0447\u0430\u0442",
username: 'milfadanil',
type: 'supergroup'
},
date: 1_693_849_886,
new_chat_participant: {
id: 5_829_883_840,
is_bot: true,
first_name: 'Wir sind Potsdam',
username: 'MAZ_Potsdam_Bot'
},
new_chat_member: {
id: 5_829_883_840,
is_bot: true,
first_name: 'Wir sind Potsdam',
username: 'MAZ_Potsdam_Bot'
},
new_chat_members: [
{
id: 5_829_883_840,
is_bot: true,
first_name: 'Wir sind Potsdam',
username: 'MAZ_Potsdam_Bot'
}
]
}
end
end

0 comments on commit 92f5039

Please sign in to comment.