action_bot 0.1.13 → 0.1.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c80a7fb7e4d29b94f33aca746630229c9802b86212490c908b3b6c403e938c40
4
- data.tar.gz: 6fdaf3c1991938185a500f3433768dc9db18de2a59e5eda2f7f139ed70f70932
3
+ metadata.gz: 6cd02a083032cf1a30af35a8ce7bcce03388aa458c3a5d287e64da7180164806
4
+ data.tar.gz: c06bf08cf2a2309b25bfc447f61e452e22112c02a9d425ddb470d2e5458e444d
5
5
  SHA512:
6
- metadata.gz: d5e52f093386631b20beb22bfee5e6267374d3e4b2bd7a61be917577f8b11bd833f959870f06487a9f92720ed03a6df7d9ce3914f8ca397f3992dfd780ac7c9c
7
- data.tar.gz: 89e4b2e0dd6278c394c49fedb7e53e4815334364a2552a6c78036c2eb0b1c1fbf5a5ed4d37c49907aff632bc2c993ff737a92db4a19c9b4b624b1c19b23634e1
6
+ metadata.gz: 58dbd5b967385bf66d0b4d38e28f14af9c82e0132ddd1460bccbe59375f7306581d2eae577804d82db418638c5a1115bb3cd7bc870270f53de7bd96e8b6b226c
7
+ data.tar.gz: f726602ffa3fc327c238725bf93cc46d2bda35f9ba23803afec5b5477b1a0ee4c7453ee7764d53d4dc8752257540a4424b8ee0c70770f96264323f538db70dd6
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ import "./lib/tasks/bot_scaffold.rake"
@@ -0,0 +1,6 @@
1
+ spec = Gem::Specification.find_by_name 'action_bot'
2
+
3
+ desc 'Generate files for the bot'
4
+ task :bot_scaffold do
5
+ FileUtils.cp_r "#{spec.gem_dir}/scaffolds/.", "#{Dir.pwd}"
6
+ end
@@ -0,0 +1,7 @@
1
+ require 'action_bot'
2
+
3
+ require_relative '../config/configuration'
4
+ require_relative '../bots/example_long_polling_bot'
5
+
6
+
7
+ ExampleLongPollingBot.call
@@ -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
+ action 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,2 @@
1
+ en:
2
+ hello_world: "Hello world!"
@@ -0,0 +1 @@
1
+ telegram_bot_token: your-tg-bot-token
@@ -0,0 +1,2 @@
1
+ class BotsController < ActionBot::Controller
2
+ end
@@ -0,0 +1,5 @@
1
+ class HelloController
2
+ def world
3
+ notify(params[:tg_chat_id], t('hello_world'))
4
+ end
5
+ end
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.13
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Barseek
@@ -115,6 +115,7 @@ extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
117
  - Gemfile
118
+ - Rakefile
118
119
  - lib/action_bot.rb
119
120
  - lib/action_bot/base.rb
120
121
  - lib/action_bot/controller.rb
@@ -124,6 +125,17 @@ files:
124
125
  - lib/configuration/configurators/bot_configurator.rb
125
126
  - lib/configuration/configurators/db_configurator.rb
126
127
  - lib/configuration/configurators/i18n_configurator.rb
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
127
139
  homepage: https://rubygems.org/gems/hola
128
140
  licenses:
129
141
  - MIT