Skip to content

Commit 43aad60

Browse files
authored
DEVX-7835: Add Conversation API (#305)
* Adding Conversation API v1
1 parent ae6a36e commit 43aad60

25 files changed

+948
-2
lines changed

Diff for: CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 7.22.0
2+
3+
* Adds support for v1 the Conversation API. [#305](https://github.com/Vonage/vonage-ruby-sdk/pull/305)
4+
15
# 7.21.0
26

37
* Changes the HTTP adapter from `Net::HTTP` to `Net::HTTP::Persistent` and fixes an issue with a dependency (`ruby-jwt`)

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ The following is a list of Vonage APIs for which the Ruby SDK currently provides
525525

526526
* [Account API](https://developer.vonage.com/en/account/overview)
527527
* [Application API](https://developer.vonage.com/en/application/overview)
528+
* [Conversation API](https://developer.vonage.com/en/conversation/overview)
528529
* [Meetings API](https://developer.vonage.com/en/meetings/overview)
529530
* [Messages API](https://developer.vonage.com/en/messages/overview)
530531
* [Number Insight API](https://developer.vonage.com/en/number-insight/overview)

Diff for: lib/vonage/client.rb

+9
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,17 @@ def applications
4040
@applications ||= T.let(Applications.new(config), T.nilable(Vonage::Applications))
4141
end
4242

43+
# @return [Conversation]
44+
#
45+
sig { returns(T.nilable(Vonage::Conversation)) }
46+
def conversation
47+
@conversation ||= T.let(Conversation.new(config), T.nilable(Vonage::Conversation))
48+
end
49+
4350
# @return [Conversations]
4451
#
52+
# @deprecated Please use {#conversation} instead
53+
#
4554
sig { returns(T.nilable(Vonage::Conversations)) }
4655
def conversations
4756
@conversations ||= T.let(Conversations.new(config), T.nilable(Vonage::Conversations))

Diff for: lib/vonage/conversation.rb

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
module Vonage
5+
class Conversation < Namespace
6+
extend T::Sig
7+
8+
self.authentication = BearerToken
9+
10+
self.request_body = JSON
11+
12+
# List conversations associated with a Vonage application.
13+
#
14+
# @example
15+
# response = client.conversation.list
16+
#
17+
# @param [String] :date_start
18+
# Return the records that occurred after this point in time.
19+
#
20+
# @param [String] :date_end
21+
# Return the records that occurred before this point in time.
22+
#
23+
# @param [Integer] :page_size
24+
# Return this amount of records in the response.
25+
#
26+
# @param ['asc', 'desc'] :order
27+
# Return the records in ascending or descending order.
28+
#
29+
# @param [String] :cursor
30+
# The cursor to start returning results from.
31+
#
32+
# @return [Conversation::ListResponse]
33+
#
34+
# @see https://developer.vonage.com/en/api/conversation#listConversations
35+
#
36+
def list(**params)
37+
request('/v1/conversations', params: params, response_class: ListResponse)
38+
end
39+
40+
# Create a conversation.
41+
#
42+
# @example
43+
# response = client.conversation.create(name: 'Example Conversation', display_name: 'Example Display Name')
44+
#
45+
# @param [String] :name
46+
# Your internal conversation name. Must be unique.
47+
#
48+
# @param [String] :display_name
49+
# The public facing name of the conversation.
50+
#
51+
# @param [String] :image_url
52+
# An image URL that you associate with the conversation
53+
#
54+
# @param [Hash] :properties
55+
# - :ttl (Integer) After how many seconds an empty conversation is deleted
56+
# - :type (String)
57+
# - :custom_sort_key (String)
58+
# - :custom_data (Hash) Custom key/value pairs to be included with conversation data
59+
#
60+
# @option params [Array] :numbers An array of Hashes containing number information for different channels.
61+
#
62+
# @option params [Hash] :callback
63+
# - @option callback :url (String)
64+
# - @option callback :event_mask (String)
65+
# - @option callback :params (Hash)
66+
# - @option params :applicationId (String)
67+
# - @option params :ncco_url (String)
68+
# - @option callback :method (String) Must be one of ['POST', 'GET']
69+
#
70+
# @return [Response]
71+
#
72+
# @see https://developer.vonage.com/en/api/conversation#createConversation
73+
#
74+
def create(**params)
75+
request('/v1/conversations', params: params, type: Post)
76+
end
77+
78+
# Retrieve a conversation.
79+
#
80+
# @example
81+
# response = client.conversation.find(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a')
82+
#
83+
# @param [String] :conversation_id
84+
#
85+
# @return [Response]
86+
#
87+
# @see https://developer.vonage.com/en/api/conversation#retrieveConversation
88+
#
89+
def find(conversation_id:)
90+
request("/v1/conversations/#{conversation_id}")
91+
end
92+
93+
# Update a conversation.
94+
#
95+
# @example
96+
# response = client.conversation.update(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a', display_name: 'Updated conversation')
97+
#
98+
# @param [String] :name
99+
# Your internal conversation name. Must be unique.
100+
#
101+
# @param [String] :display_name
102+
# The public facing name of the conversation.
103+
#
104+
# @param [String] :image_url
105+
# An image URL that you associate with the conversation
106+
#
107+
# @param [Hash] :properties
108+
# - @option properties :ttl (Integer) After how many seconds an empty conversation is deleted
109+
# - @option properties :type (String)
110+
# - @option properties :custom_sort_key (String)
111+
# - @option properties :custom_data (Hash) Custom key/value pairs to be included with conversation data
112+
#
113+
# @param [Array] :numbers An array of Hashes containing number information for different channels.
114+
#
115+
# @option params [Hash] :callback
116+
# - @option callback :url (String)
117+
# - @option callback :event_mask (String)
118+
# - @option callback :params (Hash)
119+
# - @option params :applicationId (String)
120+
# - @option params :ncco_url (String)
121+
# - @option callback :method (String) Must be one of ['POST', 'GET']
122+
#
123+
# @return [Response]
124+
#
125+
# @see https://developer.vonage.com/en/api/conversation#replaceConversation
126+
#
127+
def update(conversation_id:, **params)
128+
request("/v1/conversations/#{conversation_id}", params: params, type: Put)
129+
end
130+
131+
# Delete a conversation.
132+
#
133+
# @example
134+
# response = client.conversation.delete(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a')
135+
#
136+
# @param [String] :conversation_id
137+
#
138+
# @return [Response]
139+
#
140+
# @see https://developer.vonage.com/en/api/conversation#deleteConversation
141+
#
142+
def delete(conversation_id:)
143+
request("/v1/conversations/#{conversation_id}", type: Delete)
144+
end
145+
146+
# @return [Conversation::User]
147+
sig { returns(T.nilable(Vonage::Conversation::User)) }
148+
def user
149+
@user ||= User.new(@config)
150+
end
151+
152+
# @return [Conversation::Member]
153+
sig { returns(T.nilable(Vonage::Conversation::Member)) }
154+
def member
155+
@member ||= Member.new(@config)
156+
end
157+
158+
# @return [Conversation::Event]
159+
sig { returns(T.nilable(Vonage::Conversation::Event)) }
160+
def event
161+
@event ||= Event.new(@config)
162+
end
163+
end
164+
end

Diff for: lib/vonage/conversation/event.rb

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# typed: true
2+
# frozen_string_literal: true
3+
4+
module Vonage
5+
class Conversation::Event < Namespace
6+
self.authentication = BearerToken
7+
8+
self.request_body = JSON
9+
10+
# List conversation events
11+
#
12+
# @example
13+
# response = client.conversation.event.list(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a')
14+
#
15+
# @param [required, String] :conversation_id The conversation_id of the conversation to list events for
16+
#
17+
# @param [String] :start_id
18+
# The ID to start returning events at
19+
#
20+
# @param [String] :end_id
21+
# The ID to end returning events at
22+
#
23+
# @param [String] :event_type
24+
# The type of event to search for. Does not currently support custom events
25+
#
26+
# @param [Integer] :page_size
27+
# Return this amount of records in the response.
28+
#
29+
# @param ['asc', 'desc'] :order
30+
# Return the records in ascending or descending order.
31+
#
32+
# @param [String] :cursor
33+
# The cursor to start returning results from.
34+
#
35+
# @return [Conversation::Member::ListResponse]
36+
#
37+
# @see https://developer.vonage.com/en/api/conversation#getEvents
38+
#
39+
def list(conversation_id:, **params)
40+
request("/v1/conversations/#{conversation_id}/events", params: params, response_class: ListResponse)
41+
end
42+
43+
# Create an event
44+
# @example
45+
# response = client.conversation.event.create(
46+
# conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a',
47+
# type: 'message',
48+
# body: {
49+
# message_type: 'text',
50+
# text: 'Hello World'
51+
# }
52+
# )
53+
#
54+
# @param [required, String] :conversation_id The conversation_id of the conversation to create the event for
55+
#
56+
# @param [required, String] :type
57+
# Event type.
58+
#
59+
# @param [String] :from
60+
#
61+
# @option params [required, String] :from
62+
#
63+
# @param [Hash] :body
64+
# The body of the event. There are many possible properties depending on the event type and message_type
65+
#
66+
# @return [Response]
67+
#
68+
# @see https://developer.vonage.com/en/api/conversation#createEvent
69+
#
70+
def create(conversation_id:, **params)
71+
request("/v1/conversations/#{conversation_id}/events", params: params, type: Post)
72+
end
73+
74+
# Get details of a specific event
75+
#
76+
# @example
77+
# response = client.conversation.event.find(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a', event_id: 1)
78+
#
79+
# @param [required, String] :conversation_id
80+
#
81+
# @param [required, String] :event_id
82+
#
83+
# @return [Response]
84+
#
85+
# @see https://developer.vonage.com/en/api/conversation#getEvent
86+
#
87+
def find(conversation_id:, event_id:)
88+
request("/v1/conversations/#{conversation_id}/events/#{event_id}")
89+
end
90+
91+
# Delete an event.
92+
#
93+
# @example
94+
# response = client.conversation.event.delete(conversation_id: 'CON-d66d47de-5bcb-4300-94f0-0c9d4b948e9a', event_id: 1)
95+
#
96+
# @param [String] :conversation_id
97+
#
98+
# @param [String] :event_id
99+
#
100+
# @return [Response]
101+
#
102+
# @see https://developer.vonage.com/en/api/conversation#deleteEvent
103+
#
104+
def delete(conversation_id:, event_id:)
105+
request("/v1/conversations/#{conversation_id}/events/#{event_id}", type: Delete)
106+
end
107+
end
108+
end

Diff for: lib/vonage/conversation/event/list_response.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# typed: true
2+
3+
class Vonage::Conversation::Event::ListResponse < Vonage::Response
4+
include Enumerable
5+
6+
def each
7+
return enum_for(:each) unless block_given?
8+
9+
@entity._embedded.each { |item| yield item }
10+
end
11+
end

Diff for: lib/vonage/conversation/list_response.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# typed: true
2+
3+
class Vonage::Conversation::ListResponse < Vonage::Response
4+
include Enumerable
5+
6+
def each
7+
return enum_for(:each) unless block_given?
8+
9+
@entity._embedded.conversations.each { |item| yield item }
10+
end
11+
end

0 commit comments

Comments
 (0)