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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b0736e051ec87a94ff8d73f8c0c023dfcbeefc8acf82c7772b4220289cf35266
|
|
4
|
+
data.tar.gz: f86066dd39e8e99245630268b79f407a3f1d6c17dbcc82e41b4fd2edf49d538f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cac44b97beda98cdade923724bf7a36eda1501cf77b1e098a10fcc35765fd90ab956080b3d907383f8d8296657c6261465c6aef44b8e888c045d84c553fb3880
|
|
7
|
+
data.tar.gz: 985a93b4c1655dcfc51de67bf0ca3db479cd7952d4aeb32c589cdd2b67d58a80e66227358098f197f68ec685c2ec63d35c1e71e6e455ce39c8ac9631cbdbcacf
|
|
@@ -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 "
|
|
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|
|