зеркало из
https://github.com/glebtv/telegram-bot.git
synced 2026-09-03 17:55:52 +03:00
Сравнить коммиты
6 Коммитов
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
8494c7df0c | ||
|
|
a2659e00c2 | ||
|
|
e43c611d9d | ||
|
|
b84c48bc1d | ||
|
|
43cd096a21 | ||
|
|
903e14a3e5 |
@@ -1,5 +1,11 @@
|
|||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
|
# 0.14.4
|
||||||
|
|
||||||
|
- Update to Bot API 4.7
|
||||||
|
|
||||||
|
# 0.14.3
|
||||||
|
|
||||||
- Rails 6.0 support.
|
- Rails 6.0 support.
|
||||||
- Update to Bot API 4.4.
|
- Update to Bot API 4.4.
|
||||||
|
|
||||||
|
|||||||
2
Gemfile
2
Gemfile
@@ -8,7 +8,7 @@ group :development do
|
|||||||
gem 'pry-byebug', '~> 3.2.0'
|
gem 'pry-byebug', '~> 3.2.0'
|
||||||
gem 'sdoc', '~> 0.4.1'
|
gem 'sdoc', '~> 0.4.1'
|
||||||
|
|
||||||
gem 'telegram-bot-types', '~> 0.6.0'
|
gem 'telegram-bot-types', '~> 0.6.2'
|
||||||
|
|
||||||
gem 'rspec', '~> 3.5.0'
|
gem 'rspec', '~> 3.5.0'
|
||||||
gem 'rspec-its', '~> 1.1.0'
|
gem 'rspec-its', '~> 1.1.0'
|
||||||
|
|||||||
@@ -475,10 +475,11 @@ RSpec.describe TelegramWebhooksController, telegram_bot: :rails do
|
|||||||
# dispatch_command(cmd, *args)
|
# dispatch_command(cmd, *args)
|
||||||
|
|
||||||
# Available matchers can be found in Telegram::Bot::RSpec::ClientMatchers.
|
# Available matchers can be found in Telegram::Bot::RSpec::ClientMatchers.
|
||||||
it 'shows usage of basic matchers'
|
it 'shows usage of basic matchers' do
|
||||||
# The most basic one is #make_telegram_request(bot, endpoint, params_matcher)
|
# The most basic one is #make_telegram_request(bot, action).
|
||||||
expect { dispatch_command(:start) }.
|
# It works similar to `receive` matcher and supports chaining `.with(args).exactly(n).times`.
|
||||||
to make_telegram_request(bot, :sendMessage, hash_including(text: 'msg text'))
|
expect { dispatch_command(:start) }.to make_telegram_request(bot, :sendMessage).
|
||||||
|
with(hash_including(text: 'msg text'))
|
||||||
|
|
||||||
# There are some shortcuts for dispatching basic updates and testing responses.
|
# There are some shortcuts for dispatching basic updates and testing responses.
|
||||||
expect { dispatch_message('Hi') }.to send_telegram_message(bot, /msg regexp/, some: :option)
|
expect { dispatch_message('Hi') }.to send_telegram_message(bot, /msg regexp/, some: :option)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ group :development do
|
|||||||
gem "pry", "~> 0.10.1"
|
gem "pry", "~> 0.10.1"
|
||||||
gem "pry-byebug", "~> 3.2.0"
|
gem "pry-byebug", "~> 3.2.0"
|
||||||
gem "sdoc", "~> 0.4.1"
|
gem "sdoc", "~> 0.4.1"
|
||||||
gem "telegram-bot-types", "~> 0.6.0"
|
gem "telegram-bot-types", "~> 0.6.2"
|
||||||
gem "rspec", "~> 3.5.0"
|
gem "rspec", "~> 3.5.0"
|
||||||
gem "rspec-its", "~> 1.1.0"
|
gem "rspec-its", "~> 1.1.0"
|
||||||
gem "rspec-rails", "~> 3.5.0"
|
gem "rspec-rails", "~> 3.5.0"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ group :development do
|
|||||||
gem "pry", "~> 0.10.1"
|
gem "pry", "~> 0.10.1"
|
||||||
gem "pry-byebug", "~> 3.2.0"
|
gem "pry-byebug", "~> 3.2.0"
|
||||||
gem "sdoc", "~> 0.4.1"
|
gem "sdoc", "~> 0.4.1"
|
||||||
gem "telegram-bot-types", "~> 0.6.0"
|
gem "telegram-bot-types", "~> 0.6.2"
|
||||||
gem "rspec", "~> 3.5.0"
|
gem "rspec", "~> 3.5.0"
|
||||||
gem "rspec-its", "~> 1.1.0"
|
gem "rspec-its", "~> 1.1.0"
|
||||||
gem "rspec-rails", "~> 3.5.0"
|
gem "rspec-rails", "~> 3.5.0"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ group :development do
|
|||||||
gem "pry", "~> 0.10.1"
|
gem "pry", "~> 0.10.1"
|
||||||
gem "pry-byebug", "~> 3.2.0"
|
gem "pry-byebug", "~> 3.2.0"
|
||||||
gem "sdoc", "~> 0.4.1"
|
gem "sdoc", "~> 0.4.1"
|
||||||
gem "telegram-bot-types", "~> 0.6.0"
|
gem "telegram-bot-types", "~> 0.6.2"
|
||||||
gem "rspec", "~> 3.5.0"
|
gem "rspec", "~> 3.5.0"
|
||||||
gem "rspec-its", "~> 1.1.0"
|
gem "rspec-its", "~> 1.1.0"
|
||||||
gem "rspec-rails", "~> 3.5.0"
|
gem "rspec-rails", "~> 3.5.0"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ group :development do
|
|||||||
gem "pry", "~> 0.10.1"
|
gem "pry", "~> 0.10.1"
|
||||||
gem "pry-byebug", "~> 3.2.0"
|
gem "pry-byebug", "~> 3.2.0"
|
||||||
gem "sdoc", "~> 0.4.1"
|
gem "sdoc", "~> 0.4.1"
|
||||||
gem "telegram-bot-types", "~> 0.6.0"
|
gem "telegram-bot-types", "~> 0.6.2"
|
||||||
gem "rspec", "~> 3.5.0"
|
gem "rspec", "~> 3.5.0"
|
||||||
gem "rspec-its", "~> 1.1.0"
|
gem "rspec-its", "~> 1.1.0"
|
||||||
gem "rspec-rails", "~> 3.5.0"
|
gem "rspec-rails", "~> 3.5.0"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ group :development do
|
|||||||
gem "pry", "~> 0.10.1"
|
gem "pry", "~> 0.10.1"
|
||||||
gem "pry-byebug", "~> 3.2.0"
|
gem "pry-byebug", "~> 3.2.0"
|
||||||
gem "sdoc", "~> 0.4.1"
|
gem "sdoc", "~> 0.4.1"
|
||||||
gem "telegram-bot-types", "~> 0.6.0"
|
gem "telegram-bot-types", "~> 0.6.2"
|
||||||
gem "rspec", "~> 3.5.0"
|
gem "rspec", "~> 3.5.0"
|
||||||
gem "rspec-its", "~> 1.1.0"
|
gem "rspec-its", "~> 1.1.0"
|
||||||
gem "rspec-rails", "~> 3.5.0"
|
gem "rspec-rails", "~> 3.5.0"
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ group :development do
|
|||||||
gem "pry", "~> 0.10.1"
|
gem "pry", "~> 0.10.1"
|
||||||
gem "pry-byebug", "~> 3.2.0"
|
gem "pry-byebug", "~> 3.2.0"
|
||||||
gem "sdoc", "~> 0.4.1"
|
gem "sdoc", "~> 0.4.1"
|
||||||
gem "telegram-bot-types", "~> 0.6.0"
|
gem "telegram-bot-types", "~> 0.6.2"
|
||||||
gem "rspec", "~> 3.5.0"
|
gem "rspec", "~> 3.5.0"
|
||||||
gem "rspec-its", "~> 1.1.0"
|
gem "rspec-its", "~> 1.1.0"
|
||||||
gem "rspec-rails", "~> 3.5.0"
|
gem "rspec-rails", "~> 3.5.0"
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ module Telegram
|
|||||||
# accessible via `Teletgram.bots[id]` in job worker. Or just use
|
# accessible via `Teletgram.bots[id]` in job worker. Or just use
|
||||||
# `Telegram.bots_config=` for configuration.
|
# `Telegram.bots_config=` for configuration.
|
||||||
#
|
#
|
||||||
# Being in async mode `#request` enqueues job instead to perform
|
# Being in async mode `#request` enqueues job to perform
|
||||||
# http request instead of performing it directly.
|
# http request instead of performing it immediately.
|
||||||
# Async behavior is controlled with `#async=` writer
|
# Async behavior is controlled with `#async=` writer
|
||||||
# and can be enabled/disabled for the block with `#async`:
|
# and can be enabled/disabled for the block with `#async`:
|
||||||
#
|
#
|
||||||
@@ -29,7 +29,7 @@ module Telegram
|
|||||||
# while `#async(val, &block)` is thread-safe.
|
# while `#async(val, &block)` is thread-safe.
|
||||||
#
|
#
|
||||||
# It can be set with custom job class or classname. By default it defines
|
# It can be set with custom job class or classname. By default it defines
|
||||||
# job classes for every client class, inherited from ApplicationRecord, which
|
# job classes inherited from ApplicationJob, which
|
||||||
# can be accessed via `.default_async_job`. You can integrate it with any
|
# can be accessed via `.default_async_job`. You can integrate it with any
|
||||||
# other job provider by defining a class with `.perform_later(bot_id, *args)`
|
# other job provider by defining a class with `.perform_later(bot_id, *args)`
|
||||||
# method. See Async::Job for implemetation.
|
# method. See Async::Job for implemetation.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Generated with bin/fetch-telegram-methods
|
# Generated with bin/fetch-telegram-methods
|
||||||
# Bot API 4.4
|
# Bot API 4.7
|
||||||
|
|
||||||
getUpdates
|
getUpdates
|
||||||
setWebhook
|
setWebhook
|
||||||
@@ -23,6 +23,7 @@ stopMessageLiveLocation
|
|||||||
sendVenue
|
sendVenue
|
||||||
sendContact
|
sendContact
|
||||||
sendPoll
|
sendPoll
|
||||||
|
sendDice
|
||||||
sendChatAction
|
sendChatAction
|
||||||
getUserProfilePhotos
|
getUserProfilePhotos
|
||||||
getFile
|
getFile
|
||||||
@@ -30,6 +31,7 @@ kickChatMember
|
|||||||
unbanChatMember
|
unbanChatMember
|
||||||
restrictChatMember
|
restrictChatMember
|
||||||
promoteChatMember
|
promoteChatMember
|
||||||
|
setChatAdministratorCustomTitle
|
||||||
setChatPermissions
|
setChatPermissions
|
||||||
exportChatInviteLink
|
exportChatInviteLink
|
||||||
setChatPhoto
|
setChatPhoto
|
||||||
@@ -46,6 +48,8 @@ getChatMember
|
|||||||
setChatStickerSet
|
setChatStickerSet
|
||||||
deleteChatStickerSet
|
deleteChatStickerSet
|
||||||
answerCallbackQuery
|
answerCallbackQuery
|
||||||
|
setMyCommands
|
||||||
|
getMyCommands
|
||||||
|
|
||||||
editMessageText
|
editMessageText
|
||||||
editMessageCaption
|
editMessageCaption
|
||||||
@@ -61,6 +65,7 @@ createNewStickerSet
|
|||||||
addStickerToSet
|
addStickerToSet
|
||||||
setStickerPositionInSet
|
setStickerPositionInSet
|
||||||
deleteStickerFromSet
|
deleteStickerFromSet
|
||||||
|
setStickerSetThumb
|
||||||
|
|
||||||
answerInlineQuery
|
answerInlineQuery
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,8 @@ module Telegram
|
|||||||
callback_query
|
callback_query
|
||||||
shipping_query
|
shipping_query
|
||||||
pre_checkout_query
|
pre_checkout_query
|
||||||
|
poll
|
||||||
|
poll_answer
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
@@ -148,7 +150,7 @@ module Telegram
|
|||||||
# Accessor to `'from'` field of payload. Can be overriden with `from` option
|
# Accessor to `'from'` field of payload. Can be overriden with `from` option
|
||||||
# for #initialize.
|
# for #initialize.
|
||||||
def from
|
def from
|
||||||
@_from ||= payload && payload['from']
|
@_from ||= payload.is_a?(Hash) ? payload['from'] : payload.try(:from)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Processes current update.
|
# Processes current update.
|
||||||
@@ -206,6 +208,10 @@ module Telegram
|
|||||||
[payload_type, [payload['data']]]
|
[payload_type, [payload['data']]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def action_for_poll_answer
|
||||||
|
[payload_type, [payload['poll_id'], payload['option_ids']]]
|
||||||
|
end
|
||||||
|
|
||||||
# Silently ignore unsupported messages to not fail when user crafts
|
# Silently ignore unsupported messages to not fail when user crafts
|
||||||
# an update with usupported command, callback query context, etc.
|
# an update with usupported command, callback query context, etc.
|
||||||
def action_missing(action, *_args)
|
def action_missing(action, *_args)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module Telegram
|
module Telegram
|
||||||
module Bot
|
module Bot
|
||||||
VERSION = '0.14.3'.freeze
|
VERSION = '0.14.4'.freeze
|
||||||
|
|
||||||
def self.gem_version
|
def self.gem_version
|
||||||
Gem::Version.new VERSION
|
Gem::Version.new VERSION
|
||||||
|
|||||||
@@ -26,6 +26,12 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
|||||||
it { should eq [payload_type, payload.values_at(:data)] }
|
it { should eq [payload_type, payload.values_at(:data)] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when payload is poll_answer' do
|
||||||
|
let(:payload_type) { 'poll_answer' }
|
||||||
|
let(:payload) { stub_payload(:poll_id, :user, :option_ids) }
|
||||||
|
it { should eq [payload_type, payload.values_at(:poll_id, :option_ids)] }
|
||||||
|
end
|
||||||
|
|
||||||
context 'when payload is not supported' do
|
context 'when payload is not supported' do
|
||||||
let(:payload_type) { '_unsupported_' }
|
let(:payload_type) { '_unsupported_' }
|
||||||
it { should eq [:unsupported_payload_type, []] }
|
it { should eq [:unsupported_payload_type, []] }
|
||||||
@@ -39,6 +45,7 @@ RSpec.describe Telegram::Bot::UpdatesController do
|
|||||||
inline_query
|
inline_query
|
||||||
chosen_inline_result
|
chosen_inline_result
|
||||||
callback_query
|
callback_query
|
||||||
|
poll_answer
|
||||||
]
|
]
|
||||||
(described_class::PAYLOAD_TYPES - custom_payload_types).each do |type|
|
(described_class::PAYLOAD_TYPES - custom_payload_types).each do |type|
|
||||||
context "when payload is #{type}" do
|
context "when payload is #{type}" do
|
||||||
|
|||||||
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
|
|||||||
spec.add_dependency 'httpclient', '~> 2.7'
|
spec.add_dependency 'httpclient', '~> 2.7'
|
||||||
|
|
||||||
spec.add_development_dependency 'bundler', '> 1.16'
|
spec.add_development_dependency 'bundler', '> 1.16'
|
||||||
spec.add_development_dependency 'rake', '~> 10.0'
|
spec.add_development_dependency 'rake', '~> 13.0'
|
||||||
end
|
end
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user