Class: MaxBotApi::Resources::Chats
- Inherits:
-
Object
- Object
- MaxBotApi::Resources::Chats
- Defined in:
- lib/max_bot_api/resources/chats.rb
Overview
Chats API methods.
Instance Method Summary collapse
-
#add_member(chat_id:, users:) ⇒ Object
Add members to chat.
-
#edit_chat(chat_id:, update:) ⇒ Object
Patch chat info.
-
#get_chat(chat_id:) ⇒ Object
Fetch a single chat.
-
#get_chat_admins(chat_id:) ⇒ Object
List chat admins.
-
#get_chat_members(chat_id:, count: nil, marker: nil) ⇒ Object
List chat members.
-
#get_chat_membership(chat_id:) ⇒ Object
Fetch current bot membership info.
-
#get_chats(count: nil, marker: nil) ⇒ Object
List chats with pagination.
-
#get_pinned_message(chat_id:) ⇒ Object
Fetch the currently pinned message.
-
#get_specific_chat_members(chat_id:, user_ids:) ⇒ Object
Fetch specific members by user IDs.
-
#initialize(client) ⇒ Chats
constructor
A new instance of Chats.
-
#leave_chat(chat_id:) ⇒ Object
Leave a chat.
-
#pin_message(chat_id:, message_id:) ⇒ Object
Pin a message in chat.
-
#remove_member(chat_id:, user_id:) ⇒ Object
Remove a member from chat.
-
#send_action(chat_id:, action:) ⇒ Object
Send a chat action.
-
#unpin_message(chat_id:) ⇒ Object
Remove the currently pinned message.
Constructor Details
#initialize(client) ⇒ Chats
Returns a new instance of Chats.
7 8 9 |
# File 'lib/max_bot_api/resources/chats.rb', line 7 def initialize(client) @client = client end |
Instance Method Details
#add_member(chat_id:, users:) ⇒ Object
Add members to chat.
72 73 74 |
# File 'lib/max_bot_api/resources/chats.rb', line 72 def add_member(chat_id:, users:) @client.request(:post, "chats/#{chat_id}/members", body: users) end |
#edit_chat(chat_id:, update:) ⇒ Object
Patch chat info.
65 66 67 |
# File 'lib/max_bot_api/resources/chats.rb', line 65 def edit_chat(chat_id:, update:) @client.request(:patch, "chats/#{chat_id}", body: update) end |
#get_chat(chat_id:) ⇒ Object
Fetch a single chat.
23 24 25 |
# File 'lib/max_bot_api/resources/chats.rb', line 23 def get_chat(chat_id:) @client.request(:get, "chats/#{chat_id}") end |
#get_chat_admins(chat_id:) ⇒ Object
List chat admins.
52 53 54 |
# File 'lib/max_bot_api/resources/chats.rb', line 52 def get_chat_admins(chat_id:) @client.request(:get, "chats/#{chat_id}/members/admins") end |
#get_chat_members(chat_id:, count: nil, marker: nil) ⇒ Object
List chat members.
35 36 37 38 39 40 |
# File 'lib/max_bot_api/resources/chats.rb', line 35 def get_chat_members(chat_id:, count: nil, marker: nil) query = {} query['count'] = count if count && count.to_i > 0 query['marker'] = marker unless marker.nil? @client.request(:get, "chats/#{chat_id}/members", query: query) end |
#get_chat_membership(chat_id:) ⇒ Object
Fetch current bot membership info.
29 30 31 |
# File 'lib/max_bot_api/resources/chats.rb', line 29 def get_chat_membership(chat_id:) @client.request(:get, "chats/#{chat_id}/members/me") end |
#get_chats(count: nil, marker: nil) ⇒ Object
List chats with pagination.
14 15 16 17 18 19 |
# File 'lib/max_bot_api/resources/chats.rb', line 14 def get_chats(count: nil, marker: nil) query = {} query['count'] = count if count && count.to_i > 0 query['marker'] = marker if marker && marker.to_i > 0 @client.request(:get, 'chats', query: query) end |
#get_pinned_message(chat_id:) ⇒ Object
Fetch the currently pinned message.
99 100 101 |
# File 'lib/max_bot_api/resources/chats.rb', line 99 def (chat_id:) @client.request(:get, "chats/#{chat_id}/pin") end |
#get_specific_chat_members(chat_id:, user_ids:) ⇒ Object
Fetch specific members by user IDs.
45 46 47 48 |
# File 'lib/max_bot_api/resources/chats.rb', line 45 def get_specific_chat_members(chat_id:, user_ids:) ids = Array(user_ids).map(&:to_s).join(',') @client.request(:get, "chats/#{chat_id}/members", query: { 'user_ids' => ids }) end |
#leave_chat(chat_id:) ⇒ Object
Leave a chat.
58 59 60 |
# File 'lib/max_bot_api/resources/chats.rb', line 58 def leave_chat(chat_id:) @client.request(:delete, "chats/#{chat_id}/members/me") end |
#pin_message(chat_id:, message_id:) ⇒ Object
Pin a message in chat.
93 94 95 |
# File 'lib/max_bot_api/resources/chats.rb', line 93 def (chat_id:, message_id:) @client.request(:put, "chats/#{chat_id}/pin", body: { message_id: }) end |
#remove_member(chat_id:, user_id:) ⇒ Object
Remove a member from chat.
79 80 81 |
# File 'lib/max_bot_api/resources/chats.rb', line 79 def remove_member(chat_id:, user_id:) @client.request(:delete, "chats/#{chat_id}/members", query: { 'user_id' => user_id }) end |
#send_action(chat_id:, action:) ⇒ Object
Send a chat action.
86 87 88 |
# File 'lib/max_bot_api/resources/chats.rb', line 86 def send_action(chat_id:, action:) @client.request(:post, "chats/#{chat_id}/actions", body: { action: action }) end |
#unpin_message(chat_id:) ⇒ Object
Remove the currently pinned message.
105 106 107 |
# File 'lib/max_bot_api/resources/chats.rb', line 105 def (chat_id:) @client.request(:delete, "chats/#{chat_id}/pin") end |