telbe 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/telbe/bot.rb +37 -0
- data/lib/telbe/helper.rb +25 -5
- data/lib/telbe/keyboard.rb +22 -0
- data/lib/telbe/location.rb +49 -0
- data/lib/telbe/poll.rb +23 -0
- data/lib/telbe/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c710a1a3419afc4a5068d6b2cdc3291451e7c7e62c309384c8d31021df3c6d74
|
4
|
+
data.tar.gz: 88e578bfccddbf24fab533e920b690945d0ac8a5c6ba5a3d34d42a846846383d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc9b91a5a112548d353bfd80b59e546979f6b98c1d34f429637c2cbec988b1cac72f6742bf04b696985a38da9bb24d271f101cd6bb636b2de99266e3be89b414
|
7
|
+
data.tar.gz: 6a0e69ac415e379108b3b880fddbd80c027387345704a471a5fcc0fcad74c5d848a0f9afa5c9e2db74c810aafaddcd385f00a81f5e3cfaa3c7b41cae9085ecf2
|
data/lib/telbe/bot.rb
CHANGED
@@ -9,13 +9,16 @@ module Telbe
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def request(action, query = {})
|
12
|
+
puts "### Telbe::Bot.request #{action} - #{query.to_h}"
|
12
13
|
path = "/bot#{@token}/#{action}"
|
13
14
|
response = @connection.post(path: path, query: query.to_h)
|
14
15
|
if response.status == 200
|
16
|
+
puts "### Telbe::Bot.request --- Success"
|
15
17
|
body = response.body
|
16
18
|
data = JSON.parse(body)
|
17
19
|
data["result"]
|
18
20
|
else
|
21
|
+
puts "### Telbe::Bot.request --- Error"
|
19
22
|
raise ResponseError, response.body
|
20
23
|
end
|
21
24
|
end
|
@@ -51,8 +54,42 @@ module Telbe
|
|
51
54
|
include InitializeFromHash
|
52
55
|
end
|
53
56
|
|
57
|
+
# chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
58
|
+
# text String Yes Text of the message to be sent
|
59
|
+
# parse_mode String Optional Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
|
60
|
+
# disable_web_page_preview Boolean Optional Disables link previews for links in this message
|
61
|
+
# disable_notification Boolean Optional Sends the message silently. Users will receive a notification with no sound.
|
62
|
+
# reply_to_message_id Integer Optional If the message is a reply, ID of the original message
|
63
|
+
# reply_markup InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply Optional Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
54
64
|
class MessageDescriptor
|
55
65
|
include InitializeFromHash
|
66
|
+
def self.factory
|
67
|
+
new(
|
68
|
+
chat_id: nil,
|
69
|
+
text: "",
|
70
|
+
parse_mode: "", # Markdown or HTML
|
71
|
+
disable_web_page_preview: false,
|
72
|
+
disable_notification: false,
|
73
|
+
reply_to_message_id: nil,
|
74
|
+
reply_markup: nil
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def initialize(opts)
|
79
|
+
raise ArgumentError, 'Invalid parse_mode' unless valid_parse_mode? opts[:parse_mode]
|
80
|
+
super opts
|
81
|
+
end
|
82
|
+
|
83
|
+
def parse_mode= (value)
|
84
|
+
value ||= "" # cast nil to the empty string
|
85
|
+
raise ArgumentError, 'Invalid parse_mode' unless valid_parse_mode? value
|
86
|
+
@parse_mode = value
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
def valid_parse_mode? (value)
|
91
|
+
value =~ /(^Markdown$)|(^HTML$)|(^$)/ # 0 = true
|
92
|
+
end
|
56
93
|
end
|
57
94
|
|
58
95
|
class ChatPhoto
|
data/lib/telbe/helper.rb
CHANGED
@@ -16,7 +16,7 @@ module Telbe
|
|
16
16
|
v.collect! { |i| Telbe::const_get(k.to_s.camelize).new(i) }
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
create_and_set_instance_variable("#{k}", v)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -34,13 +34,33 @@ module Telbe
|
|
34
34
|
h
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
|
37
|
+
def to_json
|
38
|
+
self.to_h.to_json
|
39
|
+
end
|
40
|
+
|
41
|
+
def method_missing(method_name, *args, &block)
|
42
|
+
case method_name
|
43
|
+
when /(.*)\=$/
|
44
|
+
create_and_set_instance_variable("#{$1}", args[0])
|
45
|
+
else
|
46
|
+
super(method_name, args, block)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def respond_to_missing?(method_name, *args)
|
51
|
+
case method_name
|
39
52
|
when /(.*)\=$/
|
40
|
-
|
53
|
+
true # always respond to assignment methods
|
41
54
|
else
|
42
|
-
|
55
|
+
super(method_name, args)
|
43
56
|
end
|
44
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def create_and_set_instance_variable(name, value)
|
61
|
+
instance_variable_set("@#{name}", value)
|
62
|
+
define_singleton_method("#{name}=") { |arg| instance_variable_set("@#{name}", arg) }
|
63
|
+
define_singleton_method("#{name}") { instance_variable_get("@#{name}") }
|
64
|
+
end
|
45
65
|
end
|
46
66
|
end
|
data/lib/telbe/keyboard.rb
CHANGED
@@ -1,14 +1,36 @@
|
|
1
1
|
module Telbe
|
2
|
+
# text String Text of the button. If none of the optional fields are used, it will be sent as a message when the button is pressed
|
3
|
+
# request_contact Boolean Optional. If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only
|
4
|
+
# request_location Boolean Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only
|
2
5
|
class KeyboardButton
|
3
6
|
include InitializeFromHash
|
7
|
+
def self.factory
|
8
|
+
self.new(
|
9
|
+
text: "",
|
10
|
+
request_contact: false,
|
11
|
+
request_location: false
|
12
|
+
)
|
13
|
+
end
|
4
14
|
end
|
5
15
|
|
6
16
|
class ReplyKeyboardRemove
|
7
17
|
include InitializeFromHash
|
8
18
|
end
|
9
19
|
|
20
|
+
# keyboard Array of Array of KeyboardButton Array of button rows, each represented by an Array of KeyboardButton objects
|
21
|
+
# resize_keyboard Boolean Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard.
|
22
|
+
# one_time_keyboard Boolean Optional. Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat – the user can press a special button in the input field to see the custom keyboard again. Defaults to false.
|
23
|
+
# selective Boolean Optional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
|
10
24
|
class ReplyKeyboardMarkup
|
11
25
|
include InitializeFromHash
|
26
|
+
def self.factory
|
27
|
+
self.new(
|
28
|
+
keyboard: [[]],
|
29
|
+
resize_keyboard: true,
|
30
|
+
one_time_keyboard: true,
|
31
|
+
selective: false
|
32
|
+
)
|
33
|
+
end
|
12
34
|
end
|
13
35
|
|
14
36
|
class InlineKeyboardMarkup
|
data/lib/telbe/location.rb
CHANGED
@@ -1,4 +1,53 @@
|
|
1
1
|
module Telbe
|
2
|
+
class Bot
|
3
|
+
def send_location(send_location_descriptor)
|
4
|
+
Message.new(request(:sendLocation, send_location_descriptor))
|
5
|
+
end
|
6
|
+
end
|
7
|
+
# chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
8
|
+
# latitude Float number Yes Latitude of the location
|
9
|
+
# longitude Float number Yes Longitude of the location
|
10
|
+
# live_period Integer Optional Period in seconds for which the location will be updated (see Live Locations, should be between 60 and 86400.
|
11
|
+
# disable_notification Boolean Optional Sends the message silently. Users will receive a notification with no sound.
|
12
|
+
# reply_to_message_id Integer Optional If the message is a reply, ID of the original message
|
13
|
+
# reply_markup InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply
|
14
|
+
class SendLocationDescriptor
|
15
|
+
include InitializeFromHash
|
16
|
+
|
17
|
+
def self.factory
|
18
|
+
new(
|
19
|
+
chat_id: nil,
|
20
|
+
latitude: nil,
|
21
|
+
longitude: nil,
|
22
|
+
liveperiod: 60,
|
23
|
+
disable_notification: true,
|
24
|
+
reply_to_message_id: nil,
|
25
|
+
reply_markup: nil
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# chat_id Integer or String Optional Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
31
|
+
# message_id Integer Optional Required if inline_message_id is not specified. Identifier of the message to edit
|
32
|
+
# inline_message_id String Optional Required if chat_id and message_id are not specified. Identifier of the inline message
|
33
|
+
# latitude Float number Yes Latitude of new location
|
34
|
+
# longitude Float number Yes Longitude of new location
|
35
|
+
# reply_markup InlineKeyboardMarkup Optional A JSON-serialized object for a new inline keyboard.
|
36
|
+
class EditMessageLiveLocationDescriptor
|
37
|
+
include InitializeFromHash
|
38
|
+
|
39
|
+
def self.factory
|
40
|
+
new(
|
41
|
+
chat_id: nil,
|
42
|
+
message_id: nil,
|
43
|
+
inline_message_id: nil,
|
44
|
+
latitude: nil,
|
45
|
+
longitude: nil,
|
46
|
+
reply_markup:nil
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
2
51
|
class Location
|
3
52
|
include InitializeFromHash
|
4
53
|
end
|
data/lib/telbe/poll.rb
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
module Telbe
|
2
2
|
class Bot
|
3
|
+
def send_poll(poll_descriptor)
|
4
|
+
Message.new(request(:sendPoll, poll_descriptor))
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
# chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername). A native poll can't be sent to a private chat.
|
9
|
+
# question String Yes Poll question, 1-255 characters
|
10
|
+
# options Array of String Yes List of answer options, 2-10 strings 1-100 characters each
|
11
|
+
# disable_notification Boolean Optional Sends the message silently. Users will receive a notification with no sound.
|
12
|
+
# reply_to_message_id Integer Optional If the message is a reply, ID of the original message
|
13
|
+
# reply_markup InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply Optional Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
14
|
+
class PollDescriptor
|
15
|
+
include InitializeFromHash
|
16
|
+
def self.factory
|
17
|
+
self.new(
|
18
|
+
chat_id: nil,
|
19
|
+
question: nil,
|
20
|
+
options: [],
|
21
|
+
disable_notification: false,
|
22
|
+
reply_to_message_id: nil,
|
23
|
+
reply_markup: nil
|
24
|
+
)
|
25
|
+
end
|
3
26
|
end
|
4
27
|
|
5
28
|
class PollOption
|
data/lib/telbe/version.rb
CHANGED