chat_sdk-telegram 0.3.1 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f7d37715ceea339728711cb2bf73bb3ca54c505ebf41a7ceaefbdd1854855a2
4
- data.tar.gz: 7c577f6be364fa0590510c0b96cff7e80f06b875ed1961c51e58679b9116aea2
3
+ metadata.gz: 58370e45b0bd2e2b95b7e855bf5ad495ca5d1fdd5308762acccbd6d225768977
4
+ data.tar.gz: ff900b05aeb9fe7dfc0246bbc8ed67d7eacf902a465c95b55498096f39f4de8a
5
5
  SHA512:
6
- metadata.gz: 614df50891bcf72c989fcbe7cdab943163bae5ff687085bb1b22a2d9817a8316f6787bca63c99c0dcce7a55db51e7c971992879ef7144be88820a6c207055589
7
- data.tar.gz: c441e637e325a4819dda8e373bd587377aade11b1ffef58e91232dd68da8c318f84a4e8ea88351691f7cdf27cecf43d31bc0744e1da943893210a5996d77b790
6
+ metadata.gz: 61967c1e0462b9f65b5bf2ce8f79850942c118cff494c8a75286d8b490d52e1cd90c4d331ea6d10d2590be63d3c25195a702ea322fcffdf28e95550a1f9d6244
7
+ data.tar.gz: ab68df93fede82b187ccfcbc0aeedcddd86781aa7c5a3575d58f3ede4bb3c59c753e9f61b48de05205aa5fb0963d33704eaa16184bc54035d210ae08dd558c42
@@ -9,6 +9,8 @@ module ChatSDK
9
9
 
10
10
  if payload["callback_query"]
11
11
  parse_callback_query(payload["callback_query"])
12
+ elsif payload["message_reaction"]
13
+ parse_message_reaction(payload["message_reaction"])
12
14
  elsif payload["message"]
13
15
  parse_message(payload["message"], bot_username: bot_username)
14
16
  else
@@ -79,6 +81,46 @@ module ChatSDK
79
81
  )]
80
82
  end
81
83
 
84
+ def parse_message_reaction(reaction)
85
+ chat_id = reaction.dig("chat", "id")&.to_s
86
+ message_id = reaction["message_id"]&.to_s
87
+ user = reaction.dig("user") || reaction.dig("actor_chat") || {}
88
+ user_id = user["id"]&.to_s || "unknown"
89
+
90
+ new_reactions = reaction["new_reaction"] || []
91
+ old_reactions = reaction["old_reaction"] || []
92
+
93
+ if new_reactions.any?
94
+ emoji = new_reactions.first["emoji"] || new_reactions.first.dig("custom_emoji_id") || "unknown"
95
+ [ChatSDK::Events::Reaction.new(
96
+ emoji: emoji,
97
+ user_id: user_id,
98
+ message_id: message_id,
99
+ thread_id: message_id,
100
+ channel_id: chat_id,
101
+ added: true,
102
+ platform: :telegram,
103
+ adapter_name: :telegram,
104
+ raw: reaction
105
+ )]
106
+ elsif old_reactions.any?
107
+ emoji = old_reactions.first["emoji"] || old_reactions.first.dig("custom_emoji_id") || "unknown"
108
+ [ChatSDK::Events::Reaction.new(
109
+ emoji: emoji,
110
+ user_id: user_id,
111
+ message_id: message_id,
112
+ thread_id: message_id,
113
+ channel_id: chat_id,
114
+ added: false,
115
+ platform: :telegram,
116
+ adapter_name: :telegram,
117
+ raw: reaction
118
+ )]
119
+ else
120
+ []
121
+ end
122
+ end
123
+
82
124
  def extract_user(message)
83
125
  from = message["from"] || {}
84
126
  {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chat_sdk-telegram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quentin Rousseau