telegram-bot 0.14.0 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a35f4302d428cf24b66fa6122bcb5852b8680b85259bd2dd070a6a8e9aff5b74
4
- data.tar.gz: 53fa7c7a14b637cbcae403b87786e93c2b685fa2461cbef9edd9e68c869f9206
3
+ metadata.gz: e6d77239250dfe0b0929e91f8bb625282ba34d34e242a5a138e37d51b14281e8
4
+ data.tar.gz: e2471ee47e80f2b648d078cad288cad4b5fb15417d7b8dd37ed59cb002b555ca
5
5
  SHA512:
6
- metadata.gz: 7d788d67fcc120b5f4ce0ac6299a3e6ab1015213b1a8710f1f7ea4311deca27381befae700ff708813f1c2d47dfbc9144c6cd901b5a39d8ca4843b405c7b2124
7
- data.tar.gz: '09b511503e001cd6fe9a25072a384ac04b7c0de2a4e728894d3c4c10a5badcbb7872072fb9f3d10cf3c5cbae0edc14d7bb3ee70966ecaa01f09d6c8844edbf01'
6
+ metadata.gz: 1b930c85ae8b1c4fd8dff076243466c4da6e22794828f4a7f4827a677104a1ed4a756abc301f79cbb49333be02442c10c0a53085a35b5f5eddf70df34aff3ae5
7
+ data.tar.gz: c96a953d8d7bf36ecb421a8e985383c9f91c78e540c070d46cfe579c625ad981e81820e034908aafde27d4c2151c513f391c5863d1d5d1617d714325e55f955f
@@ -1,5 +1,9 @@
1
1
  # Unreleased
2
2
 
3
+ - Read config from secrets when credentials don't provide it in rails >= 5.2.
4
+ - Remove botan.io support. It's already shut down, so it should not be a braking change.
5
+ https://github.com/botanio/sdk#this-service-will-be-shut-down-on-25th-may-2018
6
+
3
7
  # 0.14.0
4
8
 
5
9
  - Make integration & controller specs consistent.
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Code Climate](https://codeclimate.com/github/telegram-bot-rb/telegram-bot/badges/gpa.svg)](https://codeclimate.com/github/telegram-bot-rb/telegram-bot)
5
5
  [![Build Status](https://travis-ci.org/telegram-bot-rb/telegram-bot.svg)](https://travis-ci.org/telegram-bot-rb/telegram-bot)
6
6
 
7
- __Breaking changes in v0.14!__ See [upgrading guide](https://github.com/telegram-bot-rb/telegram-bot/wiki/Upgrading-to-0.14).
7
+ __Breaking changes in v0.14!__ See [upgrade guide](https://github.com/telegram-bot-rb/telegram-bot/wiki/Upgrading-to-0.14).
8
8
 
9
9
  Tools for developing Telegram bots. Best used with Rails, but can be used in
10
10
  [standalone app](https://github.com/telegram-bot-rb/telegram-bot/wiki/Not-rails-application).
@@ -19,7 +19,7 @@ Package contains:
19
19
  - Middleware and routes helpers for production env.
20
20
  - Poller with automatic source-reloader for development env.
21
21
  - Rake tasks to update webhook urls.
22
- - __[Async mode](#async-mode)__ for Telegram and/or Botan API.
22
+ - __[Async mode](#async-mode)__.
23
23
  Let the queue adapter handle network errors!
24
24
 
25
25
  Here is sample [telegram_bot_app](https://github.com/telegram-bot-rb/telegram_bot_app)
@@ -55,9 +55,28 @@ require 'telegram/bot'
55
55
 
56
56
  ## Usage
57
57
 
58
+ ### Configuration
59
+
60
+ While clients can be instantiated explicitly, there is `Telegram.bots_config=` method
61
+ to configure app-wide clients, which are accessible via `Telegram.bots`.
62
+ It accepts hash of `{bot_id: bot_config}`, and there is special id `:default`
63
+ which is used for `Telegram.bot`.
64
+
65
+ ```ruby
66
+ Telegram.bots_config = {
67
+ default: DEFAULT_BOT_TOKEN,
68
+ chat: {token: CHAT_BOT_TOKEN, username: 'chatbot'},
69
+ }
70
+
71
+ Telegram.bot.get_updates
72
+ Telegram.bot == Telegram.bots[:default] # true
73
+ Telegram.bots[:chat].send_message(...)
74
+ ```
75
+
58
76
  ### Configuration in Rails app
59
77
 
60
- Add `telegram` section into `secrets.yml`:
78
+ In Rails app `Telegram.bots_config` is read from `secrets.yml` automatically
79
+ from `telegram` section:
61
80
 
62
81
  ```yml
63
82
  development:
@@ -79,6 +98,15 @@ development:
79
98
  username: ChatBot
80
99
  ```
81
100
 
101
+ For Rails >= 5.2 `Telegram::Bot` searches for config first in credentials and then in secrets.
102
+ To use credentials as config store, add telegram section to credentials instead of secrets using
103
+ `rails credentials:edit`. In this case be aware of that [Rails may not load
104
+ credentials in dev environment by default](https://github.com/telegram-bot-rb/telegram-bot/issues/74#issuecomment-384205609).
105
+
106
+ I suggest not using Rails 5.2 credentials because it can lead to leakage of sesitive data
107
+ and it's more difficult to use in multiple environments. See
108
+ [secure_credentials](https://github.com/printercu/secure_credentials) gem for better option.
109
+
82
110
  From now clients will be accessible with `Telegram.bots[:chat]` or `Telegram.bots[:auction]`.
83
111
  Single bot can be accessed with `Telegram.bot` or `Telegram.bots[:default]`.
84
112
 
@@ -206,7 +234,7 @@ def edit_message(type, params = {}); end
206
234
  #### Optional typecasting
207
235
 
208
236
  You can enable typecasting of `update` with `telegram-bot-types` by including
209
- `Telegram::Bot::UpdatesPoller::TypedUpdate`:
237
+ `Telegram::Bot::UpdatesController::TypedUpdate`:
210
238
 
211
239
  ```ruby
212
240
  class Telegram::WebhookController < Telegram::Bot::UpdatesController
@@ -494,48 +522,12 @@ While webhooks-mode is prefered, poller still can be used in production.
494
522
  See [comparison and examples](https://github.com/telegram-bot-rb/telegram-bot/wiki/Deployment)
495
523
  for details.
496
524
 
497
- ### Botan.io metrics
498
-
499
- Initialize with `bot = Telegram::Bot::Client.new(token, botan: 'botan token')`
500
- or just add `botan` key in `secrets.yml`:
501
-
502
- ```yml
503
- telegram:
504
- bot:
505
- token: bot_token
506
- botan: botan_token
507
- ```
508
-
509
- Access to Botan client with `bot.botan`.
510
- Use `bot.botan.track(event, uid, payload)` to track events.
511
-
512
- There are some helpers for controllers in `Telegram::Bot::Botan::ControllerHelpers`:
513
-
514
- ```ruby
515
- class Telegram::WebhookController < Telegram::Bot::UpdatesController
516
- include Telegram::Bot::Botan::ControllerHelpers
517
-
518
- # This will track with event: action_name & data: payload
519
- before_action :botan_track_action
520
-
521
- def smth(*)
522
- # This will track event for current user only when botan is configured.
523
- botan_track :my_event, custom_data
524
-
525
- # or get access directly to botan client:
526
- botan.track(...)
527
- end
528
- end
529
- ```
530
-
531
- There is no stubbing for botan clients, so don't set botan token in tests.
532
-
533
525
  ### Async mode
534
526
 
535
527
  There is built in support for async requests using ActiveJob. Without Rails
536
528
  you can implement your own worker class to handle such requests. This allows:
537
529
 
538
- - Process updates very fast, without waiting for telegram and botan responses.
530
+ - Process updates very fast, without waiting for telegram responses.
539
531
  - Handle and retry network and other errors with queue adapter.
540
532
  - ???
541
533
 
@@ -543,7 +535,7 @@ Instead of performing request instantly client serializes it, pushes to queue,
543
535
  and immediately return control back. The job is then fetched with a worker
544
536
  and real API request is performed. And this all is absolutely transparent for the app.
545
537
 
546
- To enable this mode add `async: true` to bot's and botan's config.
538
+ To enable this mode add `async: true` to bot's config.
547
539
  For more information and custom configuration check out
548
540
  [docs](http://www.rubydoc.info/github/telegram-bot-rb/telegram-bot/master/Telegram/Bot/Async) or
549
541
  [source](https://github.com/telegram-bot-rb/telegram-bot/blob/master/lib/telegram/bot/async.rb).
@@ -22,7 +22,6 @@ module Telegram
22
22
  end
23
23
 
24
24
  autoload :Async, 'telegram/bot/async'
25
- autoload :Botan, 'telegram/bot/botan'
26
25
  autoload :Client, 'telegram/bot/client'
27
26
  autoload :ClientStub, 'telegram/bot/client_stub'
28
27
  autoload :DebugClient, 'telegram/bot/debug_client'
@@ -1,20 +1,15 @@
1
1
  module Telegram
2
2
  module Bot
3
- # Telegram & Botan clients can perform requests in async way with
3
+ # Telegram clients can perform requests in async way with
4
4
  # any job adapter (ActiveJob by default). Using Rails you don't need any
5
5
  # additional configuration. However you may want to enable async requests
6
- # by default with `async: true` in `secrets.yml`. Botan client doesn't inherit
7
- # async setting from client and must be configured separately.
6
+ # by default with `async: true` in `secrets.yml`.
8
7
  #
9
8
  # telegram:
10
9
  # bots:
11
10
  # chat_async:
12
11
  # token: secret
13
12
  # async: true # enable async mode for client
14
- # botan: botan_token # in this way botan will not be async
15
- # botan: # in this way - it's in async mode
16
- # token: botan_token
17
- # async: true
18
13
  #
19
14
  # Without Rails To start using async requests
20
15
  # initialize client with `id` kwarg and make sure the client is
@@ -9,7 +9,6 @@ module Telegram
9
9
  autoload :TypedResponse, 'telegram/bot/client/typed_response'
10
10
  extend Initializers
11
11
  prepend Async
12
- prepend Botan::ClientHelpers
13
12
  include DebugClient
14
13
 
15
14
  require 'telegram/bot/client/api_helper'
@@ -1,5 +1,5 @@
1
1
  # Generated with bin/fetch-telegram-methods
2
- # Bot API 3.5.
2
+ # Bot API 4.1
3
3
 
4
4
  getUpdates
5
5
  setWebhook
@@ -13,6 +13,7 @@ sendPhoto
13
13
  sendAudio
14
14
  sendDocument
15
15
  sendVideo
16
+ sendAnimation
16
17
  sendVoice
17
18
  sendVideoNote
18
19
  sendMediaGroup
@@ -46,6 +47,7 @@ answerCallbackQuery
46
47
 
47
48
  editMessageText
48
49
  editMessageCaption
50
+ editMessageMedia
49
51
  editMessageReplyMarkup
50
52
  deleteMessage
51
53
 
@@ -63,6 +65,8 @@ sendInvoice
63
65
  answerShippingQuery
64
66
  answerPreCheckoutQuery
65
67
 
68
+ setPassportDataErrors
69
+
66
70
  sendGame
67
71
  setGameScore
68
72
  getGameHighScores
@@ -40,11 +40,6 @@ module Telegram
40
40
  end
41
41
  end
42
42
 
43
- # Hash of botan clients made from #bots.
44
- def botans
45
- @botans ||= bots.map { |k, v| [k, v.botan] }.to_h
46
- end
47
-
48
43
  # Returns config for .bots method. By default uses `telegram['bots']` section
49
44
  # from `secrets.yml` merging `telegram['bot']` at `:default` key.
50
45
  #
@@ -53,10 +48,12 @@ module Telegram
53
48
  @bots_config ||=
54
49
  if defined?(Rails.application)
55
50
  app = Rails.application
56
- store = app.respond_to?(:credentials) ? app.credentials : app.secrets
57
- secrets = store.fetch(:telegram, {}).with_indifferent_access
58
- secrets.fetch(:bots, {}).symbolize_keys.tap do |config|
59
- default = secrets[:bot]
51
+ store = app.credentials[:telegram] if app.respond_to?(:credentials)
52
+ store ||= app.secrets[:telegram] if app.respond_to?(:secrets)
53
+ store ||= {}
54
+ store = store.with_indifferent_access
55
+ store.fetch(:bots, {}).symbolize_keys.tap do |config|
56
+ default = store[:bot]
60
57
  config[:default] = default if default
61
58
  end
62
59
  else
@@ -69,7 +66,6 @@ module Telegram
69
66
  @bots = nil
70
67
  @bot = nil
71
68
  @bots_config = nil
72
- @botans = nil
73
69
  end
74
70
  end
75
71
  end
@@ -1,6 +1,6 @@
1
1
  module Telegram
2
2
  module Bot
3
- VERSION = '0.14.0'.freeze
3
+ VERSION = '0.14.1'.freeze
4
4
 
5
5
  def self.gem_version
6
6
  Gem::Version.new VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegram-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Melentiev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-07 00:00:00.000000000 Z
11
+ date: 2018-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -123,9 +123,6 @@ files:
123
123
  - lib/tasks/telegram-bot.rake
124
124
  - lib/telegram/bot.rb
125
125
  - lib/telegram/bot/async.rb
126
- - lib/telegram/bot/botan.rb
127
- - lib/telegram/bot/botan/client_helpers.rb
128
- - lib/telegram/bot/botan/controller_helpers.rb
129
126
  - lib/telegram/bot/client.rb
130
127
  - lib/telegram/bot/client/api_helper.rb
131
128
  - lib/telegram/bot/client/api_methods.txt
@@ -1,53 +0,0 @@
1
- module Telegram
2
- module Bot
3
- class Botan
4
- TRACK_URI = 'https://api.botan.io/track'.freeze
5
-
6
- autoload :ClientHelpers, 'telegram/bot/botan/client_helpers'
7
- autoload :ControllerHelpers, 'telegram/bot/botan/controller_helpers'
8
- class Error < Bot::Error; end
9
-
10
- extend Initializers
11
- prepend Async
12
- include DebugClient
13
-
14
- class << self
15
- def by_id(id)
16
- Telegram.botans[id]
17
- end
18
-
19
- def prepare_async_args(method, uri, query = {}, body = nil)
20
- [method.to_s, uri.to_s, Async.prepare_hash(query), body]
21
- end
22
- end
23
-
24
- attr_reader :client, :token
25
-
26
- def initialize(token = nil, **options)
27
- @client = HTTPClient.new
28
- @token = token || options[:token]
29
- end
30
-
31
- def track(event, uid, payload = {})
32
- request(:post, TRACK_URI, {name: event, uid: uid}, payload.to_json)
33
- end
34
-
35
- def request(method, uri, query = {}, body = nil)
36
- res = http_request(method, uri, query.merge(token: token), body)
37
- status = res.status
38
- return JSON.parse(res.body) if status < 300
39
- result = JSON.parse(res.body) rescue nil # rubocop:disable RescueModifier
40
- err_msg = "#{res.reason}: #{result && result['info'] || '-'}"
41
- raise Error, err_msg
42
- end
43
-
44
- def http_request(method, uri, query, body)
45
- client.request(method, uri, query, body)
46
- end
47
-
48
- def inspect
49
- "#<#{self.class.name}##{object_id}(#{@id})>"
50
- end
51
- end
52
- end
53
- end
@@ -1,15 +0,0 @@
1
- module Telegram
2
- module Bot
3
- class Botan
4
- # Helpers for botan.io metrics.
5
- module ClientHelpers
6
- attr_reader :botan
7
-
8
- def initialize(*, botan: nil, **options)
9
- super
10
- @botan = Botan.wrap(botan, id: id) if botan
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,33 +0,0 @@
1
- module Telegram
2
- module Bot
3
- class Botan
4
- # Helpers for botan.io metrics.
5
- module ControllerHelpers
6
- class MissingFrom < Error; end
7
-
8
- protected
9
-
10
- def botan
11
- @botan ||= bot.try!(:botan)
12
- end
13
-
14
- # Track custom event for user taken from `from` field:
15
- #
16
- # botan_track :my_event, {data: :val}
17
- #
18
- def botan_track(event, data = {})
19
- raise MissingFrom, 'Can not track without user' unless from
20
- botan.try! { |x| x.track(event, from['id'], data) }
21
- end
22
-
23
- # Track current action and payload for current user. Best used with `before_action`:
24
- #
25
- # before_action :botan_track_action
26
- #
27
- def botan_track_action
28
- botan_track(action_name, payload)
29
- end
30
- end
31
- end
32
- end
33
- end