xasin-telegram 0.1.2.dev → 0.1.3.dev

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe8e24b94d5c11648a6b986c5c54f32851774019
4
- data.tar.gz: 93a23b6c042aa90fdfa0c0db6cda284c6381630f
3
+ metadata.gz: 743b7681fa291a1401aa3b999eeb412d8bda857d
4
+ data.tar.gz: '099444ca11d5acc8419ed9c27886e3f1636bf49f'
5
5
  SHA512:
6
- metadata.gz: 51568135c241d13a44e9ab1520322774f67e6b7ac7085f959a50efc2cc7fbb8ff77d1d6a5ba5c5f9b49eece675799fc2c590e712ccfb9262e9846a240838b925
7
- data.tar.gz: 0f7c5b06f43cc7524034a24f000e2bd2b44bb8aebb58275d83d2c4bf57401be63f03ac62c3cf4d209b20e9878e5ee6bd86a61c5b01a1d32d0e0863caf17b4cd0
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
- data[:parse_mode] ||= "Markdown";
51
- data[:chat_id] = uID;
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", data);
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
- # Send the POST request editing the message text
80
- @httpCore.perform_post("editMessageText",
81
- { text: data[:text],
82
- chat_id: uID,
83
- message_id: mID});
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xasin-telegram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.dev
4
+ version: 0.1.3.dev
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xasin