telerb 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/2 +0 -0
- data/CHANGELOG.md +9 -1
- data/README.md +35 -2
- data/lib/telerb/http_client.rb +1 -1
- data/lib/telerb/version.rb +1 -1
- data/lib/telerb.rb +26 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78d7ec07b519c1f75aec94eb4ac66e0f34d86ff7c1485436dbc1caae1aaadf5c
|
4
|
+
data.tar.gz: 3bf93431b90dc93e26ec310a8f18c5cf108da873e0f58ef8c6a6b5a264435c42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de664f52593818ef039e2a8c30b039b59572c681ee02072428630571fa70f90523324d8c886fbbd4962ac060cbf78e899e9b33063b7cdad2a8457a64bfdda2e7
|
7
|
+
data.tar.gz: 54071830dc6d80c45ca94ae37a86a9662420ffdcdc48a8a9abded3150524b4b43e22fbf13bcc99c42e2a4c6bfa3e77dfef4f1a5c33a3edefd0e57cbd6368f25a
|
data/2
ADDED
File without changes
|
data/CHANGELOG.md
CHANGED
@@ -14,4 +14,12 @@
|
|
14
14
|
|
15
15
|
- Add error handling to methods
|
16
16
|
- Implements The Audio, Video, Document sending method
|
17
|
-
- Improvement in media delivery Service
|
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
|
22
|
+
|
23
|
+
## [0.1.4] - 2024-04-09
|
24
|
+
|
25
|
+
- Implements the forwardMessage method
|
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,6 +30,14 @@ 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)
|
33
|
+
end
|
34
|
+
|
35
|
+
```
|
36
|
+
The ***message_id*** parameter is only necessary if you want the message to be sent as a reply.
|
37
|
+
|
38
|
+
### Send Medias
|
39
|
+
```
|
40
|
+
|
31
41
|
# Send a Photo
|
32
42
|
bot.send_photo(chat_id, "./exemple.png", "test", message_id)
|
33
43
|
# Send Document
|
@@ -36,9 +46,32 @@ bot.listen do |message|
|
|
36
46
|
bot.send_audio(chat_id, "./exemple.mp3", "test", message_id)
|
37
47
|
# Send Video
|
38
48
|
bot.send_video(chat_id, "./exemple.mp4", "test", message_id)
|
39
|
-
|
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
|
+
|
67
|
+
### Forward Message
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
# Method for forwarding a message from one chat to another
|
72
|
+
bot.forward_message(from_chat_id, to_chat_id, message_id)
|
73
|
+
|
40
74
|
```
|
41
|
-
The ***message_id*** parameter is only necessary if you want the message to be sent as a reply.
|
42
75
|
|
43
76
|
## Development
|
44
77
|
|
data/lib/telerb/http_client.rb
CHANGED
data/lib/telerb/version.rb
CHANGED
data/lib/telerb.rb
CHANGED
@@ -55,6 +55,32 @@ module TeleRb
|
|
55
55
|
send_media(chat_id, document_path, caption, reply_to_message_id, "sendDocument", :document)
|
56
56
|
end
|
57
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
|
+
def forward_message(from_chat_id, to_chat_id, message_id)
|
76
|
+
CLIENT.post("#{@base_uri}#{@token}/forwardMessage",
|
77
|
+
{ chat_id: to_chat_id, from_chat_id: from_chat_id, message_id: message_id })
|
78
|
+
"Forwarding was then done successfully!"
|
79
|
+
rescue StandardError => e
|
80
|
+
puts "Error forwarding message: #{e.message}"
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
|
58
84
|
private
|
59
85
|
|
60
86
|
def send_media(chat_id, media_path, caption = nil, reply_to_message_id = nil, method, filekey)
|
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.4
|
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-09 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:
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- ".rspec"
|
21
21
|
- ".rubocop.yml"
|
22
22
|
- ".ruby-version"
|
23
|
+
- '2'
|
23
24
|
- CHANGELOG.md
|
24
25
|
- CODE_OF_CONDUCT.md
|
25
26
|
- LICENSE.txt
|