Class: KapsoClientRuby::Resources::Calls
- Inherits:
-
Object
- Object
- KapsoClientRuby::Resources::Calls
- Defined in:
- lib/kapso_client_ruby/resources/calls.rb
Defined Under Namespace
Classes: Permissions
Instance Method Summary collapse
-
#accept(phone_number_id:, call_id:, session:, biz_opaque_callback_data: nil) ⇒ Object
Accept a call.
-
#connect(phone_number_id:, to:, session: nil, biz_opaque_callback_data: nil) ⇒ Object
Initiate a call.
-
#get(phone_number_id:, call_id:, fields: nil) ⇒ Object
Get call details (Kapso Proxy only).
-
#initialize(client) ⇒ Calls
constructor
A new instance of Calls.
-
#list(phone_number_id:, direction: nil, status: nil, since: nil, until_time: nil, call_id: nil, limit: nil, after: nil, before: nil, fields: nil) ⇒ Object
List calls (Kapso Proxy only).
- #permissions ⇒ Object
-
#pre_accept(phone_number_id:, call_id:, session:) ⇒ Object
Pre-accept a call.
-
#reject(phone_number_id:, call_id:) ⇒ Object
Reject a call.
-
#terminate(phone_number_id:, call_id:) ⇒ Object
Terminate a call.
Constructor Details
#initialize(client) ⇒ Calls
Returns a new instance of Calls.
6 7 8 |
# File 'lib/kapso_client_ruby/resources/calls.rb', line 6 def initialize(client) @client = client end |
Instance Method Details
#accept(phone_number_id:, call_id:, session:, biz_opaque_callback_data: nil) ⇒ Object
Accept a call
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/kapso_client_ruby/resources/calls.rb', line 44 def accept(phone_number_id:, call_id:, session:, biz_opaque_callback_data: nil) raise ArgumentError, 'call_id cannot be empty' if call_id.nil? || call_id.strip.empty? raise ArgumentError, 'session cannot be nil' if session.nil? payload = { messaging_product: 'whatsapp', call_id: call_id, action: 'accept', session: session } payload[:biz_opaque_callback_data] = biz_opaque_callback_data if biz_opaque_callback_data response = @client.request(:post, "#{phone_number_id}/calls", body: payload.to_json, response_type: :json) Types::CallActionResponse.new(response) end |
#connect(phone_number_id:, to:, session: nil, biz_opaque_callback_data: nil) ⇒ Object
Initiate a call
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/kapso_client_ruby/resources/calls.rb', line 11 def connect(phone_number_id:, to:, session: nil, biz_opaque_callback_data: nil) payload = { messaging_product: 'whatsapp', to: to, action: 'connect' } payload[:session] = session if session payload[:biz_opaque_callback_data] = biz_opaque_callback_data if biz_opaque_callback_data response = @client.request(:post, "#{phone_number_id}/calls", body: payload.to_json, response_type: :json) Types::CallConnectResponse.new(response) end |
#get(phone_number_id:, call_id:, fields: nil) ⇒ Object
Get call details (Kapso Proxy only)
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/kapso_client_ruby/resources/calls.rb', line 116 def get(phone_number_id:, call_id:, fields: nil) assert_kapso_proxy('Call details API') query_params = {} query_params[:fields] = fields if fields response = @client.request(:get, "#{phone_number_id}/calls/#{call_id}", query: query_params, response_type: :json) Types::CallRecord.new(response) end |
#list(phone_number_id:, direction: nil, status: nil, since: nil, until_time: nil, call_id: nil, limit: nil, after: nil, before: nil, fields: nil) ⇒ Object
List calls (Kapso Proxy only)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/kapso_client_ruby/resources/calls.rb', line 93 def list(phone_number_id:, direction: nil, status: nil, since: nil, until_time: nil, call_id: nil, limit: nil, after: nil, before: nil, fields: nil) assert_kapso_proxy('Call history API') query_params = { direction: direction, status: status, since: since, until: until_time, call_id: call_id, limit: limit, after: after, before: before, fields: fields }.compact response = @client.request(:get, "#{phone_number_id}/calls", query: query_params, response_type: :json) Types::PagedResponse.new(response, Types::CallRecord) end |
#permissions ⇒ Object
160 161 162 |
# File 'lib/kapso_client_ruby/resources/calls.rb', line 160 def ||= Permissions.new(@client) end |
#pre_accept(phone_number_id:, call_id:, session:) ⇒ Object
Pre-accept a call
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/kapso_client_ruby/resources/calls.rb', line 27 def pre_accept(phone_number_id:, call_id:, session:) raise ArgumentError, 'call_id cannot be empty' if call_id.nil? || call_id.strip.empty? raise ArgumentError, 'session cannot be nil' if session.nil? payload = { messaging_product: 'whatsapp', call_id: call_id, action: 'pre_accept', session: session } response = @client.request(:post, "#{phone_number_id}/calls", body: payload.to_json, response_type: :json) Types::CallActionResponse.new(response) end |
#reject(phone_number_id:, call_id:) ⇒ Object
Reject a call
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/kapso_client_ruby/resources/calls.rb', line 63 def reject(phone_number_id:, call_id:) raise ArgumentError, 'call_id cannot be empty' if call_id.nil? || call_id.strip.empty? payload = { messaging_product: 'whatsapp', call_id: call_id, action: 'reject' } response = @client.request(:post, "#{phone_number_id}/calls", body: payload.to_json, response_type: :json) Types::CallActionResponse.new(response) end |
#terminate(phone_number_id:, call_id:) ⇒ Object
Terminate a call
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/kapso_client_ruby/resources/calls.rb', line 78 def terminate(phone_number_id:, call_id:) raise ArgumentError, 'call_id cannot be empty' if call_id.nil? || call_id.strip.empty? payload = { messaging_product: 'whatsapp', call_id: call_id, action: 'terminate' } response = @client.request(:post, "#{phone_number_id}/calls", body: payload.to_json, response_type: :json) Types::CallActionResponse.new(response) end |