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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59d96b52e19ae816e6586e40a289fb5f102137ddab921ddb16b7bcb74eb2702f
4
- data.tar.gz: a29d0b1d2a68e3ecd65e98fe09407a46ed0c6f6a35c21dbf995ea58b55261b98
3
+ metadata.gz: ea238818add1a2f25843a6e113643badfdde6d8484462727b672f337dcf59a9b
4
+ data.tar.gz: 94d79fd07541a22fb455ae5543e415928a70b914e3b7c253e8b72a6a0cfa7902
5
5
  SHA512:
6
- metadata.gz: 1fa688e246a77545709d0ac539b2e0b231f62d684ec422e92441453fee52ba39e2ef3767c0ae60f7d199df973af83805d6f19effa17fa05fa61e6af839e24055
7
- data.tar.gz: 515fcbb1a5e71c19bec2df988a54cbe1e229d3a1aa66ddf8112f788b4a049af253c0caa74a75252e9489541adf594338e12636bdd837c32e78ad189501abc4fc
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chat_sdk-twilio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quentin Rousseau