telegram-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +52 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/telegram/client_adapter.rb +84 -0
- data/lib/telegram/controller.rb +102 -0
- data/lib/telegram/errors/common_error.rb +6 -0
- data/lib/telegram/errors/configuration/token_missing_error.rb +13 -0
- data/lib/telegram/errors/controller/block_not_given_error.rb +13 -0
- data/lib/telegram/errors/routing/bad_route_error.rb +14 -0
- data/lib/telegram/errors/routing/bot_not_found_error.rb +14 -0
- data/lib/telegram/rails/action_dispatcher.rb +121 -0
- data/lib/telegram/rails/railtie.rb +75 -0
- data/lib/telegram/rails/routes_helper.rb +11 -0
- data/lib/telegram/rails/version.rb +5 -0
- data/lib/telegram/rails.rb +8 -0
- data/lib/telegram/utils/keyboard_builder.rb +37 -0
- data/lib/telegram/utils/responder.rb +117 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 32045c7d423551f7c28bf5cb2a2461e70f04cf07
|
4
|
+
data.tar.gz: ae807568c5f7806f718f4177a3bd52b2abb6b6d6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d77da4d52528321a44a3815f188062f5ef935873c010a1afc869013043ad4af2247b6997fce9602e01f441fe89c5bfb9b866c91ffda4a31f49c723a22b1bb8ab
|
7
|
+
data.tar.gz: e773a1c9ab1dd94de058d7fb3e206bfb360c753f689c7fa88428f9987220f66dc2dd636636ebe963155c08876ae9f1398d35e10c23c3eb08e1caf43f6f0de289
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Telegram::Rails
|
2
|
+
|
3
|
+
## Work in progress
|
4
|
+
|
5
|
+
Rails integration for [`telegram-rabbit`](https://github.com/govorov/telegram-rabbit).
|
6
|
+
|
7
|
+
Gives you http-like routes and controllers. Allows you to write such a code:
|
8
|
+
|
9
|
+
```
|
10
|
+
#routes.rb
|
11
|
+
Rails.application.routes.draw do
|
12
|
+
|
13
|
+
telegram 'main/start', to: 'telegram/message#start'
|
14
|
+
telegram 'main/stop', to: 'telegram/message#stop'
|
15
|
+
telegram 'main', to: 'telegram/message'
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
#message_controller.rb
|
20
|
+
class Telegram::MessageController < Telegram::Controller
|
21
|
+
|
22
|
+
def start
|
23
|
+
respond_with 'received /start'
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def stop
|
28
|
+
respond_with 'received /stop'
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def process
|
33
|
+
respond_with 'other commands'
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
```
|
39
|
+
|
40
|
+
## TODO
|
41
|
+
|
42
|
+
* Sessions
|
43
|
+
* Callbacks
|
44
|
+
* `rescue_from`
|
45
|
+
* `respond_to`
|
46
|
+
* ...and so on from vanilla rails controllers
|
47
|
+
* Documentation
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
52
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "telegram/rails"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'telegram/rails/action_dispatcher'
|
2
|
+
|
3
|
+
|
4
|
+
module Telegram
|
5
|
+
class ClientAdapter
|
6
|
+
|
7
|
+
class ApiProxy
|
8
|
+
def initialize adapter
|
9
|
+
@adapter = adapter
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing command, *args
|
13
|
+
puts "call adapter with #{command}"
|
14
|
+
p args
|
15
|
+
@adapter.send_command command, *args
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
attr_accessor :connection
|
21
|
+
attr_accessor :queue_namespace
|
22
|
+
attr_accessor :options
|
23
|
+
attr_accessor :bot_name
|
24
|
+
|
25
|
+
|
26
|
+
def configure
|
27
|
+
yield self
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def start
|
33
|
+
send_queue_name = "#{queue_prefix}.commands"
|
34
|
+
receive_queue_name = "#{queue_prefix}.messages"
|
35
|
+
|
36
|
+
@channel = connection.create_channel
|
37
|
+
@send_queue = @channel.queue send_queue_name
|
38
|
+
@receive_queue = @channel.queue receive_queue_name
|
39
|
+
|
40
|
+
@receive_queue.subscribe do |info,metadata,raw_data|
|
41
|
+
data = Marshal.load(raw_data)
|
42
|
+
@receive_callbacks.each do |callback|
|
43
|
+
callback.call(data)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
@api_proxy = ApiProxy.new(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def on_message_received &block
|
52
|
+
@receive_callbacks ||= []
|
53
|
+
@receive_callbacks << block
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def api
|
58
|
+
@api_proxy
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def send_message payload
|
63
|
+
api.send_message payload
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def send_command command, payload
|
68
|
+
raw_data = Marshal.dump(serialize_command(command,payload))
|
69
|
+
@channel.default_exchange.publish raw_data, routing_key: @send_queue.name
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def serialize_command command, payload
|
76
|
+
{command: command, payload: payload}
|
77
|
+
end
|
78
|
+
|
79
|
+
def queue_prefix
|
80
|
+
"#{queue_namespace}.#{bot_name}"
|
81
|
+
end
|
82
|
+
|
83
|
+
end # ClientAdapter
|
84
|
+
end # Telegram
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'telegram/utils/responder'
|
2
|
+
require 'telegram/utils/keyboard_builder'
|
3
|
+
|
4
|
+
|
5
|
+
module Telegram
|
6
|
+
class Controller
|
7
|
+
|
8
|
+
def bots= adapters
|
9
|
+
@bots = adapters
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def bot_name= name
|
14
|
+
@bot_name = name
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def message= payload
|
19
|
+
@message = payload
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def explicit_response?
|
24
|
+
@explicit_response
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def bot
|
31
|
+
@bots[@bot_name]
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def bots
|
36
|
+
@bots
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def request
|
41
|
+
@message
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def send_message *args
|
46
|
+
bot.api.send_message *args
|
47
|
+
@explicit_response = true
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def default_response
|
52
|
+
{ chat_id: @message.chat.id }
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def respond_with payload
|
57
|
+
response = payload.clone
|
58
|
+
# WIP угадывать тип, посмотреть какие есть типы ответа
|
59
|
+
unless response.is_a? Hash
|
60
|
+
response = {text: response.to_s}
|
61
|
+
end
|
62
|
+
|
63
|
+
# :keyboard => :reply_markup, call :keyboard
|
64
|
+
# :inline_keyboard => :reply_markup, call :inline_keyboard
|
65
|
+
if response.has_key? :keyboard
|
66
|
+
response[:reply_markup] = keyboard(response[:keyboard])
|
67
|
+
response.delete :keyboard
|
68
|
+
end
|
69
|
+
|
70
|
+
if response.has_key? :inline_keyboard
|
71
|
+
response[:reply_markup] = inline_keyboard(response[:inline_keyboard])
|
72
|
+
response.delete :inline_keyboard
|
73
|
+
end
|
74
|
+
|
75
|
+
if response.has_key?(:remove_keyboard) && response[:remove_keyboard]
|
76
|
+
response[:reply_markup] = remove_keyboard
|
77
|
+
response.delete :remove_keyboard
|
78
|
+
end
|
79
|
+
|
80
|
+
send_message default_response.merge(response)
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
keyboard_builder = Telegram::Utils::KeyboardBuilder
|
85
|
+
|
86
|
+
define_method :keyboard do |buttons|
|
87
|
+
keyboard_builder.keyboard buttons
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
define_method :inline_keyboard do |buttons|
|
92
|
+
keyboard_builder.inline_keyboard buttons
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
define_method :remove_keyboard do
|
97
|
+
res = keyboard_builder.remove_keyboard
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
end # Controller
|
102
|
+
end # Telegram
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'telegram/errors/common_error'
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Errors
|
5
|
+
module Configuration
|
6
|
+
class TokenMissingError < Telegram::Errors::CommonError
|
7
|
+
def initialize name
|
8
|
+
super "No token were provided for bot \"#{name}\""
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'telegram/errors/common_error'
|
2
|
+
|
3
|
+
#WIP--
|
4
|
+
module Telegram
|
5
|
+
module Errors
|
6
|
+
module Routing
|
7
|
+
class BotNotFoundError < Telegram::Errors::CommonError
|
8
|
+
def initialize name
|
9
|
+
super "Bot \"#{name}\" was not found"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
|
4
|
+
module Telegram
|
5
|
+
module Rails
|
6
|
+
class ActionDispatcher
|
7
|
+
|
8
|
+
ROUTE_DELIMETER = "/"
|
9
|
+
ENDPOINT_DELIMETER = "#"
|
10
|
+
COMMAND_START_SYMBOL = "/"
|
11
|
+
COMMAND_ARGS_SEPARATOR = /\s+/
|
12
|
+
DEFAULT_ACTION_NAME = :process
|
13
|
+
|
14
|
+
|
15
|
+
def initialize adapters
|
16
|
+
@adapters = adapters
|
17
|
+
@routes = []
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def register_route route_data
|
22
|
+
route = parse_route(route_data)
|
23
|
+
@routes << route
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def dispatch_message bot_name, message
|
28
|
+
adapter = find_adapter_for bot_name
|
29
|
+
return unless adapter
|
30
|
+
|
31
|
+
command, args = extract_command_from message
|
32
|
+
route = find_route_for bot_name, command
|
33
|
+
return unless route
|
34
|
+
|
35
|
+
process_message message, with: route
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def find_adapter_for name
|
42
|
+
@adapters[name]
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def find_route_for bot_name, command
|
47
|
+
@routes.find do |route|
|
48
|
+
route_match? bot_name, command, route
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def route_match? bot_name, command, route
|
54
|
+
bot_name == route[:bot_name] &&
|
55
|
+
(command == route[:command] || route[:command].nil?)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def process_message message, opts
|
60
|
+
route = opts[:with]
|
61
|
+
controller = route[:controller_class].new
|
62
|
+
controller.tap do |c|
|
63
|
+
c.bots = @adapters
|
64
|
+
c.bot_name = route[:bot_name]
|
65
|
+
c.message = message
|
66
|
+
end
|
67
|
+
|
68
|
+
begin
|
69
|
+
# WIP check explicit response...
|
70
|
+
controller.send route[:action_name]
|
71
|
+
rescue StandardError => e
|
72
|
+
puts "RESCUE FROM"
|
73
|
+
puts "RESCUE FROM"
|
74
|
+
puts "RESCUE FROM"
|
75
|
+
puts "RESCUE FROM"
|
76
|
+
#HERE rescue_from!!!
|
77
|
+
raise e
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
#TODO test coverage
|
83
|
+
def parse_route route_data
|
84
|
+
route_string = route_data[:route]
|
85
|
+
options = route_data[:options]
|
86
|
+
|
87
|
+
segments = route_string.split ROUTE_DELIMETER, 2
|
88
|
+
bot_name, command = segments
|
89
|
+
|
90
|
+
bot_name = bot_name.to_sym if bot_name
|
91
|
+
command = command.to_sym if command
|
92
|
+
|
93
|
+
endpoint = options[:to]
|
94
|
+
controller_name, action_name = endpoint.to_s.split ENDPOINT_DELIMETER, 2
|
95
|
+
|
96
|
+
controller_class = "#{controller_name}_controller".classify.constantize
|
97
|
+
action_name = action_name ? action_name.to_sym : DEFAULT_ACTION_NAME
|
98
|
+
|
99
|
+
{
|
100
|
+
bot_name: bot_name,
|
101
|
+
command: command,
|
102
|
+
controller_class: controller_class,
|
103
|
+
action_name: action_name,
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
# get command name from payload
|
109
|
+
def extract_command_from payload
|
110
|
+
command_str = payload.text
|
111
|
+
if command_str && command_str.starts_with?(COMMAND_START_SYMBOL)
|
112
|
+
command_str.slice!(0)
|
113
|
+
command,*args = command_str.split COMMAND_ARGS_SEPARATOR
|
114
|
+
return [command.to_sym, args] if command && command.length
|
115
|
+
end
|
116
|
+
return [nil,nil]
|
117
|
+
end
|
118
|
+
|
119
|
+
end # ActionDispatcher
|
120
|
+
end # Rails
|
121
|
+
end # Telegram
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'bunny'
|
2
|
+
require 'active_support/notifications'
|
3
|
+
|
4
|
+
require 'telegram/rails/routes_helper'
|
5
|
+
require 'telegram/client_adapter'
|
6
|
+
|
7
|
+
require 'telegram/errors/configuration/token_missing_error'
|
8
|
+
require 'telegram/errors/routing/bot_not_found_error'
|
9
|
+
require 'telegram/controller'
|
10
|
+
require 'telegram/bot'
|
11
|
+
|
12
|
+
|
13
|
+
module Telegram
|
14
|
+
module Rails
|
15
|
+
class Railtie < ::Rails::Railtie
|
16
|
+
|
17
|
+
# add config section
|
18
|
+
config.telegram = ActiveSupport::OrderedOptions.new
|
19
|
+
notifications = ActiveSupport::Notifications
|
20
|
+
|
21
|
+
#add route helper
|
22
|
+
config.before_initialize do
|
23
|
+
::ActionDispatch::Routing::Mapper.send(:include, Telegram::Rails::RoutesHelper)
|
24
|
+
end
|
25
|
+
|
26
|
+
initializer "telegram_rails.run_client_adapters" do |app|
|
27
|
+
|
28
|
+
@options ||= default_options.merge(app.config.telegram)
|
29
|
+
@adapters = {}
|
30
|
+
dispatcher = Telegram::Rails::ActionDispatcher.new @adapters
|
31
|
+
|
32
|
+
@connection = Bunny.new(get_option :bunny).start
|
33
|
+
at_exit { @connection.close }
|
34
|
+
|
35
|
+
#create adapter for each bot
|
36
|
+
get_option(:bots).each do |pair; name,options|
|
37
|
+
name, options = pair
|
38
|
+
|
39
|
+
adapter = Telegram::ClientAdapter.new.configure do |c|
|
40
|
+
c.bot_name = name
|
41
|
+
c.options = options
|
42
|
+
c.connection = @connection
|
43
|
+
c.queue_namespace = get_option(:queue_namespace)
|
44
|
+
end
|
45
|
+
|
46
|
+
adapter.on_message_received do |message|
|
47
|
+
#TODO logging
|
48
|
+
dispatcher.dispatch_message name, message
|
49
|
+
end
|
50
|
+
|
51
|
+
@adapters[name] = adapter
|
52
|
+
adapter.start
|
53
|
+
end
|
54
|
+
|
55
|
+
notifications.subscribe "telegram.register_route" do |name, started, finished, id, data|
|
56
|
+
dispatcher.register_route data
|
57
|
+
end
|
58
|
+
|
59
|
+
end # initializer
|
60
|
+
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def get_option *args
|
65
|
+
(@options || {}).dig *args
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def default_options
|
70
|
+
Hash.new
|
71
|
+
end
|
72
|
+
|
73
|
+
end # Railtie
|
74
|
+
end # Rails
|
75
|
+
end # Telegram
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'telegram/bot'
|
2
|
+
|
3
|
+
module Telegram
|
4
|
+
module Utils
|
5
|
+
module KeyboardBuilder
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def keyboard buttons
|
9
|
+
btnClass = Telegram::Bot::Types::KeyboardButton
|
10
|
+
kbClass = Telegram::Bot::Types::ReplyKeyboardMarkup
|
11
|
+
build :keyboard, buttons, btnClass, kbClass
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def inline_keyboard buttons
|
16
|
+
btnClass = Telegram::Bot::Types::InlineKeyboardButton
|
17
|
+
kbClass = Telegram::Bot::Types::InlineKeyboardMarkup
|
18
|
+
build :keyboard, buttons, btnClass, kbClass
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def remove_keyboard
|
23
|
+
Telegram::Bot::Types::ReplyKeyboardRemove.new(remove_keyboard: true)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
private
|
28
|
+
def build key, buttons, btnClass, kbClass
|
29
|
+
keyboard = buttons.map do |button|
|
30
|
+
btnClass.new button
|
31
|
+
end
|
32
|
+
kbClass.new({ key => keyboard })
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end # Utils
|
37
|
+
end # Telegram
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
require 'telegram/errors/controller/block_not_given_error'
|
3
|
+
#WIP-- `ag byebug`
|
4
|
+
require 'byebug'
|
5
|
+
|
6
|
+
#WIP move to ...::Controller, продумать
|
7
|
+
|
8
|
+
module Telegram
|
9
|
+
module Utils
|
10
|
+
class Responder
|
11
|
+
|
12
|
+
class << self
|
13
|
+
private
|
14
|
+
def register_type type
|
15
|
+
instance_eval do
|
16
|
+
define_method type do |&block|
|
17
|
+
set_respond_to type, &block
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
RESPONSE_TYPES = [
|
25
|
+
:from,
|
26
|
+
:date,
|
27
|
+
:chat,
|
28
|
+
:forward_from,
|
29
|
+
:forward_from_chat,
|
30
|
+
:forward_from_message_id,
|
31
|
+
:forward_date,
|
32
|
+
:reply_to_message,
|
33
|
+
:edit_date,
|
34
|
+
:text,
|
35
|
+
:entities,
|
36
|
+
:audio,
|
37
|
+
:document,
|
38
|
+
:game,
|
39
|
+
:photo,
|
40
|
+
:sticker,
|
41
|
+
:video,
|
42
|
+
:voice,
|
43
|
+
:caption,
|
44
|
+
:contact,
|
45
|
+
:location,
|
46
|
+
:venue,
|
47
|
+
:new_chat_member,
|
48
|
+
:left_chat_member,
|
49
|
+
:new_chat_title,
|
50
|
+
:new_chat_photo,
|
51
|
+
:delete_chat_photo,
|
52
|
+
:group_chat_created,
|
53
|
+
:supergroup_chat_created,
|
54
|
+
:channel_chat_created,
|
55
|
+
:migrate_to_chat_id,
|
56
|
+
:migrate_from_chat_id,
|
57
|
+
:pinned_message,
|
58
|
+
# Telegram::Bot::Types::ReplyKeyboardMarkup,
|
59
|
+
# Telegram::Bot::Types::ReplyKeyboardRemove,
|
60
|
+
# Telegram::Bot::Types::ForceReply,
|
61
|
+
# Telegram::Bot::Types::InlineKeyboardMarkup
|
62
|
+
]
|
63
|
+
|
64
|
+
|
65
|
+
RESPONSE_TYPES.each do |type_const|
|
66
|
+
register_type type_const.to_s.underscore.to_sym
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def current_message= message
|
71
|
+
@message = message
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def current_message
|
76
|
+
@message
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def clear_current_message
|
81
|
+
@message = nil
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def any &block
|
86
|
+
set_respond_to :any, &block
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
#TEST
|
91
|
+
#match first not nil attribute
|
92
|
+
def set_respond_to type, &block
|
93
|
+
@stack ||= []
|
94
|
+
@stack.push type
|
95
|
+
if block && @block.nil?
|
96
|
+
# check if message matches stack
|
97
|
+
has_attr = @stack.find do |format|
|
98
|
+
format == :any || !current_message.send(format).nil?
|
99
|
+
end
|
100
|
+
|
101
|
+
if has_attr
|
102
|
+
@block = block
|
103
|
+
end
|
104
|
+
|
105
|
+
@stack.clear
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
def block
|
112
|
+
@block or raise Telegram::Errors::Controller::BlockNotGivenError
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: telegram-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stanislav E. Govorov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: telegram-bot-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: wisper
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bunny
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.14'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.14'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- govorov.st@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- README.md
|
119
|
+
- bin/console
|
120
|
+
- bin/setup
|
121
|
+
- lib/telegram/client_adapter.rb
|
122
|
+
- lib/telegram/controller.rb
|
123
|
+
- lib/telegram/errors/common_error.rb
|
124
|
+
- lib/telegram/errors/configuration/token_missing_error.rb
|
125
|
+
- lib/telegram/errors/controller/block_not_given_error.rb
|
126
|
+
- lib/telegram/errors/routing/bad_route_error.rb
|
127
|
+
- lib/telegram/errors/routing/bot_not_found_error.rb
|
128
|
+
- lib/telegram/rails.rb
|
129
|
+
- lib/telegram/rails/action_dispatcher.rb
|
130
|
+
- lib/telegram/rails/railtie.rb
|
131
|
+
- lib/telegram/rails/routes_helper.rb
|
132
|
+
- lib/telegram/rails/version.rb
|
133
|
+
- lib/telegram/utils/keyboard_builder.rb
|
134
|
+
- lib/telegram/utils/responder.rb
|
135
|
+
homepage:
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 2.6.11
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: Rails integration for telegram-bot-rabbit
|
159
|
+
test_files: []
|