Class: Blueticks::Resources::ChatsResource

Inherits:
BaseResource show all
Defined in:
lib/blueticks/resources/chats.rb

Instance Attribute Summary

Attributes inherited from BaseResource

#client

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from Blueticks::BaseResource

Instance Method Details

#batch_message_acks(message_keys:) ⇒ Object

Batch get delivery status for up to 200 sent messages.



103
104
105
106
107
108
109
110
# File 'lib/blueticks/resources/chats.rb', line 103

def batch_message_acks(message_keys:)
  data = client.request(
    "POST",
    "/v1/chats/message_acks",
    body: { "message_keys" => message_keys }
  )
  Types::BatchMessageAcksResponse.from_hash(data)
end

#get(chat_id) ⇒ Object

Retrieve a chat by its JID.



21
22
23
24
# File 'lib/blueticks/resources/chats.rb', line 21

def get(chat_id)
  data = client.request("GET", "/v1/chats/#{chat_id}")
  Types::Chat.from_hash(data)
end

#get_media(chat_id, key) ⇒ Object

Fetch full media bytes (base64) for a message.



97
98
99
100
# File 'lib/blueticks/resources/chats.rb', line 97

def get_media(chat_id, key)
  data = client.request("GET", "/v1/chats/#{chat_id}/messages/#{key}/media")
  Types::ChatMedia.from_hash(data)
end

#get_media_url(chat_id, key) ⇒ Object

Get a hosted URL for the message media without inlining bytes.



91
92
93
94
# File 'lib/blueticks/resources/chats.rb', line 91

def get_media_url(chat_id, key)
  data = client.request("GET", "/v1/chats/#{chat_id}/messages/#{key}/media_url")
  Types::MediaUrlResponse.from_hash(data)
end

#get_message(chat_id, key) ⇒ Object

Retrieve a single message in a chat by its key.



63
64
65
66
# File 'lib/blueticks/resources/chats.rb', line 63

def get_message(chat_id, key)
  data = client.request("GET", "/v1/chats/#{chat_id}/messages/#{key}")
  Types::ChatMessage.from_hash(data)
end

#get_message_ack(chat_id, key) ⇒ Object

Get message delivery status (ack value: -1=error, 0=pending, 1=server, 2=device, 3=read, 4=played).



69
70
71
72
# File 'lib/blueticks/resources/chats.rb', line 69

def get_message_ack(chat_id, key)
  data = client.request("GET", "/v1/chats/#{chat_id}/messages/#{key}/ack")
  Types::MessageAck.from_hash(data)
end

#list(query: nil, limit: nil, cursor: nil) ⇒ Object

List/search chats, newest first. Cursor-paginated.



11
12
13
14
15
16
17
18
# File 'lib/blueticks/resources/chats.rb', line 11

def list(query: nil, limit: nil, cursor: nil)
  params = {}
  params["query"] = query unless query.nil?
  params["limit"] = limit unless limit.nil?
  params["cursor"] = cursor unless cursor.nil?
  data = client.request("GET", "/v1/chats", params: params.empty? ? nil : params)
  Types::Page.from_hash(data, item_type: Types::Chat)
end

#list_messages(chat_id, mode: "latest", query: nil, since: nil, until_: nil, message_types: nil, limit: nil, cursor: nil) ⇒ Object

List messages in a chat. ‘mode` is “latest” or “history”.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/blueticks/resources/chats.rb', line 49

def list_messages(chat_id, mode: "latest", query: nil, since: nil, until_: nil,
                  message_types: nil, limit: nil, cursor: nil)
  params = { "mode" => mode }
  params["query"] = query unless query.nil?
  params["since"] = since unless since.nil?
  params["until"] = until_ unless until_.nil?
  params["message_types"] = message_types.join(",") if message_types && !message_types.empty?
  params["limit"] = limit unless limit.nil?
  params["cursor"] = cursor unless cursor.nil?
  data = client.request("GET", "/v1/chats/#{chat_id}/messages", params: params)
  Types::Page.from_hash(data, item_type: Types::ChatMessage)
end

#list_participants(chat_id, limit: nil, cursor: nil) ⇒ Object

List participants in a group chat. Cursor-paginated.



27
28
29
30
31
32
33
34
# File 'lib/blueticks/resources/chats.rb', line 27

def list_participants(chat_id, limit: nil, cursor: nil)
  params = {}
  params["limit"] = limit unless limit.nil?
  params["cursor"] = cursor unless cursor.nil?
  data = client.request("GET", "/v1/chats/#{chat_id}/participants",
                        params: params.empty? ? nil : params)
  Types::Page.from_hash(data, item_type: Types::Participant)
end

#load_older_messages(chat_id) ⇒ Object

Ask the engine to pull older history from the connected phone.



85
86
87
88
# File 'lib/blueticks/resources/chats.rb', line 85

def load_older_messages(chat_id)
  data = client.request("POST", "/v1/chats/#{chat_id}/messages/load_older")
  Types::LoadOlderMessagesResponse.from_hash(data)
end

#mark_read(chat_id) ⇒ Object

Mark a chat as read (sends read receipts if enabled).



37
38
39
40
# File 'lib/blueticks/resources/chats.rb', line 37

def mark_read(chat_id)
  data = client.request("POST", "/v1/chats/#{chat_id}/mark_read")
  Types::OkResponse.from_hash(data)
end

#open(chat_id) ⇒ Object

Open a chat on the engine (useful for UI-assisted workflows).



43
44
45
46
# File 'lib/blueticks/resources/chats.rb', line 43

def open(chat_id)
  data = client.request("POST", "/v1/chats/#{chat_id}/open")
  Types::ChatRef.from_hash(data)
end

#react(chat_id, key, emoji:) ⇒ Object

React to a message. Pass an empty ‘emoji` string to remove a reaction.



75
76
77
78
79
80
81
82
# File 'lib/blueticks/resources/chats.rb', line 75

def react(chat_id, key, emoji:)
  data = client.request(
    "POST",
    "/v1/chats/#{chat_id}/messages/#{key}/reactions",
    body: { "emoji" => emoji }
  )
  Types::OkResponse.from_hash(data)
end