chat_sdk-twilio 0.5.0 → 0.6.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 +4 -4
- data/lib/chat_sdk/twilio/adapter.rb +26 -1
- data/lib/chat_sdk/twilio/api_client.rb +15 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ea238818add1a2f25843a6e113643badfdde6d8484462727b672f337dcf59a9b
|
|
4
|
+
data.tar.gz: 94d79fd07541a22fb455ae5543e415928a70b914e3b7c253e8b72a6a0cfa7902
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ef2736852916fc4b0b5829f11a15867b0808322e6b157dbbc52575ff4dab6fa94ac423ab7a4decfec8af8068c488116440f2ff4f5d76f215a114428eeba18ac6
|
|
7
|
+
data.tar.gz: 249c12d6ac9c15fbd2592ba235f5de4e025e592a9019b84f996e43bfb87795e8a10828687d17a8be1b5bcb259c6c39473345412eeea77964f70fe66e944d716d
|
|
@@ -5,7 +5,7 @@ require "rack/utils"
|
|
|
5
5
|
module ChatSDK
|
|
6
6
|
module Twilio
|
|
7
7
|
class Adapter < ChatSDK::Adapter::Base
|
|
8
|
-
capabilities :direct_messages
|
|
8
|
+
capabilities :direct_messages, :message_history, :delete_messages
|
|
9
9
|
|
|
10
10
|
attr_reader :client
|
|
11
11
|
|
|
@@ -72,6 +72,31 @@ module ChatSDK
|
|
|
72
72
|
parse_twilio_message(result, channel_id)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
def fetch_messages(channel_id:, thread_id: nil, limit: 20) # rubocop:disable Lint/UnusedMethodArgument
|
|
76
|
+
result = @client.list_messages(to: channel_id, limit: limit)
|
|
77
|
+
messages = (result["messages"] || []).map do |msg|
|
|
78
|
+
ChatSDK::Message.new(
|
|
79
|
+
id: msg["sid"],
|
|
80
|
+
text: msg["body"] || "",
|
|
81
|
+
author: ChatSDK::Author.new(
|
|
82
|
+
id: msg["from"],
|
|
83
|
+
name: msg["from"],
|
|
84
|
+
platform: :twilio,
|
|
85
|
+
bot: msg["direction"] != "inbound"
|
|
86
|
+
),
|
|
87
|
+
thread_id: "twilio:#{channel_id}",
|
|
88
|
+
channel_id: channel_id,
|
|
89
|
+
platform: :twilio,
|
|
90
|
+
raw: msg
|
|
91
|
+
)
|
|
92
|
+
end
|
|
93
|
+
[messages, nil]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def delete_message(channel_id:, message_id:) # rubocop:disable Lint/UnusedMethodArgument
|
|
97
|
+
@client.delete_message(message_sid: message_id)
|
|
98
|
+
end
|
|
99
|
+
|
|
75
100
|
def open_dm(user_id)
|
|
76
101
|
user_id
|
|
77
102
|
end
|
|
@@ -20,6 +20,21 @@ module ChatSDK
|
|
|
20
20
|
handle_response(response)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
def list_messages(to: nil, from: nil, limit: 20)
|
|
24
|
+
params = {"PageSize" => limit.to_s}
|
|
25
|
+
params["To"] = to if to
|
|
26
|
+
params["From"] = from if from
|
|
27
|
+
response = connection.get(messages_path, params)
|
|
28
|
+
handle_response(response)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def delete_message(message_sid:)
|
|
32
|
+
response = connection.delete("/2010-04-01/Accounts/#{@account_sid}/Messages/#{message_sid}.json")
|
|
33
|
+
return {} if response.status == 204
|
|
34
|
+
|
|
35
|
+
handle_response(response)
|
|
36
|
+
end
|
|
37
|
+
|
|
23
38
|
private
|
|
24
39
|
|
|
25
40
|
def messages_path
|