xasin-telegram 0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xasin/telegram/MQTT_Adapter.rb +29 -19
- 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: 0f3ca644e1e5d77120315bfd33be84caca0c66ef
|
4
|
+
data.tar.gz: b88593045f6338ad204bfefcdade20fff9ec0cf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82b65f87cb2d4b341a086bb748a48ee7a73ade189eee2e2ac21933f21352b149e0fef778ebb54ef1d932f0afdb2bdacd196ed3dc253fb625048b96c39eee26f8
|
7
|
+
data.tar.gz: 8b297c561c50a537a740a701bbb263adbffc2c596951ef7ae52d3680c8fff46e078dec39a794d51d53cef7a30d551ce932a1e4087b466fa13b4e34765c35a89c
|
@@ -32,20 +32,18 @@ module Telegram
|
|
32
32
|
return nil unless (keyboardLayout.is_a? Array)
|
33
33
|
return nil unless gID
|
34
34
|
|
35
|
+
|
36
|
+
keyboardLayout = [keyboardLayout] unless(keyboardLayout[0].is_a? Array);
|
35
37
|
outData = Array.new();
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
newRow = Array.new();
|
44
|
-
row.each do |key|
|
45
|
-
newRow << {text: key, callback_data: "#{gID}:#{key}"}
|
46
|
-
end
|
47
|
-
outData << newRow
|
38
|
+
|
39
|
+
keyboardLayout.each do |row|
|
40
|
+
newRow = Array.new();
|
41
|
+
|
42
|
+
row.each do |key, val|
|
43
|
+
cbd = {i: gID, k: (val or key)};
|
44
|
+
newRow << {text: key, callback_data: cbd.to_json}
|
48
45
|
end
|
46
|
+
outData << newRow;
|
49
47
|
end
|
50
48
|
|
51
49
|
return {inline_keyboard: outData};
|
@@ -76,15 +74,15 @@ module Telegram
|
|
76
74
|
text: data[:text]
|
77
75
|
}
|
78
76
|
|
79
|
-
if(ilk = data[:inline_keyboard] and data[:
|
80
|
-
outData[:reply_markup] = _process_inline_keyboard(ilk, data[:
|
77
|
+
if(ilk = data[:inline_keyboard] and data[:gid])
|
78
|
+
outData[:reply_markup] = _process_inline_keyboard(ilk, data[:gid]);
|
81
79
|
end
|
82
80
|
|
83
81
|
reply = @httpCore.perform_post("sendMessage", outData);
|
84
82
|
return unless reply[:ok]
|
85
83
|
|
86
84
|
# Check if this message has a grouping ID
|
87
|
-
if(gID = data[:
|
85
|
+
if(gID = data[:gid])
|
88
86
|
# If the message has the :single flag, delete the last one
|
89
87
|
if(data[:single])
|
90
88
|
_handle_delete(gID, uID);
|
@@ -105,7 +103,7 @@ module Telegram
|
|
105
103
|
|
106
104
|
return unless data[:text];
|
107
105
|
# Fetch the target Message ID
|
108
|
-
return unless mID = @groupIDList[uID][data[:
|
106
|
+
return unless mID = @groupIDList[uID][data[:gid]]
|
109
107
|
|
110
108
|
outData = {
|
111
109
|
chat_id: uID,
|
@@ -174,10 +172,14 @@ module Telegram
|
|
174
172
|
return unless(data[:text] = msg[:text])
|
175
173
|
|
176
174
|
if(replyMSG = msg[:reply_to_message])
|
177
|
-
data[:
|
175
|
+
data[:reply_gid] = @groupIDList[uID].key(replyMSG[:message_id]);
|
178
176
|
end
|
179
177
|
|
180
|
-
if(data[:
|
178
|
+
if(data[:text] =~ /^\//)
|
179
|
+
@mqtt.publish_to "Telegram/#{uID}/Command", data.to_json;
|
180
|
+
end
|
181
|
+
|
182
|
+
if(data[:reply_gid])
|
181
183
|
@mqtt.publish_to "Telegram/#{uID}/Reply", data.to_json;
|
182
184
|
else
|
183
185
|
@mqtt.publish_to "Telegram/#{uID}/Received", data.to_json;
|
@@ -193,7 +195,15 @@ module Telegram
|
|
193
195
|
end
|
194
196
|
|
195
197
|
return unless /(\S+):(\S+)/ =~ msg[:data]
|
196
|
-
|
198
|
+
begin
|
199
|
+
data = JSON.parse(msg[:data], symbolize_names: true);
|
200
|
+
|
201
|
+
if(data[:k] =~ /^\//)
|
202
|
+
@mqtt.publish_to "Telegram/#{uID}/Command", {text: data[:k]}.to_json
|
203
|
+
end
|
204
|
+
@mqtt.publish_to "Telegram/#{uID}/KeyboardPress", data.to_json
|
205
|
+
rescue
|
206
|
+
end
|
197
207
|
end
|
198
208
|
end
|
199
209
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xasin-telegram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xasin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mqtt-sub_handler
|