telegram_bot_ruby 0.1.6 → 0.1.7
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/README.md +135 -1
- data/lib/telegram_bot/date.rb +5 -4
- data/lib/telegram_bot/document.rb +1 -1
- data/lib/telegram_bot/request_methods.rb +2 -3
- data/lib/telegram_bot/shorthand_methods.rb +4 -4
- data/lib/telegram_bot/sticker.rb +1 -1
- data/lib/telegram_bot/version.rb +1 -1
- data/lib/telegram_bot/video.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: 5a4984bb585eb4f2590080ba9c3cd2ba4f7bca2d
|
4
|
+
data.tar.gz: 0e27c1c8b74e0d43b1a0e38e13bb2303093fca3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7d61fc109eee58ec9f89eebd98a33a00917dc4b5b69e8d0c3c3116b8fb743c6548657693cd44e2125bb6cdbfd457f2103ce2d52a26612b8fd1ab1d3716e5b45
|
7
|
+
data.tar.gz: abde2a9ea7307cd81da65f97391eeec4b0256c665abcc8b0a7b332677825e80e1c492bf0da86728352334f5ae1b97eee3721b30af804296fcfa40f42a706a321
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ Or install it yourself as:
|
|
23
23
|
$ gem install telegram_bot_ruby
|
24
24
|
```
|
25
25
|
|
26
|
-
##
|
26
|
+
## Quick start
|
27
27
|
|
28
28
|
### Set up client
|
29
29
|
|
@@ -68,9 +68,143 @@ end
|
|
68
68
|
|
69
69
|
```ruby
|
70
70
|
# register service at telegram or start long polling
|
71
|
+
trap(:INT) {
|
72
|
+
bot.stop!
|
73
|
+
}
|
71
74
|
bot.start!
|
72
75
|
```
|
73
76
|
|
77
|
+
## Documentation
|
78
|
+
|
79
|
+
### Matchers
|
80
|
+
|
81
|
+
**anything/fallback matcher**
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
on :anything
|
85
|
+
on :fallback
|
86
|
+
```
|
87
|
+
|
88
|
+
**text matcher**
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
# match when message.type == :text
|
92
|
+
on :text do |txt|
|
93
|
+
end
|
94
|
+
|
95
|
+
# arguments are given by `MatchData#to_a`
|
96
|
+
on :text, /reply me with (.*)/ do |matched_text, reply_txt|
|
97
|
+
send_message reply_txt
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
**command matcher**
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
on :command, :ping do
|
105
|
+
reply 'pong'
|
106
|
+
end
|
107
|
+
|
108
|
+
# handling requests like `/plus 1 2`
|
109
|
+
on :command :plus do |*args|
|
110
|
+
reply args.map(&:to_i).sum.to_s
|
111
|
+
end
|
112
|
+
|
113
|
+
# or handle all commands
|
114
|
+
on :command do |cmd, *args|
|
115
|
+
case cmd
|
116
|
+
when 'echo'
|
117
|
+
reply args.join(' ')
|
118
|
+
when 'rand'
|
119
|
+
reply rand.to_s
|
120
|
+
else
|
121
|
+
reply "unknown command #{cmd}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
### Telegram Types
|
127
|
+
|
128
|
+
Check the classes that include this module:
|
129
|
+
|
130
|
+
http://www.rubydoc.info/gems/telegram_bot_ruby/TelegramBot/AutoFromMethods
|
131
|
+
|
132
|
+
### Bot methods
|
133
|
+
|
134
|
+
```
|
135
|
+
# msg: message object, or message id
|
136
|
+
# to: chat/user object or chat/user id
|
137
|
+
TelegramBot#forward_message(msg, to, from = nil)
|
138
|
+
|
139
|
+
TelegramBot#get_me => User
|
140
|
+
|
141
|
+
CHAT_ACTIONS = [
|
142
|
+
:typing,
|
143
|
+
:upload_photo,
|
144
|
+
:record_video,
|
145
|
+
:update_video,
|
146
|
+
:record_audio,
|
147
|
+
:upload_audio,
|
148
|
+
:upload_document,
|
149
|
+
:find_location
|
150
|
+
]
|
151
|
+
# chat: {chat,user} {object,id}
|
152
|
+
# action: CHAT_ACTIONS.sample
|
153
|
+
TelegramBot#send_chat_action(chat, action)
|
154
|
+
|
155
|
+
|
156
|
+
# chat: {chat,user} {object,id}
|
157
|
+
# text: text content of the message
|
158
|
+
# disable_web_page_preview: see Telegram doc
|
159
|
+
# reply_to: message object or id
|
160
|
+
# reply_markup: a keyboard markup, see example below
|
161
|
+
send_message(chat,
|
162
|
+
text,
|
163
|
+
disable_web_page_preview: nil,
|
164
|
+
reply_to: nil,
|
165
|
+
reply_markup: nil)
|
166
|
+
|
167
|
+
|
168
|
+
# example keyboard markup
|
169
|
+
markup = {
|
170
|
+
keyboard: [
|
171
|
+
["1", "2"],
|
172
|
+
["3", "4", "5"],
|
173
|
+
["6"]
|
174
|
+
],
|
175
|
+
selective: false
|
176
|
+
}
|
177
|
+
```
|
178
|
+
|
179
|
+
### Shorthand methods
|
180
|
+
|
181
|
+
shorthand methods can be used within the handler block, with the
|
182
|
+
received message as context. [rubydoc.info](http://www.rubydoc.info/gems/telegram_bot_ruby/TelegramBot/ShorthandMethods)
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
reply(text, *args)
|
186
|
+
send_message(text, *args)
|
187
|
+
forward_message(to, *args)
|
188
|
+
send_chat_action(action, *args)
|
189
|
+
```
|
190
|
+
|
191
|
+
### Handler context variables/methods
|
192
|
+
|
193
|
+
Other than the shorthand above, within the handler block, these
|
194
|
+
contextual variable are accessible:
|
195
|
+
|
196
|
+
```
|
197
|
+
bot # the current TelegramBot instance
|
198
|
+
bot.history # request histories :: [Message]
|
199
|
+
bot.start! # start polling
|
200
|
+
bot.stop! # quit the bot
|
201
|
+
|
202
|
+
message # the message just received
|
203
|
+
message.<attr> # message attributes
|
204
|
+
matcher # current matcher object
|
205
|
+
```
|
206
|
+
|
207
|
+
|
74
208
|
## Contributing
|
75
209
|
|
76
210
|
Bug reports and pull requests are welcome on GitHub at https://github.com/shouya/telegram-bot.
|
data/lib/telegram_bot/date.rb
CHANGED
@@ -7,9 +7,6 @@ class TelegramBot::Date
|
|
7
7
|
def self.members
|
8
8
|
[]
|
9
9
|
end
|
10
|
-
def members
|
11
|
-
self.class.members
|
12
|
-
end
|
13
10
|
|
14
11
|
def self.from(date)
|
15
12
|
case date
|
@@ -29,8 +26,12 @@ class TelegramBot::Date
|
|
29
26
|
|
30
27
|
attr_accessor :datetime
|
31
28
|
|
29
|
+
def members
|
30
|
+
self.class.members
|
31
|
+
end
|
32
|
+
|
32
33
|
def initialize(datetime)
|
33
|
-
@
|
34
|
+
@datetime = datetime
|
34
35
|
end
|
35
36
|
|
36
37
|
def method_missing(sym, *args, &blk)
|
@@ -25,9 +25,8 @@ class TelegramBot
|
|
25
25
|
chat_id: Chat.from(chat).id,
|
26
26
|
text: text,
|
27
27
|
disable_web_page_preview: disable_web_page_preview,
|
28
|
-
reply_to_message_id: reply_to && reply_to.id
|
29
|
-
|
30
|
-
# reply_markup: reply_markup
|
28
|
+
reply_to_message_id: reply_to && reply_to.id,
|
29
|
+
reply_markup: reply_markup ? reply_markup.to_json : nil
|
31
30
|
}.reject {|_,v| v.nil?}
|
32
31
|
|
33
32
|
Message.from(request(:send_message, params))
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module TelegramBot::ShorthandMethods
|
2
|
-
def send_message(text, *args, to: message.chat)
|
3
|
-
bot.send_message(to, text, *args)
|
2
|
+
def send_message(text, *args, to: message.chat, **opts)
|
3
|
+
bot.send_message(to, text, *args, **opts)
|
4
4
|
end
|
5
5
|
|
6
|
-
def reply(text, *args, to: message.chat)
|
7
|
-
bot.send_message(to, text, *args, reply_to: message)
|
6
|
+
def reply(text, *args, to: message.chat, **opts)
|
7
|
+
bot.send_message(to, text, *args, reply_to: message, **opts)
|
8
8
|
end
|
9
9
|
|
10
10
|
def forward_message(to)
|
data/lib/telegram_bot/sticker.rb
CHANGED
data/lib/telegram_bot/version.rb
CHANGED
data/lib/telegram_bot/video.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.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shou Ya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|