Class: KapsoClientRuby::Resources::Conversations
- Inherits:
-
Object
- Object
- KapsoClientRuby::Resources::Conversations
- Defined in:
- lib/kapso_client_ruby/resources/conversations.rb
Instance Method Summary collapse
-
#analytics(phone_number_id:, conversation_id: nil, since: nil, until_time: nil, granularity: 'day') ⇒ Object
Get conversation analytics (Kapso Proxy only).
-
#archive(conversation_id:) ⇒ Object
Archive conversation (Kapso Proxy only).
-
#end_conversation(conversation_id:) ⇒ Object
End conversation (Kapso Proxy only).
-
#get(conversation_id:) ⇒ Object
Get conversation details (Kapso Proxy only).
-
#initialize(client) ⇒ Conversations
constructor
A new instance of Conversations.
-
#list(phone_number_id:, status: nil, last_active_since: nil, last_active_until: nil, phone_number: nil, limit: nil, after: nil, before: nil, fields: nil) ⇒ Object
List conversations (Kapso Proxy only).
-
#unarchive(conversation_id:) ⇒ Object
Unarchive conversation (Kapso Proxy only).
-
#update_status(conversation_id:, status:) ⇒ Object
Update conversation status (Kapso Proxy only).
Constructor Details
#initialize(client) ⇒ Conversations
Returns a new instance of Conversations.
6 7 8 |
# File 'lib/kapso_client_ruby/resources/conversations.rb', line 6 def initialize(client) @client = client end |
Instance Method Details
#analytics(phone_number_id:, conversation_id: nil, since: nil, until_time: nil, granularity: 'day') ⇒ Object
Get conversation analytics (Kapso Proxy only)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/kapso_client_ruby/resources/conversations.rb', line 79 def analytics(phone_number_id:, conversation_id: nil, since: nil, until_time: nil, granularity: 'day') assert_kapso_proxy('Conversation Analytics API') query_params = { conversation_id: conversation_id, since: since, until: until_time, granularity: granularity }.compact response = @client.request(:get, "#{phone_number_id}/conversations/analytics", query: query_params, response_type: :json) response end |
#archive(conversation_id:) ⇒ Object
Archive conversation (Kapso Proxy only)
64 65 66 |
# File 'lib/kapso_client_ruby/resources/conversations.rb', line 64 def archive(conversation_id:) update_status(conversation_id: conversation_id, status: 'archived') end |
#end_conversation(conversation_id:) ⇒ Object
End conversation (Kapso Proxy only)
74 75 76 |
# File 'lib/kapso_client_ruby/resources/conversations.rb', line 74 def end_conversation(conversation_id:) update_status(conversation_id: conversation_id, status: 'ended') end |
#get(conversation_id:) ⇒ Object
Get conversation details (Kapso Proxy only)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kapso_client_ruby/resources/conversations.rb', line 33 def get(conversation_id:) assert_kapso_proxy('Conversations API') raise ArgumentError, 'conversation_id cannot be empty' if conversation_id.nil? || conversation_id.strip.empty? response = @client.request(:get, "conversations/#{conversation_id}", response_type: :json) # Handle both single object and data envelope responses if response.is_a?(Hash) && response.key?('data') Types::ConversationRecord.new(response['data']) else Types::ConversationRecord.new(response) end end |
#list(phone_number_id:, status: nil, last_active_since: nil, last_active_until: nil, phone_number: nil, limit: nil, after: nil, before: nil, fields: nil) ⇒ Object
List conversations (Kapso Proxy only)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kapso_client_ruby/resources/conversations.rb', line 11 def list(phone_number_id:, status: nil, last_active_since: nil, last_active_until: nil, phone_number: nil, limit: nil, after: nil, before: nil, fields: nil) assert_kapso_proxy('Conversations API') query_params = { status: status, last_active_since: last_active_since, last_active_until: last_active_until, phone_number: phone_number, limit: limit, after: after, before: before, fields: fields }.compact response = @client.request(:get, "#{phone_number_id}/conversations", query: query_params, response_type: :json) Types::PagedResponse.new(response, Types::ConversationRecord) end |
#unarchive(conversation_id:) ⇒ Object
Unarchive conversation (Kapso Proxy only)
69 70 71 |
# File 'lib/kapso_client_ruby/resources/conversations.rb', line 69 def unarchive(conversation_id:) update_status(conversation_id: conversation_id, status: 'active') end |
#update_status(conversation_id:, status:) ⇒ Object
Update conversation status (Kapso Proxy only)
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/kapso_client_ruby/resources/conversations.rb', line 50 def update_status(conversation_id:, status:) assert_kapso_proxy('Conversations API') raise ArgumentError, 'conversation_id cannot be empty' if conversation_id.nil? || conversation_id.strip.empty? raise ArgumentError, 'status cannot be empty' if status.nil? || status.strip.empty? payload = { status: status } response = @client.request(:patch, "conversations/#{conversation_id}", body: payload.to_json, response_type: :json) Types::GraphSuccessResponse.new(response) end |