ya_telegram_bot 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/ya_telegram_bot/base.rb +32 -0
- data/lib/ya_telegram_bot/exceptions.rb +6 -5
- data/lib/ya_telegram_bot/telegram_api/chat.rb +13 -1
- data/lib/ya_telegram_bot/telegram_api/message.rb +2 -0
- data/lib/ya_telegram_bot/telegram_api/user.rb +12 -0
- data/lib/ya_telegram_bot/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 824c8bc77b35bdf7d81bc9a111e2f893d8a03349
|
4
|
+
data.tar.gz: c852921184c91322dbbf2828e64f70a639913bbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37e3bc364b16c3516cb84d5a68ab208a56a2ab290143bb4a43a7f484d236a428a71563419a8c17583572f6931ae898f128c306b61bbcfe8f7640b5983dfab834
|
7
|
+
data.tar.gz: 8e214248e540cf8ec074ceea7252b1320b009bf8f8d12000fafd8efc692729dbfb2107cc5f279e77ffe0714f4e3c52d2a1753e44ac96ea6bd5bef7ee78e1bc82
|
data/README.md
CHANGED
@@ -2,10 +2,9 @@
|
|
2
2
|
|
3
3
|
**IN DEV**
|
4
4
|
|
5
|
-
## What's new **0.
|
5
|
+
## What's new **0.4.0**
|
6
6
|
|
7
|
-
*
|
8
|
-
* Class `YATelegramBot::TelegramAPI::Chat`.
|
7
|
+
* `#send_photo` method on `Base`, `User`, `Chat`
|
9
8
|
|
10
9
|
## Usage
|
11
10
|
|
@@ -43,6 +42,9 @@ user.send_text text: '*hey hey!*',
|
|
43
42
|
chat = Bot.updates[0].chat
|
44
43
|
chat.send_text text: "Hi, #{chat.type == :private ? 'dude' : 'all'}!"
|
45
44
|
|
45
|
+
# send photo
|
46
|
+
user.send_photo file: File.new('my_awesome_photo.png'), caption: 'awesome photo'
|
47
|
+
|
46
48
|
```
|
47
49
|
|
48
50
|
## Contributing
|
data/lib/ya_telegram_bot/base.rb
CHANGED
@@ -53,6 +53,24 @@ module YATelegramBot
|
|
53
53
|
response['ok'] && Message.new(response['result'], self)
|
54
54
|
end
|
55
55
|
|
56
|
+
#
|
57
|
+
# send photo message to user.
|
58
|
+
#
|
59
|
+
# required params:
|
60
|
+
# * :chat [Fixnum] id of chat
|
61
|
+
# * :file [File] your photo
|
62
|
+
#
|
63
|
+
# additional params:
|
64
|
+
# * :caption [String] caption for your photo
|
65
|
+
# * :reply_to [Fixnum] id of message you reply
|
66
|
+
#
|
67
|
+
def send_photo(params = {})
|
68
|
+
response = send_api_request 'sendPhoto',
|
69
|
+
params_for_sending_photo(params)
|
70
|
+
|
71
|
+
response['ok'] && Message.new(response['result'], self)
|
72
|
+
end
|
73
|
+
|
56
74
|
private
|
57
75
|
|
58
76
|
def params_for_sending_text(params)
|
@@ -68,8 +86,22 @@ module YATelegramBot
|
|
68
86
|
result
|
69
87
|
end
|
70
88
|
|
89
|
+
def params_for_sending_photo(params)
|
90
|
+
fail NoChatSpecified unless params[:chat]
|
91
|
+
fail NoFileSpecified unless params[:file] && params[:file].is_a?(File)
|
92
|
+
|
93
|
+
result = { chat_id: params[:chat],
|
94
|
+
photo: params[:file] }
|
95
|
+
|
96
|
+
result[:caption] = params[:caption] if params[:caption]
|
97
|
+
result[:reply_to_message_id] = params[:reply_to].to_i if params[:reply_to]
|
98
|
+
|
99
|
+
result
|
100
|
+
end
|
101
|
+
|
71
102
|
def send_api_request(method, params = {})
|
72
103
|
fail NoTokenSpecified unless defined?(@token)
|
104
|
+
|
73
105
|
@telegram_api_url = 'https://api.telegram.org' unless defined? @telegram_api_url
|
74
106
|
JSON.parse RestClient.post "#{@telegram_api_url}/#{@api_request_prefix}/#{method}",
|
75
107
|
params
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module YATelegramBot
|
2
|
-
class NoTokenSpecified; end
|
3
|
-
class
|
4
|
-
class
|
5
|
-
class
|
6
|
-
class
|
2
|
+
class NoTokenSpecified < StandardError; end
|
3
|
+
class NoFileSpecified < StandardError; end
|
4
|
+
class ResponseIsNotOk < StandardError; end
|
5
|
+
class NoChatSpecified < StandardError; end
|
6
|
+
class NoMessageSpecified < StandardError; end
|
7
|
+
class InitWithoutBot < StandardError; end
|
7
8
|
end
|
@@ -27,7 +27,7 @@ module YATelegramBot
|
|
27
27
|
end
|
28
28
|
|
29
29
|
#
|
30
|
-
# uses bot to send text to this
|
30
|
+
# uses bot to send text to this chat.
|
31
31
|
#
|
32
32
|
# @param params [Hash] params for Base#send_text. This method will only set :chat to self[:id]
|
33
33
|
#
|
@@ -37,6 +37,18 @@ module YATelegramBot
|
|
37
37
|
params[:chat] = id
|
38
38
|
@bot.send_text params
|
39
39
|
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# uses bot to send photo to this chat.
|
43
|
+
#
|
44
|
+
# @param params [Hash] params for Base#send_photo. This method will only set :chat to self[:id]
|
45
|
+
#
|
46
|
+
def send_photo(params = {})
|
47
|
+
fail InitWithoutBot unless @bot
|
48
|
+
|
49
|
+
params[:chat] = id
|
50
|
+
@bot.send_photo params
|
51
|
+
end
|
40
52
|
end
|
41
53
|
end
|
42
54
|
end
|
@@ -49,6 +49,8 @@ module YATelegramBot
|
|
49
49
|
# * :text [String]
|
50
50
|
# * :as_plain_message [Boolean] default: true. If it's true, method won't set :reply_to parameter
|
51
51
|
#
|
52
|
+
# TODO: what about files?
|
53
|
+
#
|
52
54
|
# @example message.reply(text: 'Hi, *friend*!', markdown: true)
|
53
55
|
#
|
54
56
|
def reply(params = {})
|
@@ -35,6 +35,18 @@ module YATelegramBot
|
|
35
35
|
params[:chat] = id
|
36
36
|
@bot.send_text params
|
37
37
|
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# uses bot to send photo to this user.
|
41
|
+
#
|
42
|
+
# @param params [Hash] params for Base#send_photo. This method will only set :chat to self[:id]
|
43
|
+
#
|
44
|
+
def send_photo(params = {})
|
45
|
+
fail InitWithoutBot unless @bot
|
46
|
+
|
47
|
+
params[:chat] = id
|
48
|
+
@bot.send_photo params
|
49
|
+
end
|
38
50
|
end
|
39
51
|
end
|
40
52
|
end
|