Module: Telegram::SendApis

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

Overview

rubocop:disable Metrics/ModuleLength

Instance Method Summary collapse

Methods included from CoreApi

#http_get, #http_post

Instance Method Details

#send_animation(chat_id, animation, params = {}) ⇒ Object

Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).



65
66
67
68
69
70
71
72
# File 'lib/api/send_apis.rb', line 65

def send_animation(chat_id, animation, params = {})
  hash = { chat_id: chat_id, animation: animation }.merge!(params)
  response = http_post('sendAnimation', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.result)
end

#send_audio(chat_id, audio, params = {}) ⇒ Object

Use this method to send audio files.



33
34
35
36
37
38
39
40
# File 'lib/api/send_apis.rb', line 33

def send_audio(chat_id, audio, params = {})
  hash = { chat_id: chat_id, audio: audio }.merge!(params)
  response = http_post('sendAudio', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.result)
end

#send_chat_action(chat_id, action) ⇒ Object

Use this methods to send chat actions actions may be typing upload_photo record_video upload_video upload_audio upload_document find_location record_video_note upload_video_note



166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/api/send_apis.rb', line 166

def send_chat_action(chat_id, action) # rubocop:disable: Metrics/MethodLength
   actions = %w{ typing upload_photo record_video upload_video
   upload_audio upload_document find_location record_video_note
   upload_video_note }
   unless actions.include? action # rubocop:disable Style/IfUnlessModifier
     throw Error, 'invalid chat action'
   end
   hash = { chat_id: chat_id, action: action }
   response = http_post('sendChatAction', hash)
   unless response.ok # rubocop:disable Style/IfUnlessModifier
     fail IdError, 'incorrect chat id'
   end
   response.result
end

#send_contact(chat_id, phone_number, first_name, params = {}) ⇒ Object

Use this method to send phone contacts.



128
129
130
131
132
133
134
135
136
137
# File 'lib/api/send_apis.rb', line 128

def send_contact(chat_id, phone_number, first_name, params = {})
  hash = { chat_id: chat_id, phone_number: phone_number }
  hash2 = { first_name: first_name }.merge!(params)
  hash.merge!(hash2)
  response = http_post('sendContact', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.result)
end

#send_dice(chat_id, params = {}) ⇒ Object

Use this method to send an animated emoji that will display a random value.



153
154
155
156
157
158
159
160
# File 'lib/api/send_apis.rb', line 153

def send_dice(chat_id, params = {})
  hash = { chat_id: chat_id}.merge!(params)
  response = http_post('sendDice', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.description)
end

#send_document(chat_id, document, params = {}) ⇒ Object

Use this method to send general files.



43
44
45
46
47
48
49
50
# File 'lib/api/send_apis.rb', line 43

def send_document(chat_id, document, params = {})
  hash = { chat_id: chat_id, document: document }.merge!(params)
  response = http_post('sendDocument', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.result)
end

#send_location(chat_id, latitude, longitude, params = {}) ⇒ Object

Use this method to send point on the map.



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

def send_location(chat_id, latitude, longitude, params = {})
  hash = { chat_id: chat_id, latitude: latitude, longitude: longitude}
  hash.merge!(params)
  response = http_post('sendLocation', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.result)
end

#send_media_group(chat_id, media, params = {}) ⇒ Object

Use this method to send a group of photos or videos as an album.



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

def send_media_group(chat_id, media, params = {})
  hash = { chat_id: chat_id, media: media }.merge!(params)
  response = http_post('sendMediaGroup', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.result)
end

#send_message(chat_id, text, params = {}) ⇒ Object

Use this method to send text messages.



13
14
15
16
17
18
19
20
# File 'lib/api/send_apis.rb', line 13

def send_message(chat_id, text, params = {})
  hash = { chat_id: chat_id, text: text }.merge!(params)
  response = http_post('sendMessage', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.result)
end

#send_photo(chat_id, photo, params = {}) ⇒ Object

Use this method to send photos.



23
24
25
26
27
28
29
30
# File 'lib/api/send_apis.rb', line 23

def send_photo(chat_id, photo, params = {})
  hash = { chat_id: chat_id, photo: photo }.merge!(params)
  response = http_post('sendPhoto', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.result)
end

#send_poll(chat_id, question, options, params = {}) ⇒ Object

Use this method to send a native poll.



140
141
142
143
144
145
146
147
148
149
# File 'lib/api/send_apis.rb', line 140

def send_poll(chat_id, question, options, params = {})
  hash = { chat_id: chat_id, question: question }
  hash2 = { options: options }.merge!(params)
  hash.merge!(hash2)
  response = http_post('sendPoll', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.result)
end

#send_sticker(chat_id, file, params = {}) ⇒ Object

Use this method to send sticker file



182
183
184
185
186
187
188
189
# File 'lib/api/send_apis.rb', line 182

def send_sticker(chat_id, file, params = {})
  hash = { chat_id: chat_id, sticker: file }.merge!(params)
  response = http_post('sendSticker', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.result)
end

#send_venue(chat_id, latitude, longitude, title, address, params = {}) ⇒ Object

Use this method to send information about a venue.



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

def send_venue(chat_id, latitude, longitude, title, address, params = {})
  hash = { chat_id: chat_id, latitude: latitude, longitude: longitude }
  hash2 = { title: title, address: address}.merge!(params)
  hash.merge!(hash2)
  response = http_post('sendVenue', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    throw FatalError, response.description
  end
  Message.new(response.result)
end

#send_video(chat_id, video, params = {}) ⇒ Object

Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).



54
55
56
57
58
59
60
61
# File 'lib/api/send_apis.rb', line 54

def send_video(chat_id, video, params = {})
  hash = { chat_id: chat_id, video: video }.merge!(params)
  response = http_post('sendVideo', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
     fail FatalError, response.description
  end
  Message.new(response.result)
end

#send_video_note(chat_id, video_note, params = {}) ⇒ Object

Use this methods to send video note file



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

def send_video_note(chat_id, video_note, params = {})
  hash = { chat_id: chat_id, video_note: video_note }.merge!(params)
  response = http_post('sendVideoNote', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.result)
end

#send_voice(chat_id, voice, params = {}) ⇒ Object

Use this method to send voice file



75
76
77
78
79
80
81
82
# File 'lib/api/send_apis.rb', line 75

def send_voice(chat_id, voice, params = {})
  hash = { chat_id: chat_id, voice: voice }.merge!(params)
  response = http_post('sendVoice', hash)
  unless response.ok # rubocop:disable Style/IfUnlessModifier
    fail FatalError, response.description
  end
  Message.new(response.result)
end