Module: Telegram::SetApis

Includes:
CoreApi
Included in:
AllApis, Client
Defined in:
lib/api/set_apis.rb

Overview

rubocop:disable Metrics/ModuleLength

Instance Method Summary collapse

Methods included from CoreApi

#http_get, #http_post

Instance Method Details

#set_chat_description(chat_id, description) ⇒ Object

Use this method to change the description of a group, a supergroup or a channel.



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/api/set_apis.rb', line 70

def set_chat_description(chat_id, description)
  unless chat_id.to_i.negative?
    fail BadRequestError, 'can\'t set description for private chat'
  end

  hash = { chat_id: chat_id, description: description }
  data = http_post('setChatDescription', hash)
  unless data.ok # rubocop:disable Style/IfUnlessModifier
    fail PermissionError, data.description
  end

  data.result
end

#set_chat_permissions(chat_id, permissions) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/api/set_apis.rb', line 26

def set_chat_permissions(chat_id, permissions)
  unless chat_id.to_i.negative?
    fail BadRequestError, 'can\' set permissions for private chat'
  end
  hash = { chat_id: chat_id, permissions: permissions }
  response = http_post('setChatPermissions', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail PermissionError, response.description
  end
  response.result
end

#set_chat_photo(chat_id, file) ⇒ Object

Use this method to set a new profile photo for the chat. Photos can’t be changed for private chats.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/api/set_apis.rb', line 40

def set_chat_photo(chat_id, file)
  unless chat_id.to_i.negative?
    fail BadRequestError, 'can\'t set photo for private chat'
  end
  hash = { chat_id: chat_id, photo: file }
  data = http_post('setChatPhoto', hash)
  unless data.ok # rubocop:disable Style/IfUnlessModifier
    fail PermissionError, data.description
  end
  data.result
end

#set_chat_sticker_set(chat_id, set_name) ⇒ Object

Use this method to set a new group sticker set for a supergroup.



85
86
87
88
89
90
91
92
# File 'lib/api/set_apis.rb', line 85

def set_chat_sticker_set(chat_id, set_name)
  hash = { chat_id: chat_id, set_name: set_name }
  data = http_post('setChatStickerSet', hash)
  unless data.ok # rubocop:disable Style/IfUnlessModifier
    fail StandardError, data.description
  end
  data.result
end

#set_chat_title(chat_id, title) ⇒ Object

Use this method to change the title of a chat. Titles can’t be changed for private chats.



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/api/set_apis.rb', line 54

def set_chat_title(chat_id, title)
  unless chat_id.to_i.negative?
    fail BadRequestError, 'can\'t set chat title for private'
  end

  hash = { chat_id: chat_id, title: title.to_s }
  data = http_post('setChatTitle', hash)
  unless data.ok # rubocop:disable Style/IfUnlessModifier
    throw PermissionError, data.description
  end

  data.result
end

#set_cutom_title(chat_id, user_id, title) ⇒ Object

Use this method to set a custom title for an administrator in a supergroup promoted by the bot.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/api/set_apis.rb', line 14

def set_cutom_title(chat_id, user_id, title)
  if chat_id.to_i.negative?
    fail BadRequestError, 'can\' set custom title for private chat'
  end
  hash = { chat_id: chat_id, user_id: user_id, custom_title: title }
  response = http_post('setChatAdministratorCustomTitle', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail PermissionError, response.description
  end
  response.result
end

#set_my_command(command) ⇒ Object

Use this method to change the list of the bot’s commands.



95
96
97
98
99
100
101
102
# File 'lib/api/set_apis.rb', line 95

def set_my_command(command)
  hash = { command: command }
  data = http_post('setMyCommand', hash)
  unless data.ok # rubocop:disable Style/IfUnlessModifier
    fail TokenError, data.description
  end
  data.result
end

#set_sticker_position_in_the_set(sticker, position) ⇒ Object

Use this method to move a sticker in a set created by the bot to a specific position. position must be int value



106
107
108
109
110
111
112
113
# File 'lib/api/set_apis.rb', line 106

def set_sticker_position_in_the_set(sticker, position)
  hash = { sticker: sticker, position: position }
  data = http_post('setStickerPositionInTheSet', hash)
  unless data.ok # rubocop:disable Style/IfUnlessModifier
    fail Error, data.description
  end
  data.result
end

#set_sticker_set_thumb(name, user_id, params = {}) ⇒ Object

Use this method to set the thumbnail of a sticker set.



116
117
118
119
120
121
122
123
# File 'lib/api/set_apis.rb', line 116

def set_sticker_set_thumb(name, user_id, params = {})
  hash = { name: name, user_id: user_id }.merge!(params)
  data = http_post('setStickerSetThumb', hash)
  unless data.ok # rubocop:disable Style/IfUnlessModifier
    fail Error, data.description
  end
  data.result
end

#set_webhook(url, params = {}) ⇒ Object



125
126
127
# File 'lib/api/set_apis.rb', line 125

def set_webhook(url, params = {})
  fail NotImplementedError, 'not implemented'
end