Class: VoiceML::ConversationsV1ConversationsResource

Inherits:
Object
  • Object
show all
Defined in:
lib/voiceml/resources/conversations_v1.rb

Overview

============================================================================

/v1/Conversations and all nested sub-resources (messages, participants, webhooks, message receipts).

Constant Summary collapse

CONVERSATION_FIELDS =
{
  'FriendlyName' => :friendly_name,
  'UniqueName' => :unique_name,
  'MessagingServiceSid' => :messaging_service_sid,
  'Attributes' => :attributes,
  'State' => :state,
  'Timers.Inactive' => :timers_inactive,
  'Timers.Closed' => :timers_closed,
  'Bindings.Email.Address' => :bindings_email_address,
  'Bindings.Email.Name' => :bindings_email_name
}.freeze
UPDATE_FIELDS =
{
  'FriendlyName' => :friendly_name,
  'UniqueName' => :unique_name,
  'MessagingServiceSid' => :messaging_service_sid,
  'Attributes' => :attributes,
  'State' => :state,
  'Timers.Inactive' => :timers_inactive,
  'Timers.Closed' => :timers_closed
}.freeze
MESSAGE_FIELDS =
{
  'Author' => :author,
  'Body' => :body,
  'Attributes' => :attributes,
  'ContentSid' => :content_sid
}.freeze
MESSAGE_UPDATE_FIELDS =
{
  'Author' => :author,
  'Body' => :body,
  'Attributes' => :attributes
}.freeze
PARTICIPANT_FIELDS =
{
  'Identity' => :identity,
  'Attributes' => :attributes,
  'RoleSid' => :role_sid,
  'MessagingBinding.Address' => :messaging_binding_address,
  'MessagingBinding.ProxyAddress' => :messaging_binding_proxy_address,
  'MessagingBinding.ProjectedAddress' => :messaging_binding_projected_address
}.freeze
PARTICIPANT_UPDATE_FIELDS =
{
  'Identity' => :identity,
  'Attributes' => :attributes,
  'RoleSid' => :role_sid,
  'LastReadMessageIndex' => :last_read_message_index,
  'LastReadTimestamp' => :last_read_timestamp
}.freeze
WEBHOOK_FIELDS =
{
  'Target' => :target,
  'Configuration.Url' => :configuration_url,
  'Configuration.Method' => :configuration_method,
  'Configuration.FlowSid' => :configuration_flow_sid,
  'Configuration.ReplayAfter' => :configuration_replay_after
}.freeze
WEBHOOK_UPDATE_FIELDS =
{
  'Configuration.Url' => :configuration_url,
  'Configuration.Method' => :configuration_method,
  'Configuration.FlowSid' => :configuration_flow_sid
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ ConversationsV1ConversationsResource

Returns a new instance of ConversationsV1ConversationsResource.



96
97
98
# File 'lib/voiceml/resources/conversations_v1.rb', line 96

def initialize(transport)
  @transport = transport
end

Instance Method Details

#create(**kwargs) ⇒ Object



107
108
109
110
111
# File 'lib/voiceml/resources/conversations_v1.rb', line 107

def create(**kwargs)
  ConversationsV1Conversation.from_hash(
    @transport.request(:post, '/v1/Conversations', form: build_form(CONVERSATION_FIELDS, kwargs))
  )
end

#create_message(conversation_sid, **kwargs) ⇒ Object



137
138
139
140
141
142
# File 'lib/voiceml/resources/conversations_v1.rb', line 137

def create_message(conversation_sid, **kwargs)
  ConversationsV1ConversationMessage.from_hash(
    @transport.request(:post, "/v1/Conversations/#{conversation_sid}/Messages",
                       form: build_form(MESSAGE_FIELDS, kwargs))
  )
end

#create_participant(conversation_sid, **kwargs) ⇒ Object



187
188
189
190
191
192
# File 'lib/voiceml/resources/conversations_v1.rb', line 187

def create_participant(conversation_sid, **kwargs)
  ConversationsV1ConversationParticipant.from_hash(
    @transport.request(:post, "/v1/Conversations/#{conversation_sid}/Participants",
                       form: build_form(PARTICIPANT_FIELDS, kwargs))
  )
end

#create_webhook(conversation_sid, target:, **kwargs) ⇒ Object



221
222
223
224
225
226
227
# File 'lib/voiceml/resources/conversations_v1.rb', line 221

def create_webhook(conversation_sid, target:, **kwargs)
  kwargs[:target] = target
  ConversationsV1ConversationScopedWebhook.from_hash(
    @transport.request(:post, "/v1/Conversations/#{conversation_sid}/Webhooks",
                       form: build_form(WEBHOOK_FIELDS, kwargs))
  )
end

#delete(sid) ⇒ Object



123
124
125
126
# File 'lib/voiceml/resources/conversations_v1.rb', line 123

def delete(sid)
  @transport.request(:delete, "/v1/Conversations/#{sid}")
  nil
end

#delete_message(conversation_sid, message_sid) ⇒ Object



157
158
159
160
# File 'lib/voiceml/resources/conversations_v1.rb', line 157

def delete_message(conversation_sid, message_sid)
  @transport.request(:delete, "/v1/Conversations/#{conversation_sid}/Messages/#{message_sid}")
  nil
end

#delete_participant(conversation_sid, participant_sid) ⇒ Object



207
208
209
210
# File 'lib/voiceml/resources/conversations_v1.rb', line 207

def delete_participant(conversation_sid, participant_sid)
  @transport.request(:delete, "/v1/Conversations/#{conversation_sid}/Participants/#{participant_sid}")
  nil
end

#delete_webhook(conversation_sid, webhook_sid) ⇒ Object



242
243
244
245
# File 'lib/voiceml/resources/conversations_v1.rb', line 242

def delete_webhook(conversation_sid, webhook_sid)
  @transport.request(:delete, "/v1/Conversations/#{conversation_sid}/Webhooks/#{webhook_sid}")
  nil
end

#fetch(sid) ⇒ Object



113
114
115
# File 'lib/voiceml/resources/conversations_v1.rb', line 113

def fetch(sid)
  ConversationsV1Conversation.from_hash(@transport.request(:get, "/v1/Conversations/#{sid}"))
end

#fetch_message(conversation_sid, message_sid) ⇒ Object



144
145
146
147
148
# File 'lib/voiceml/resources/conversations_v1.rb', line 144

def fetch_message(conversation_sid, message_sid)
  ConversationsV1ConversationMessage.from_hash(
    @transport.request(:get, "/v1/Conversations/#{conversation_sid}/Messages/#{message_sid}")
  )
end

#fetch_message_receipt(conversation_sid, message_sid, sid) ⇒ Object



172
173
174
175
176
# File 'lib/voiceml/resources/conversations_v1.rb', line 172

def fetch_message_receipt(conversation_sid, message_sid, sid)
  ConversationsV1ConversationMessageReceipt.from_hash(
    @transport.request(:get, "/v1/Conversations/#{conversation_sid}/Messages/#{message_sid}/Receipts/#{sid}")
  )
end

#fetch_participant(conversation_sid, participant_sid) ⇒ Object



194
195
196
197
198
# File 'lib/voiceml/resources/conversations_v1.rb', line 194

def fetch_participant(conversation_sid, participant_sid)
  ConversationsV1ConversationParticipant.from_hash(
    @transport.request(:get, "/v1/Conversations/#{conversation_sid}/Participants/#{participant_sid}")
  )
end

#fetch_webhook(conversation_sid, webhook_sid) ⇒ Object



229
230
231
232
233
# File 'lib/voiceml/resources/conversations_v1.rb', line 229

def fetch_webhook(conversation_sid, webhook_sid)
  ConversationsV1ConversationScopedWebhook.from_hash(
    @transport.request(:get, "/v1/Conversations/#{conversation_sid}/Webhooks/#{webhook_sid}")
  )
end

#list(page_size: nil) ⇒ Object

--- Conversations ---



101
102
103
104
105
# File 'lib/voiceml/resources/conversations_v1.rb', line 101

def list(page_size: nil)
  params = {}
  params['PageSize'] = page_size unless page_size.nil?
  ConversationsV1ConversationList.new(@transport.request(:get, '/v1/Conversations', params: params))
end

#list_message_receipts(conversation_sid, message_sid, page_size: nil) ⇒ Object

--- Message Receipts (read-only) ---



163
164
165
166
167
168
169
170
# File 'lib/voiceml/resources/conversations_v1.rb', line 163

def list_message_receipts(conversation_sid, message_sid, page_size: nil)
  params = {}
  params['PageSize'] = page_size unless page_size.nil?
  ConversationsV1ConversationMessageReceiptList.new(
    @transport.request(:get, "/v1/Conversations/#{conversation_sid}/Messages/#{message_sid}/Receipts",
                       params: params)
  )
end

#list_messages(conversation_sid, page_size: nil) ⇒ Object

--- Messages ---



129
130
131
132
133
134
135
# File 'lib/voiceml/resources/conversations_v1.rb', line 129

def list_messages(conversation_sid, page_size: nil)
  params = {}
  params['PageSize'] = page_size unless page_size.nil?
  ConversationsV1ConversationMessageList.new(
    @transport.request(:get, "/v1/Conversations/#{conversation_sid}/Messages", params: params)
  )
end

#list_participants(conversation_sid, page_size: nil) ⇒ Object

--- Participants ---



179
180
181
182
183
184
185
# File 'lib/voiceml/resources/conversations_v1.rb', line 179

def list_participants(conversation_sid, page_size: nil)
  params = {}
  params['PageSize'] = page_size unless page_size.nil?
  ConversationsV1ConversationParticipantList.new(
    @transport.request(:get, "/v1/Conversations/#{conversation_sid}/Participants", params: params)
  )
end

#list_webhooks(conversation_sid, page_size: nil) ⇒ Object

--- Scoped Webhooks ---



213
214
215
216
217
218
219
# File 'lib/voiceml/resources/conversations_v1.rb', line 213

def list_webhooks(conversation_sid, page_size: nil)
  params = {}
  params['PageSize'] = page_size unless page_size.nil?
  ConversationsV1ConversationScopedWebhookList.new(
    @transport.request(:get, "/v1/Conversations/#{conversation_sid}/Webhooks", params: params)
  )
end

#update(sid, **kwargs) ⇒ Object



117
118
119
120
121
# File 'lib/voiceml/resources/conversations_v1.rb', line 117

def update(sid, **kwargs)
  ConversationsV1Conversation.from_hash(
    @transport.request(:post, "/v1/Conversations/#{sid}", form: build_form(UPDATE_FIELDS, kwargs))
  )
end

#update_message(conversation_sid, message_sid, **kwargs) ⇒ Object



150
151
152
153
154
155
# File 'lib/voiceml/resources/conversations_v1.rb', line 150

def update_message(conversation_sid, message_sid, **kwargs)
  ConversationsV1ConversationMessage.from_hash(
    @transport.request(:post, "/v1/Conversations/#{conversation_sid}/Messages/#{message_sid}",
                       form: build_form(MESSAGE_UPDATE_FIELDS, kwargs))
  )
end

#update_participant(conversation_sid, participant_sid, **kwargs) ⇒ Object



200
201
202
203
204
205
# File 'lib/voiceml/resources/conversations_v1.rb', line 200

def update_participant(conversation_sid, participant_sid, **kwargs)
  ConversationsV1ConversationParticipant.from_hash(
    @transport.request(:post, "/v1/Conversations/#{conversation_sid}/Participants/#{participant_sid}",
                       form: build_form(PARTICIPANT_UPDATE_FIELDS, kwargs))
  )
end

#update_webhook(conversation_sid, webhook_sid, **kwargs) ⇒ Object



235
236
237
238
239
240
# File 'lib/voiceml/resources/conversations_v1.rb', line 235

def update_webhook(conversation_sid, webhook_sid, **kwargs)
  ConversationsV1ConversationScopedWebhook.from_hash(
    @transport.request(:post, "/v1/Conversations/#{conversation_sid}/Webhooks/#{webhook_sid}",
                       form: build_form(WEBHOOK_UPDATE_FIELDS, kwargs))
  )
end