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



86
87
88
89
90
91
92
# File 'lib/blueticks/resources/chats.rb', line 86

def batch_message_acks(message_keys:)
  client.request(
    "POST",
    "/v1/chats/message_acks",
    body: { "message_keys" => message_keys }
  )
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



81
82
83
84
# File 'lib/blueticks/resources/chats.rb', line 81

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

#get_message(chat_id, key) ⇒ Object



60
61
62
63
# File 'lib/blueticks/resources/chats.rb', line 60

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



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

def get_message_ack(chat_id, key)
  client.request("GET", "/v1/chats/#{chat_id}/messages/#{key}/ack")
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”.



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

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



77
78
79
# File 'lib/blueticks/resources/chats.rb', line 77

def load_older_messages(chat_id)
  client.request("POST", "/v1/chats/#{chat_id}/messages/load_older")
end

#mark_read(chat_id) ⇒ Object

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



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

def mark_read(chat_id)
  client.request("POST", "/v1/chats/#{chat_id}/mark_read")
end

#open(chat_id) ⇒ Object

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



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

def open(chat_id)
  client.request("POST", "/v1/chats/#{chat_id}/open")
end

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



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

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