xasin-telegram 0.1.2.dev → 0.1.3.dev
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/lib/xasin/telegram/MQTT_Adapter.rb +56 -13
- 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: 743b7681fa291a1401aa3b999eeb412d8bda857d
|
4
|
+
data.tar.gz: '099444ca11d5acc8419ed9c27886e3f1636bf49f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e4fa00ac3f7d491ce64f83c3ccbba02d38a593b5e83dd132ceb0745b85585d9f867ada2041e5b3b2af50ee870f4158d8db9903cbfe5f406c50dc3773758e5c9
|
7
|
+
data.tar.gz: 85081d52cf64f6ff7654e317caa31b01623752a04e1cafa57276923d590dde2932cb371f4178b435a8d6aa77a3f9bf901a2f0669db0284a2646b9637b11f6408
|
@@ -28,6 +28,19 @@ module Telegram
|
|
28
28
|
setup_mqtt();
|
29
29
|
end
|
30
30
|
|
31
|
+
def _process_inline_keyboard(keyboardLayout, GID)
|
32
|
+
return nil unless (keyboardLayout.is_a? Array)
|
33
|
+
return nil unless GID
|
34
|
+
|
35
|
+
outData = Array.new();
|
36
|
+
|
37
|
+
keyboardLayout.each do |key|
|
38
|
+
outData << {text: key, callback_data: "#{GID}:#{key}"}
|
39
|
+
end
|
40
|
+
|
41
|
+
return {inline_keyboard: outData};
|
42
|
+
end
|
43
|
+
|
31
44
|
# Processes messages received through MQTT
|
32
45
|
# It takes care of setting a few good defaults (like parse_mode),
|
33
46
|
# deletes any old messages of the same GroupID (if requested),
|
@@ -38,7 +51,7 @@ module Telegram
|
|
38
51
|
def _handle_send(data, uID)
|
39
52
|
# Resolve a saved Username to a User-ID
|
40
53
|
uID = @usernameList[uID] if(@usernameList.key? uID)
|
41
|
-
uID = uID.to_i;
|
54
|
+
return if (uID = uID.to_i) == 0;
|
42
55
|
|
43
56
|
begin
|
44
57
|
data = JSON.parse(data, symbolize_names: true);
|
@@ -47,10 +60,17 @@ module Telegram
|
|
47
60
|
data = {text: data}
|
48
61
|
end
|
49
62
|
|
50
|
-
|
51
|
-
|
63
|
+
outData = {
|
64
|
+
chat_id: uID,
|
65
|
+
parse_mode: (data[:parse_mode] or "Markdown"),
|
66
|
+
text: data[:text]
|
67
|
+
}
|
68
|
+
|
69
|
+
if(ilk = data[:inline_keyboard])
|
70
|
+
outData[:reply_markup] = _process_inline_keyboard(ilk, data[:GID]);
|
71
|
+
end
|
52
72
|
|
53
|
-
reply = @httpCore.perform_post("sendMessage",
|
73
|
+
reply = @httpCore.perform_post("sendMessage", outData);
|
54
74
|
|
55
75
|
# Check if this message has a grouping ID
|
56
76
|
if(gID = data[:GID])
|
@@ -67,7 +87,7 @@ module Telegram
|
|
67
87
|
def _handle_edit(data, uID)
|
68
88
|
# Resolve a saved Username to a User-ID
|
69
89
|
uID = @usernameList[uID] if(@usernameList.key? uID)
|
70
|
-
uID = uID.to_i;
|
90
|
+
return if (uID = uID.to_i) == 0;
|
71
91
|
|
72
92
|
begin
|
73
93
|
data = JSON.parse(data, symbolize_names: true);
|
@@ -76,11 +96,22 @@ module Telegram
|
|
76
96
|
# Fetch the target Message ID
|
77
97
|
return unless mID = @groupIDList[uID][data[:GID]]
|
78
98
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
99
|
+
outData = {
|
100
|
+
chat_id: uID,
|
101
|
+
message_id: mID,
|
102
|
+
};
|
103
|
+
|
104
|
+
if(data[:inline_keyboard])
|
105
|
+
outData[:reply_markup] = _process_inline_keyboard(data[:inline_keyboard]);
|
106
|
+
end
|
107
|
+
|
108
|
+
if(data[:text])
|
109
|
+
outData[:text] = data[:text];
|
110
|
+
# Send the POST request editing the message text
|
111
|
+
@httpCore.perform_post("editMessageText", outData);
|
112
|
+
else
|
113
|
+
@httpCore.perform_post("editMessageReplyMarkup", outData);
|
114
|
+
end
|
84
115
|
rescue
|
85
116
|
end
|
86
117
|
end
|
@@ -88,7 +119,7 @@ module Telegram
|
|
88
119
|
def _handle_delete(data, uID)
|
89
120
|
# Resolve a saved Username to a User-ID
|
90
121
|
uID = @usernameList[uID] if(@usernameList.key? uID)
|
91
|
-
uID = uID.to_i;
|
122
|
+
return if (uID = uID.to_i) == 0;
|
92
123
|
|
93
124
|
# Fetch the real message ID held by a grouping ID
|
94
125
|
return unless mID = @groupIDList[uID][data]
|
@@ -136,10 +167,22 @@ module Telegram
|
|
136
167
|
end
|
137
168
|
|
138
169
|
if(data[:reply_GID])
|
139
|
-
@mqtt.publish_to "Telegram/#{uID}/Reply", data;
|
170
|
+
@mqtt.publish_to "Telegram/#{uID}/Reply", data.to_json;
|
140
171
|
else
|
141
|
-
@mqtt.publish_to "Telegram/#{uID}/Received", data;
|
172
|
+
@mqtt.publish_to "Telegram/#{uID}/Received", data.to_json;
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
if(msg = packet[:callback_query])
|
177
|
+
@httpCore.perform_post("answerCallbackQuery", {callback_query_id: msg[:id]});
|
178
|
+
|
179
|
+
uID = msg[:message][:chat][:id];
|
180
|
+
if(newUID = @usernameList.key(uID))
|
181
|
+
uID = newUID
|
142
182
|
end
|
183
|
+
|
184
|
+
return unless /(\w+):(\w+)/ =~ msg[:data]
|
185
|
+
@mqtt.publish_to "Telegram/#{uID}/KeyboardPress", {GID: $1, key: $2}
|
143
186
|
end
|
144
187
|
end
|
145
188
|
end
|