Class: Zavudev::Resources::Conversations

Inherits:
Object
  • Object
show all
Defined in:
lib/zavudev/resources/conversations.rb,
sig/zavudev/resources/conversations.rbs

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Conversations

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Conversations.

Parameters:



119
120
121
# File 'lib/zavudev/resources/conversations.rb', line 119

def initialize(client:)
  @client = client
end

Instance Method Details

#list(channel: nil, cursor: nil, limit: nil, search: nil, sender_id: nil, request_options: {}) ⇒ Zavudev::Internal::Cursor<Zavudev::Models::ConversationListResponse>

Some parameter documentations has been truncated, see Models::ConversationListParams for more details.

List inbox threads, most recently active first. A conversation groups every message with one contact across channels, which is what you need to build an inbox: GET /v1/messages returns a flat log with no thread to hang it on.

Use senderId to scope the list to a single number, and channel to keep only threads that have carried that channel.

Parameters:

  • channel (Symbol, Zavudev::Models::ConversationListParams::Channel) —

    Keep only threads that have carried this channel.

  • cursor (String) —

    Opaque cursor from a previous response's nextCursor. Do not construct it.

  • limit (Integer)
  • search (String) —

    Search threads by identity: phone number (any format — +1 (555) 123-4567 and `

  • sender_id (String) —

    Keep only threads last handled by this sender.

  • request_options (Zavudev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/zavudev/resources/conversations.rb', line 52

def list(params = {})
  parsed, options = Zavudev::ConversationListParams.dump_request(params)
  query = Zavudev::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "v1/conversations",
    query: query.transform_keys(sender_id: "senderId"),
    page: Zavudev::Internal::Cursor,
    model: Zavudev::Models::ConversationListResponse,
    options: options
  )
end

#list_messages(conversation_id, cursor: nil, limit: nil, request_options: {}) ⇒ Zavudev::Internal::Cursor<Zavudev::Models::Message>

Messages in this thread, newest first, across every channel it has carried. Reply with POST /v1/messages, passing the conversation's senderId as the Zavu-Sender header so the answer leaves from the number the contact already knows.

Parameters:

  • conversation_id (String)
  • cursor (String) —

    Opaque cursor from a previous response's nextCursor.

  • limit (Integer)
  • request_options (Zavudev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/zavudev/resources/conversations.rb', line 83

def list_messages(conversation_id, params = {})
  parsed, options = Zavudev::ConversationListMessagesParams.dump_request(params)
  query = Zavudev::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["v1/conversations/%1$s/messages", conversation_id],
    query: query,
    page: Zavudev::Internal::Cursor,
    model: Zavudev::Message,
    options: options
  )
end

#mark_as_read(conversation_id, request_options: {}) ⇒ Zavudev::Models::ConversationMarkAsReadResponse

Reset the thread's unreadCount to zero. Marks the thread read in your own inbox only: it does not send a read receipt to the contact.

Parameters:

Returns:

See Also:



107
108
109
110
111
112
113
114
# File 'lib/zavudev/resources/conversations.rb', line 107

def mark_as_read(conversation_id, params = {})
  @client.request(
    method: :post,
    path: ["v1/conversations/%1$s/read", conversation_id],
    model: Zavudev::Models::ConversationMarkAsReadResponse,
    options: params[:request_options]
  )
end

#retrieve(conversation_id, request_options: {}) ⇒ Zavudev::Models::ConversationRetrieveResponse

Get conversation

Parameters:

Returns:

See Also:



16
17
18
19
20
21
22
23
# File 'lib/zavudev/resources/conversations.rb', line 16

def retrieve(conversation_id, params = {})
  @client.request(
    method: :get,
    path: ["v1/conversations/%1$s", conversation_id],
    model: Zavudev::Models::ConversationRetrieveResponse,
    options: params[:request_options]
  )
end