Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/telegram_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,9 @@ def to_group(params, group_id, channel)
params.delete(:edited_channel_post) # discard unused :edited_channel_post hash
end

# Other update types (e.g. my_chat_member when a user blocks the bot) carry nothing to import.
return if !params[:message] && !params[:edited_message]

# prevent multiple update
return if !params[:edited_message] && Ticket::Article.exists?(message_id: TelegramHelper.message_id(params))

Expand Down
6 changes: 6 additions & 0 deletions spec/requests/integration/telegram_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@
expect(response).to have_http_status(:ok)
end

it 'ignores update without message (e.g. bot blocked by user)' do
expect { post callback_url, params: read_message('private', 'my_chat_member'), as: :json }
.not_to change(Ticket::Article, :count)
expect(response).to have_http_status(:ok)
end

it 'text message' do
post callback_url, params: read_message('private', 'text'), as: :json
expect(response).to have_http_status(:ok)
Expand Down
39 changes: 39 additions & 0 deletions test/data/telegram/private/my_chat_member.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"update_id":2,
"my_chat_member":{
"chat": {
"id":111111,
"first_name":"Test Firstname",
"last_name":"Test Lastname",
"username":"Testusername",
"type":"private"
},
"from": {
"id":111111,
"is_bot":false,
"first_name":"Test Firstname",
"last_name":"Test Lastname",
"username":"Testusername"
},
"date":1441645600,
"old_chat_member": {
"user": {
"id":222222,
"is_bot":true,
"first_name":"Chrispresso Customer Service",
"username":"ChrispressoBot"
},
"status":"member"
},
"new_chat_member": {
"user": {
"id":222222,
"is_bot":true,
"first_name":"Chrispresso Customer Service",
"username":"ChrispressoBot"
},
"status":"kicked",
"until_date":0
}
}
}