telerb 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +7 -1
- data/lib/telerb/version.rb +1 -1
- data/lib/telerb.rb +45 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 964e045af44fde247f3ea066345633b07deec2e907458fb01964bb7ef1b00d06
|
4
|
+
data.tar.gz: 129d9502dce5ca0bb59f285e08d56e0f05c8a2fad8cea44b5dc68a0550a5b17d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99b367e66da11237a96803259beb804f9ede27b3c8878d04540312fd1a6729bf725ee322c85865fc7a573e97be4c290ff7e9e9202c1945f66cab9458f777d4d1
|
7
|
+
data.tar.gz: 7fa9aac46a5aac79af2af8af27f5ff79e30b20b8f513d0e19efb19905a4e70323cff3749a372076dad3b87b92f9903d10c85ab8cfff496b4151b207feaddc4ba
|
data/CHANGELOG.md
CHANGED
@@ -3,3 +3,15 @@
|
|
3
3
|
## [0.1.0] - 2024-04-06
|
4
4
|
|
5
5
|
- Initial release
|
6
|
+
|
7
|
+
## [0.1.1] - 2024-04-07
|
8
|
+
|
9
|
+
- Implement the photo sending method
|
10
|
+
|
11
|
+
- Improvements to the http service
|
12
|
+
|
13
|
+
## [0.1.2] - 2024-04-07
|
14
|
+
|
15
|
+
- Add error handling to methods
|
16
|
+
- Implements The Audio, Video, Document sending method
|
17
|
+
- Improvement in media delivery Service
|
data/README.md
CHANGED
@@ -30,6 +30,12 @@ bot.listen do |message|
|
|
30
30
|
bot.send_message(chat_id, 'Hello World', message_id)
|
31
31
|
# Send a Photo
|
32
32
|
bot.send_photo(chat_id, "./exemple.png", "test", message_id)
|
33
|
+
# Send Document
|
34
|
+
bot.send_document(chat_id, "./exemple.rar", "test", message_id)
|
35
|
+
# Send Audio
|
36
|
+
bot.send_audio(chat_id, "./exemple.mp3", "test", message_id)
|
37
|
+
# Send Video
|
38
|
+
bot.send_video(chat_id, "./exemple.mp4", "test", message_id)
|
33
39
|
end
|
34
40
|
```
|
35
41
|
The ***message_id*** parameter is only necessary if you want the message to be sent as a reply.
|
@@ -50,4 +56,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
50
56
|
|
51
57
|
## Code of Conduct
|
52
58
|
|
53
|
-
Everyone interacting in the
|
59
|
+
Everyone interacting in the TeleRb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/codebyallan/TeleRb/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/telerb/version.rb
CHANGED
data/lib/telerb.rb
CHANGED
@@ -24,31 +24,63 @@ module TeleRb
|
|
24
24
|
block.call update["message"] if block_given? && update["message"]
|
25
25
|
@offset = update["update_id"] + 1
|
26
26
|
end
|
27
|
-
|
27
|
+
rescue StandardError => e
|
28
|
+
puts "Error in listen method: #{e.message}"
|
28
29
|
end
|
30
|
+
sleep 2
|
29
31
|
end
|
30
32
|
|
31
33
|
def send_message(chat_id, text, reply_to_message_id = nil)
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
CLIENT.post("#{@base_uri}#{@token}/sendMessage",
|
35
|
+
{ chat_id: chat_id, text: text, reply_to_message_id: reply_to_message_id })
|
36
|
+
"Message sent successfully!"
|
37
|
+
rescue StandardError => e
|
38
|
+
puts "Error sending message: #{e.message}"
|
39
|
+
nil
|
35
40
|
end
|
36
41
|
|
37
42
|
def send_photo(chat_id, photo_path, caption = nil, reply_to_message_id = nil)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
send_media(chat_id, photo_path, caption, reply_to_message_id, "sendPhoto", :photo)
|
44
|
+
end
|
45
|
+
|
46
|
+
def send_audio(chat_id, audio_path, caption = nil, reply_to_message_id = nil)
|
47
|
+
send_media(chat_id, audio_path, caption, reply_to_message_id, "sendAudio", :audio)
|
48
|
+
end
|
49
|
+
|
50
|
+
def send_video(chat_id, video_path, caption = nil, reply_to_message_id = nil)
|
51
|
+
send_media(chat_id, video_path, caption, reply_to_message_id, "sendVideo", :video)
|
52
|
+
end
|
53
|
+
|
54
|
+
def send_document(chat_id, document_path, caption = nil, reply_to_message_id = nil)
|
55
|
+
send_media(chat_id, document_path, caption, reply_to_message_id, "sendDocument", :document)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def send_media(chat_id, media_path, caption = nil, reply_to_message_id = nil, method, filekey)
|
61
|
+
raise ArgumentError, "Invalid media type: {#{filekey.capitalize}" unless %i[photo audio video
|
62
|
+
document].include?(filekey)
|
63
|
+
|
64
|
+
CLIENT.post("#{@base_uri}#{@token}/#{method}",
|
65
|
+
{
|
66
|
+
chat_id: chat_id,
|
67
|
+
reply_to_message_id: reply_to_message_id,
|
68
|
+
filekey.to_sym => File.new(media_path, "rb"),
|
69
|
+
caption: caption
|
70
|
+
},
|
71
|
+
{ "Content-Type" => "multipart/form-data" })
|
72
|
+
"#{filekey.capitalize} Sent with success!"
|
73
|
+
rescue StandardError => e
|
74
|
+
puts "Error when sending #{filekey.capitalize}: #{e.message}"
|
75
|
+
nil
|
47
76
|
end
|
48
77
|
|
49
78
|
def get_updates(offset = nil)
|
50
79
|
response = CLIENT.get("#{@base_uri}#{@token}/getUpdates", { offset: offset })
|
51
80
|
response.parsed_response["result"]
|
81
|
+
rescue StandardError => e
|
82
|
+
puts "Error in get_updates method: #{e.message}"
|
83
|
+
[]
|
52
84
|
end
|
53
85
|
end
|
54
86
|
end
|