telerb 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +33 -3
- data/lib/telerb/http_client.rb +1 -1
- data/lib/telerb/version.rb +1 -1
- data/lib/telerb.rb +62 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3db2e928c39d62a55c8d9a16bf1b1d6efe3f3022acb0e516ae8f62cc317aa68
|
4
|
+
data.tar.gz: 27f16654ae9420a8369d2beec14199c225139eac7dd8adccb46387e4cd1bb4f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be06d05d8992bc2fbd85b6589db0b7728d88dfd2e4d177f54d2224b18f2782dd038522083868fb0855bb0b36ee9387fcb69cdfcdefc448e3ad958fe3fbae7c53
|
7
|
+
data.tar.gz: fbd917d08644cdaab74b525f1d96004cb901247d491bda396017805cfdaa522d8712b26a76e163b1d055e43bcfcf395a9046d7cc6b81fc817a5a6b410f78fa16
|
data/CHANGELOG.md
CHANGED
@@ -3,3 +3,19 @@
|
|
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
|
18
|
+
|
19
|
+
## [0.1.3] - 2024-04-08
|
20
|
+
|
21
|
+
- Implement the methods to define the commands and obtain the defined commands
|
data/README.md
CHANGED
@@ -14,8 +14,10 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
14
14
|
|
15
15
|
## Usage
|
16
16
|
|
17
|
+
### Initialize Bot
|
17
18
|
|
18
19
|
```
|
20
|
+
|
19
21
|
require 'telerb'
|
20
22
|
|
21
23
|
# Create a bot instance
|
@@ -28,12 +30,40 @@ bot.listen do |message|
|
|
28
30
|
message_id = message['message_id']
|
29
31
|
# Send a text message
|
30
32
|
bot.send_message(chat_id, 'Hello World', message_id)
|
31
|
-
# Send a Photo
|
32
|
-
bot.send_photo(chat_id, "./exemple.png", "test", message_id)
|
33
33
|
end
|
34
|
+
|
34
35
|
```
|
35
36
|
The ***message_id*** parameter is only necessary if you want the message to be sent as a reply.
|
36
37
|
|
38
|
+
### Send Medias
|
39
|
+
```
|
40
|
+
|
41
|
+
# Send a Photo
|
42
|
+
bot.send_photo(chat_id, "./exemple.png", "test", message_id)
|
43
|
+
# Send Document
|
44
|
+
bot.send_document(chat_id, "./exemple.rar", "test", message_id)
|
45
|
+
# Send Audio
|
46
|
+
bot.send_audio(chat_id, "./exemple.mp3", "test", message_id)
|
47
|
+
# Send Video
|
48
|
+
bot.send_video(chat_id, "./exemple.mp4", "test", message_id)
|
49
|
+
|
50
|
+
```
|
51
|
+
### Commands
|
52
|
+
```
|
53
|
+
|
54
|
+
COMMANDS = [
|
55
|
+
{ command: "/start", description: "Start bot" },
|
56
|
+
{ command: "/help", description: "Show command list" }
|
57
|
+
].freeze
|
58
|
+
|
59
|
+
# Method that records bot commands
|
60
|
+
bot.set_commands(COMMANDS)
|
61
|
+
|
62
|
+
# Method that returns the available commands
|
63
|
+
bot.get_commands
|
64
|
+
|
65
|
+
```
|
66
|
+
|
37
67
|
## Development
|
38
68
|
|
39
69
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -50,4 +80,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
50
80
|
|
51
81
|
## Code of Conduct
|
52
82
|
|
53
|
-
Everyone interacting in the
|
83
|
+
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/http_client.rb
CHANGED
data/lib/telerb/version.rb
CHANGED
data/lib/telerb.rb
CHANGED
@@ -24,31 +24,80 @@ 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
|
+
def get_commands
|
59
|
+
response = CLIENT.get("#{@base_uri}#{@token}/getMyCommands")
|
60
|
+
response.parsed_response["result"]
|
61
|
+
rescue StandardError => e
|
62
|
+
puts "Error getting list of defined commands: #{e.message}"
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def set_commands(commands)
|
67
|
+
CLIENT.post("#{@base_uri}#{@token}/setMyCommands", { commands: commands }.to_json,
|
68
|
+
{ "Content-Type" => "application/json" })
|
69
|
+
"Commands set successfully"
|
70
|
+
rescue StandardError => e
|
71
|
+
puts "Error defining command list: #{e.message}"
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def send_media(chat_id, media_path, caption = nil, reply_to_message_id = nil, method, filekey)
|
78
|
+
raise ArgumentError, "Invalid media type: {#{filekey.capitalize}" unless %i[photo audio video
|
79
|
+
document].include?(filekey)
|
80
|
+
|
81
|
+
CLIENT.post("#{@base_uri}#{@token}/#{method}",
|
82
|
+
{
|
83
|
+
chat_id: chat_id,
|
84
|
+
reply_to_message_id: reply_to_message_id,
|
85
|
+
filekey.to_sym => File.new(media_path, "rb"),
|
86
|
+
caption: caption
|
87
|
+
},
|
88
|
+
{ "Content-Type" => "multipart/form-data" })
|
89
|
+
"#{filekey.capitalize} Sent with success!"
|
90
|
+
rescue StandardError => e
|
91
|
+
puts "Error when sending #{filekey.capitalize}: #{e.message}"
|
92
|
+
nil
|
47
93
|
end
|
48
94
|
|
49
95
|
def get_updates(offset = nil)
|
50
96
|
response = CLIENT.get("#{@base_uri}#{@token}/getUpdates", { offset: offset })
|
51
97
|
response.parsed_response["result"]
|
98
|
+
rescue StandardError => e
|
99
|
+
puts "Error in get_updates method: #{e.message}"
|
100
|
+
[]
|
52
101
|
end
|
53
102
|
end
|
54
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: telerb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CodeByAllan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby library to interact with the Telegram API and create custom bots.
|
14
14
|
email:
|