telegram-bot-ruby 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -7
- data/examples/bot.rb +3 -3
- data/lib/telegram/bot/api.rb +10 -1
- data/lib/telegram/bot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c12e00f696103b14d70d141923f8cbe57ab6b902
|
4
|
+
data.tar.gz: 83e391cc4f2a89c8a6eed5e43d8ff5e304b05ca3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2cbfb05f587b9644f58b0a5281a2f5364038b04c6f0bf195135d3e422fb1eb091fbe7e3d20ff4fff3facc02d17da477ccfc6219ac647f873f93a118b4754849
|
7
|
+
data.tar.gz: b912880f81e021d5d96f908d29bd2842614991721a3b4c0ee7f2e386021bc71e7c28d426f4836a68ca1f664db2065035264457f3ab3e44adbd299ccf3e45e13a
|
data/README.md
CHANGED
@@ -38,15 +38,15 @@ Telegram::Bot::Client.run(token) do |bot|
|
|
38
38
|
bot.listen do |message|
|
39
39
|
case message.text
|
40
40
|
when '/start'
|
41
|
-
bot.api.
|
41
|
+
bot.api.send_message(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}")
|
42
42
|
when '/stop'
|
43
|
-
bot.api.
|
43
|
+
bot.api.send_message(chat_id: message.chat.id, text: "Bye, #{message.from.first_name}")
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
```
|
48
48
|
|
49
|
-
Note that `bot.api` object implements [Telegram Bot API methods](https://core.telegram.org/bots/api#available-methods) as is. So you can invoke any method inside the block without any problems.
|
49
|
+
Note that `bot.api` object implements [Telegram Bot API methods](https://core.telegram.org/bots/api#available-methods) as is. So you can invoke any method inside the block without any problems. All methods are available in both *snake_case* and *camelCase* notations.
|
50
50
|
|
51
51
|
Same thing about `message` object - it implements [Message](https://core.telegram.org/bots/api#message) spec, so you always know what to expect from it.
|
52
52
|
|
@@ -63,11 +63,11 @@ bot.listen do |message|
|
|
63
63
|
answers =
|
64
64
|
Telegram::Bot::Types::ReplyKeyboardMarkup
|
65
65
|
.new(keyboard: [%w(A B), %w(C D)], one_time_keyboard: true)
|
66
|
-
bot.api.
|
66
|
+
bot.api.send_message(chat_id: message.chat.id, text: question, reply_markup: answers)
|
67
67
|
when '/stop'
|
68
68
|
# See more: https://core.telegram.org/bots/api#replykeyboardhide
|
69
69
|
kb = Telegram::Bot::Types::ReplyKeyboardHide.new(hide_keyboard: true)
|
70
|
-
bot.api.
|
70
|
+
bot.api.send_message(chat_id: message.chat.id, text: 'Sorry to see you go :(', reply_markup: kb)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
```
|
@@ -80,7 +80,7 @@ Your bot can even upload files ([photos](https://core.telegram.org/bots/api#send
|
|
80
80
|
bot.listen do |message|
|
81
81
|
case message.text
|
82
82
|
when '/photo'
|
83
|
-
bot.api.
|
83
|
+
bot.api.send_photo(chat_id: message.chat.id, photo: File.new('~/Desktop/jennifer.jpg'))
|
84
84
|
end
|
85
85
|
end
|
86
86
|
```
|
@@ -127,7 +127,11 @@ end
|
|
127
127
|
|
128
128
|
## Connection pool size
|
129
129
|
|
130
|
-
Sometimes you need to do some heavy work in another thread and send response from
|
130
|
+
Sometimes you need to do some heavy work in another thread and send response from there. In this case you have to increase your connection pool size (by default it's *1*). You can do it by setting env variable `TELEGRAM_BOT_POOL_SIZE`:
|
131
|
+
|
132
|
+
```shell
|
133
|
+
$ TELEGRAM_BOT_POOL_SIZE=4 ruby bot.rb
|
134
|
+
```
|
131
135
|
|
132
136
|
## Contributing
|
133
137
|
|
data/examples/bot.rb
CHANGED
@@ -7,11 +7,11 @@ Telegram::Bot::Client.run(token) do |bot|
|
|
7
7
|
bot.listen do |message|
|
8
8
|
case message.text
|
9
9
|
when '/start'
|
10
|
-
bot.api.
|
10
|
+
bot.api.send_message(chat_id: message.chat.id, text: "Hello, #{message.from.first_name}!")
|
11
11
|
when '/end'
|
12
|
-
bot.api.
|
12
|
+
bot.api.send_message(chat_id: message.chat.id, text: "Bye, #{message.from.first_name}!")
|
13
13
|
else
|
14
|
-
bot.api.
|
14
|
+
bot.api.send_message(chat_id: message.chat.id, text: "I don't understand you :(")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/telegram/bot/api.rb
CHANGED
@@ -25,7 +25,10 @@ module Telegram
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def method_missing(method_name, *args, &block)
|
28
|
-
|
28
|
+
endpoint = method_name.to_s
|
29
|
+
endpoint = camelize(endpoint) if endpoint.include?('_')
|
30
|
+
|
31
|
+
ENDPOINTS.include?(endpoint) ? call(endpoint, *args) : super
|
29
32
|
end
|
30
33
|
|
31
34
|
def call(endpoint, raw_params = {})
|
@@ -55,6 +58,12 @@ module Telegram
|
|
55
58
|
return value unless REPLY_MARKUP_TYPES.include?(value.class)
|
56
59
|
value.to_h.to_json
|
57
60
|
end
|
61
|
+
|
62
|
+
def camelize(method_name)
|
63
|
+
words = method_name.split('_')
|
64
|
+
words.drop(1).map(&:capitalize!)
|
65
|
+
words.join
|
66
|
+
end
|
58
67
|
end
|
59
68
|
end
|
60
69
|
end
|
data/lib/telegram/bot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: telegram-bot-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Tipugin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httmultiparty
|