From 99fbe41b16d5b91f70e2474df4755a920bf0b118 Mon Sep 17 00:00:00 2001 From: Max Melentiev Date: Fri, 9 Dec 2016 13:33:55 +0300 Subject: [PATCH] Fixed support for *channel_post updates --- CHANGELOG.md | 2 +- lib/telegram/bot/updates_controller.rb | 4 +- lib/telegram/bot/version.rb | 2 +- spec/telegram/bot/updates_controller_spec.rb | 58 ++++++++++---------- 4 files changed, 35 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0315573..324f3f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.10.1 +# 0.10.2 - Support `(edited_)channel_post` updates. - New methods from 2.3, 2.3.1 API updates. diff --git a/lib/telegram/bot/updates_controller.rb b/lib/telegram/bot/updates_controller.rb index 3a782bb..bb7f3a4 100644 --- a/lib/telegram/bot/updates_controller.rb +++ b/lib/telegram/bot/updates_controller.rb @@ -50,7 +50,7 @@ module Telegram # ControllerClass.new(bot, from: telegram_user, chat: telegram_chat). # process(:help, *args) # - class UpdatesController < AbstractController::Base + class UpdatesController < AbstractController::Base # rubocop:disable ClassLength abstract! require 'telegram/bot/updates_controller/session' @@ -183,11 +183,13 @@ module Telegram cmd &&= self.class.action_for_command(cmd) [true, cmd, args] if cmd end + alias_method :action_for_channel_post, :action_for_message # It doesn't extract commands from edited messages. Just process # them as usual ones. def action_for_edited_message end + alias_method :action_for_edited_channel_post, :action_for_edited_message def action_for_inline_query [false, payload_type, [payload['query'], payload['offset']]] diff --git a/lib/telegram/bot/version.rb b/lib/telegram/bot/version.rb index e6040bd..0011533 100644 --- a/lib/telegram/bot/version.rb +++ b/lib/telegram/bot/version.rb @@ -1,6 +1,6 @@ module Telegram module Bot - VERSION = '0.10.1'.freeze + VERSION = '0.10.2'.freeze def self.gem_version Gem::Version.new VERSION diff --git a/spec/telegram/bot/updates_controller_spec.rb b/spec/telegram/bot/updates_controller_spec.rb index cf57834..a24d021 100644 --- a/spec/telegram/bot/updates_controller_spec.rb +++ b/spec/telegram/bot/updates_controller_spec.rb @@ -102,42 +102,44 @@ RSpec.describe Telegram::Bot::UpdatesController do it { should eq [false, payload_type, payload.values_at(:data)] } end - context 'when payload is edited_message' do - let(:payload_type) { 'edited_message' } - it { should eq [false, payload_type, [payload]] } - end - context 'when payload is not supported' do let(:payload_type) { '_unsupported_' } it { should eq [false, :unsupported_payload_type, []] } end - context 'when payload is message' do - let(:payload_type) { 'message' } - let(:payload) { {'text' => text} } - let(:text) { 'test' } - - it { should eq [false, payload_type, [payload]] } - - context 'with command' do - let(:text) { "/test#{"@#{mention}" if mention} arg 1 2" } - let(:mention) {} - it { should eq [true, 'test', %w(arg 1 2)] } - - context 'with mention' do - let(:mention) { bot.username } - it { should eq [true, 'test', %w(arg 1 2)] } - end - - context 'with mention for other bot' do - let(:mention) { other_bot_name } - it { should eq [false, 'message', [payload]] } - end + %w(message channel_post).each do |type| + context 'when payload is edited_message' do + let(:payload_type) { "edited_#{type}" } + it { should eq [false, payload_type, [payload]] } end - context 'without text' do - let(:payload) { {'audio' => {'file_id' => 123}} } + context 'when payload is message' do + let(:payload_type) { type } + let(:payload) { {'text' => text} } + let(:text) { 'test' } + it { should eq [false, payload_type, [payload]] } + + context 'with command' do + let(:text) { "/test#{"@#{mention}" if mention} arg 1 2" } + let(:mention) {} + it { should eq [true, 'test', %w(arg 1 2)] } + + context 'with mention' do + let(:mention) { bot.username } + it { should eq [true, 'test', %w(arg 1 2)] } + end + + context 'with mention for other bot' do + let(:mention) { other_bot_name } + it { should eq [false, payload_type, [payload]] } + end + end + + context 'without text' do + let(:payload) { {'audio' => {'file_id' => 123}} } + it { should eq [false, payload_type, [payload]] } + end end end end