chat_sdk-whatsapp 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: b50c0867485e3db72c8642600094c6a648cd4c5f5030357d7b75c4448b3ddd86
4
- data.tar.gz: 607a03f130b22a02077456128ec0490dd54d2df0d4789739a185c6ce72725191
3
+ metadata.gz: b0736e051ec87a94ff8d73f8c0c023dfcbeefc8acf82c7772b4220289cf35266
4
+ data.tar.gz: f86066dd39e8e99245630268b79f407a3f1d6c17dbcc82e41b4fd2edf49d538f
5
5
  SHA512:
6
- metadata.gz: 8033901c11f50fe2d076a1f56db90d6c9f0793371c2a313841e7b09a2af76de34d9bcdb665125e8580fa30c77f6235ef3354da85ae9fbab1b536c5353a3426a6
7
- data.tar.gz: e9e4577b34adeaaeded3213517a3c7ccfb41e4cda3f75577bd02f15134c2d9dd62a757114c284f27bd167ffac40df6b5876be77719d7cea6262bdaa6766f23aa
6
+ metadata.gz: cac44b97beda98cdade923724bf7a36eda1501cf77b1e098a10fcc35765fd90ab956080b3d907383f8d8296657c6261465c6aef44b8e888c045d84c553fb3880
7
+ data.tar.gz: 985a93b4c1655dcfc51de67bf0ca3db479cd7952d4aeb32c589cdd2b67d58a80e66227358098f197f68ec685c2ec63d35c1e71e6e455ce39c8ac9631cbdbcacf
@@ -3,7 +3,7 @@
3
3
  module ChatSDK
4
4
  module WhatsApp
5
5
  class ApiClient < ChatSDK::ApiClient::Base
6
- BASE_URL = "https://graph.facebook.com/v21.0"
6
+ BASE_URL = "https://graph.facebook.com/v25.0"
7
7
 
8
8
  def initialize(access_token, phone_number_id)
9
9
  @access_token = access_token
@@ -29,11 +29,30 @@ module ChatSDK
29
29
  build_direct_message(msg, msg.dig("text", "body") || "", author, from, thread_id)
30
30
  when "interactive"
31
31
  parse_interactive_message(msg, author, from, thread_id)
32
- when "image", "document", "audio", "video"
32
+ when "reaction"
33
+ parse_reaction_message(msg, from, thread_id)
34
+ when "image", "document", "audio", "video", "sticker"
33
35
  parse_media_message(msg, author, from, thread_id)
34
36
  end
35
37
  end
36
38
 
39
+ def parse_reaction_message(msg, from, thread_id)
40
+ reaction = msg["reaction"] || {}
41
+ emoji = reaction["emoji"] || ""
42
+
43
+ ChatSDK::Events::Reaction.new(
44
+ emoji: emoji,
45
+ added: !emoji.empty?,
46
+ user_id: from,
47
+ message_id: reaction["message_id"],
48
+ thread_id: thread_id,
49
+ channel_id: from,
50
+ platform: :whatsapp,
51
+ adapter_name: :whatsapp,
52
+ raw: msg
53
+ )
54
+ end
55
+
37
56
  def parse_interactive_message(msg, author, channel_id, thread_id)
38
57
  interactive = msg["interactive"] || {}
39
58
  action_id = interactive.dig("button_reply", "id") || interactive.dig("list_reply", "id") || ""
@@ -41,6 +41,8 @@ module ChatSDK
41
41
  }
42
42
 
43
43
  {type: "interactive", interactive: interactive}
44
+ elsif buttons.length > 3
45
+ render_list_message(title, body_text, buttons)
44
46
  else
45
47
  # Fallback to plain text
46
48
  fallback = [title, subtitle, *text_parts].compact.reject(&:empty?).join("\n")
@@ -52,6 +54,27 @@ module ChatSDK
52
54
  end
53
55
  end
54
56
 
57
+ def render_list_message(title, body_text, buttons)
58
+ interactive = {
59
+ "type" => "list",
60
+ "body" => {"text" => body_text}
61
+ }
62
+ interactive["header"] = {"type" => "text", "text" => truncate(title, 60)} if title
63
+ interactive["action"] = {
64
+ "button" => "Options",
65
+ "sections" => [{
66
+ "rows" => buttons.first(10).map do |btn|
67
+ {
68
+ "id" => btn[:id],
69
+ "title" => truncate(btn[:text], 24)
70
+ }
71
+ end
72
+ }]
73
+ }
74
+
75
+ {type: "interactive", interactive: interactive}
76
+ end
77
+
55
78
  def collect_reply_buttons(node)
56
79
  buttons = []
57
80
  node.children.each do |child|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chat_sdk-whatsapp
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