action_bot 0.1.14 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/configuration/configurators/app_configurator.rb +1 -1
- data/lib/tasks/bot_scaffold.rake +3 -1
- data/scaffolds/bin/example_long_polling_bot_runner.rb +7 -0
- data/scaffolds/bin/example_webhook_bot_runner.rb +20 -0
- data/scaffolds/bots/example_long_polling_bot.rb +30 -0
- data/scaffolds/bots/example_webhook_bot.rb +21 -0
- data/scaffolds/config/configuration.rb +20 -0
- data/scaffolds/config/secrets/database.yml +1 -0
- data/scaffolds/config/secrets/locales.yml +2 -0
- data/scaffolds/config/secrets/token.yml +1 -0
- data/scaffolds/controllers/bots_controller.rb +2 -0
- data/scaffolds/controllers/hello_controller.rb +5 -0
- metadata +11 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f267e3093741e98e9812f5a8e43871e3fe03a0634d58972cb86dd5cc3834230b
|
4
|
+
data.tar.gz: 01767005c9771cf1395453ec27ae3f7cd6525a8db0a5413668bf3322e717de97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b403d696bc7d517a88137f65ebde2c11207eadc0b38296a1b35b3f4629a87134751806c75e2421f1df6df21b26c4399fef5f40b030e4f5cfbef5d6d7d273973
|
7
|
+
data.tar.gz: fc9f146bbec3739c4c7f7967a797d50722e45acefca89dc73e6763f9ccf23ceaae41b86e5f0224a071190e32eb3f5d8fd04316f1af2ee0b7354214ed11429872
|
data/lib/tasks/bot_scaffold.rake
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'action_bot'
|
3
|
+
|
4
|
+
require_relative '../config/configuration'
|
5
|
+
require_relative '../bots/example_webhook_bot'
|
6
|
+
use Rack::Logger
|
7
|
+
|
8
|
+
helpers do
|
9
|
+
def logger
|
10
|
+
request.logger
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Telegram requires GET endpoint to setup a webhook
|
15
|
+
get '/webhook' do
|
16
|
+
end
|
17
|
+
|
18
|
+
post '/webhook' do
|
19
|
+
# Do stuff with request here
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class ExampleLongPollingBot < ActionBot::Base
|
2
|
+
def call
|
3
|
+
bot_runner.run do |bot|
|
4
|
+
ActionBot::Base.configure do |config|
|
5
|
+
config.bot = bot
|
6
|
+
end
|
7
|
+
|
8
|
+
bot.listen do |message|
|
9
|
+
@message = message
|
10
|
+
run
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.call
|
16
|
+
new.call
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
on @message == 'hello_world', hello: :world, params: {
|
21
|
+
tg_chat_id: tg_chat_id
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def tg_chat_id
|
28
|
+
@message.chat.id
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class ExampleWebhookBot < ActionBot::Base
|
2
|
+
def initialize
|
3
|
+
@api = Telegram::Bot::Api.new(AppConfigurator.config.token)
|
4
|
+
ActionBot::Base.configure do |config|
|
5
|
+
config.api = @api
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def run(message)
|
10
|
+
@message = message
|
11
|
+
|
12
|
+
return unless message_legal?
|
13
|
+
catch(:done) do
|
14
|
+
on message == 'hello_world', hello: :world
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def message_legal?
|
19
|
+
@message.respond_to?(:text) && @message.text
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
AppConfigurator.configure do |config|
|
2
|
+
# Configure bot
|
3
|
+
config.token = begin
|
4
|
+
YAML::load(IO.read('config/secrets/token.yml'))['telegram_bot_token']
|
5
|
+
rescue Errno::ENOENT
|
6
|
+
ENV["TOKEN"]
|
7
|
+
end
|
8
|
+
|
9
|
+
# Configure database
|
10
|
+
# config.db_url = begin
|
11
|
+
# YAML::load(IO.read('config/secrets/database.yml'))["database_url"]
|
12
|
+
# rescue Errno::ENOENT
|
13
|
+
# ENV["DATABASE_URL"]
|
14
|
+
# end
|
15
|
+
|
16
|
+
# Configure i18n
|
17
|
+
config.i18n_locale = :en
|
18
|
+
config.i18n_load_path = Dir['config/secrets/locales.yml']
|
19
|
+
config.i18n_available_locales = %i[en]
|
20
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
database_url: postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]
|
@@ -0,0 +1 @@
|
|
1
|
+
telegram_bot_token: your-tg-bot-token
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Barseek
|
@@ -126,6 +126,16 @@ files:
|
|
126
126
|
- lib/configuration/configurators/db_configurator.rb
|
127
127
|
- lib/configuration/configurators/i18n_configurator.rb
|
128
128
|
- lib/tasks/bot_scaffold.rake
|
129
|
+
- scaffolds/bin/example_long_polling_bot_runner.rb
|
130
|
+
- scaffolds/bin/example_webhook_bot_runner.rb
|
131
|
+
- scaffolds/bots/example_long_polling_bot.rb
|
132
|
+
- scaffolds/bots/example_webhook_bot.rb
|
133
|
+
- scaffolds/config/configuration.rb
|
134
|
+
- scaffolds/config/secrets/database.yml
|
135
|
+
- scaffolds/config/secrets/locales.yml
|
136
|
+
- scaffolds/config/secrets/token.yml
|
137
|
+
- scaffolds/controllers/bots_controller.rb
|
138
|
+
- scaffolds/controllers/hello_controller.rb
|
129
139
|
homepage: https://rubygems.org/gems/hola
|
130
140
|
licenses:
|
131
141
|
- MIT
|