telegem 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Readme.md +2 -2
- data/Starts_HallofFame.md +65 -0
- data/Test-Projects/bot.md +145 -0
- data/Test-Projects/bot1.rb +91 -0
- data/docs-src/Bot-registration_.PNG +0 -0
- data/docs-src/bot.md +349 -180
- data/docs-src/ctx.md +399 -0
- data/lib/api/client.rb +24 -23
- data/lib/core/bot.rb +69 -148
- data/lib/telegem.rb +1 -1
- data/lib/webhook/server.rb +87 -284
- data/setup.sh +30 -0
- metadata +21 -20
- data/Test-Projects/.gitkeep +0 -0
- data/Test-Projects/Movie-tracker-bot/.gitkeep +0 -0
- data/Test-Projects/Movie-tracker-bot/Gemfile +0 -2
- data/Test-Projects/Movie-tracker-bot/bot.rb +0 -62
- data/Test-Projects/Movie-tracker-bot/handlers/.gitkeep +0 -0
- data/Test-Projects/Movie-tracker-bot/handlers/add_1_.rb +0 -160
- data/Test-Projects/Movie-tracker-bot/handlers/add_2_.rb +0 -139
- data/Test-Projects/Movie-tracker-bot/handlers/premium.rb +0 -13
- data/Test-Projects/Movie-tracker-bot/handlers/report.rb +0 -31
- data/Test-Projects/Movie-tracker-bot/handlers/search.rb +0 -150
- data/Test-Projects/Movie-tracker-bot/handlers/sponsor.rb +0 -14
- data/Test-Projects/Movie-tracker-bot/handlers/start.rb +0 -48
- data/Test-Projects/Movie-tracker-bot/handlers/watch.rb +0 -210
- data/Test-Projects/Test-submitted-by-marvel/.gitkeep +0 -0
- data/Test-Projects/Test-submitted-by-marvel/Marvel-bot.md +0 -3
- data/Test-Projects/bot_test1.rb +0 -75
- data/Test-Projects/pizza_test_bot_guide.md +0 -163
- data/docs-src/understanding-ctx.md +0 -581
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a044b22212b4380cb47006c7f5bf18b06ee732c01d1baf8e18cd46bec92e6b32
|
|
4
|
+
data.tar.gz: e5bb919a62f17c531241f94ed45fe7331708f4485dae46423b9a8811941d07a9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4b801f8c4999e6d3f9bb77798e5f6b4a1d02d4a2d38d2c9f4d138a5cc0589b59983a78b16a58787a9b387fce9e66edf7da343446dd2fdbb0f772ecacdf786f7
|
|
7
|
+
data.tar.gz: ed36cec7c19a5f0cf68f5e0415ef890f92fcc1e95f793a21a56949facc50ee68264f11a3f35c54f7b02583d6c8768b082efb487ba30b53e3c8a6d307f5d0ceb4
|
data/Readme.md
CHANGED
|
@@ -77,9 +77,9 @@ end
|
|
|
77
77
|
|
|
78
78
|
📸 See It in Action
|
|
79
79
|
|
|
80
|
-
https://
|
|
80
|
+
<img src="https://i.postimg.cc/W3fdnx45/DA5D1EC7-F2E2-4243-87AB-841F5467F70C.png">
|
|
81
81
|
|
|
82
|
-
Example bot with interactive keyboard and scene-based
|
|
82
|
+
Example bot with interactive keyboard and scene-based flow
|
|
83
83
|
|
|
84
84
|
---
|
|
85
85
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# 🏆 Hall of Fame
|
|
2
|
+
|
|
3
|
+
This page honors the individuals who have actively engaged with and supported the Telegem project from its earliest days. Your participation is the foundation of this community.
|
|
4
|
+
|
|
5
|
+
Thank you for being part of the journey. ✨
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🧑💻 Active Contributors & Early Community
|
|
10
|
+
|
|
11
|
+
**Adeniyi Ayonide** ([@adeniyiayomide712](https://gitlab.com/adeniyiayomide712))
|
|
12
|
+
*First community member to open an issue, providing crucial early feedback.*
|
|
13
|
+
|
|
14
|
+
**Aurel Branzeanu** ([@texpert](https://gitlab.com/texpert))
|
|
15
|
+
*Early supporter providing valuable technical perspective.*
|
|
16
|
+
|
|
17
|
+
**Billy Ricch** ([@billyricch40](https://gitlab.com/billyricch40))
|
|
18
|
+
*Active community participant and contributor to project discussions.*
|
|
19
|
+
|
|
20
|
+
**Damola Amadu** ([@Dambzboy](https://gitlab.com/Dambzboy))
|
|
21
|
+
*Key supporter and participant in the project's growth.*
|
|
22
|
+
|
|
23
|
+
**Kakashi Osaose** ([@kakashiosaose](https://gitlab.com/kakashiosaose))
|
|
24
|
+
*Valued community member and technical contributor.*
|
|
25
|
+
|
|
26
|
+
**Olonade Solomon** ([@Timijay789](https://gitlab.com/Timijay789))
|
|
27
|
+
*Active participant in development discussions and testing.*
|
|
28
|
+
|
|
29
|
+
**Sergey Kojin** ([@skojin](https://gitlab.com/skojin))
|
|
30
|
+
*Technical contributor providing important implementation feedback.*
|
|
31
|
+
|
|
32
|
+
**Peter Boling** ([@pboling](https://gitlab.com/pboling))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 📜 Contribution Philosophy
|
|
38
|
+
|
|
39
|
+
This Hall of Fame recognizes **active participation and contribution** to the Telegem project. We value:
|
|
40
|
+
* **Code contributions** through merged Merge Requests
|
|
41
|
+
* **Quality issue reports** that improve the project
|
|
42
|
+
* **Technical discussions** that shape implementation
|
|
43
|
+
* **Community support** that helps other users
|
|
44
|
+
* **Documentation improvements** that help everyone
|
|
45
|
+
|
|
46
|
+
While starring the repository is appreciated, this list specifically honors those who have engaged in active dialogue, reporting, or contribution to the project's development.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 🔄 For Maintainers: How to Update
|
|
51
|
+
|
|
52
|
+
To add new contributors to this list:
|
|
53
|
+
|
|
54
|
+
1. **Format:** Follow the existing structure:
|
|
55
|
+
```markdown
|
|
56
|
+
**Name** ([@username](link-to-profile))
|
|
57
|
+
*Brief description of their contribution or role.*
|
|
58
|
+
```
|
|
59
|
+
2. **Categories:** As the community grows, consider organizing by contribution type (Core Contributors, Documentation, etc.)
|
|
60
|
+
3. **Verification:** Ensure the individual has made meaningful contributions beyond passive following
|
|
61
|
+
4. **Date:** Update the "Last Updated" field below
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
**Last Updated: 2025-31-12**
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
bot1.md - Telegem Response Patterns
|
|
2
|
+
|
|
3
|
+
How Telegem Returns API Responses
|
|
4
|
+
|
|
5
|
+
All ctx methods return HTTPX::Response objects, not JSON hashes.
|
|
6
|
+
|
|
7
|
+
Pattern 1: Fire-and-Forget
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
ctx.reply("Hello!")
|
|
11
|
+
ctx.photo("image.jpg")
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Pattern 2: Get Message ID
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
response = ctx.reply("Sending...")
|
|
18
|
+
|
|
19
|
+
if response && response.status == 200
|
|
20
|
+
data = response.json
|
|
21
|
+
if data && data['ok']
|
|
22
|
+
message_id = data['result']['message_id']
|
|
23
|
+
ctx.session[:msg_id] = message_id
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Pattern 3: Check for Errors
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
response = ctx.reply("Testing...")
|
|
32
|
+
|
|
33
|
+
if response && response.status != 200
|
|
34
|
+
error = response.json rescue nil
|
|
35
|
+
error_msg = error['description'] if error
|
|
36
|
+
ctx.reply("Failed: #{error_msg}")
|
|
37
|
+
end
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Pattern 4: Edit Messages
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
edit_response = ctx.edit_message_text(
|
|
44
|
+
"Updated!",
|
|
45
|
+
message_id: ctx.session[:msg_id]
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if edit_response && edit_response.status == 200
|
|
49
|
+
ctx.reply("Edit succeeded!")
|
|
50
|
+
end
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Pattern 5: Send Media
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
photo_response = ctx.photo(
|
|
57
|
+
"https://example.com/image.jpg",
|
|
58
|
+
caption: "My photo"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
if photo_response && photo_response.status == 200
|
|
62
|
+
ctx.reply("Photo sent!")
|
|
63
|
+
end
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Pattern 6: Handle Callbacks
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
bot.on(:callback_query) do |ctx|
|
|
70
|
+
ctx.answer_callback_query(text: "Clicked: #{ctx.data}")
|
|
71
|
+
|
|
72
|
+
if ctx.data == 'test'
|
|
73
|
+
ctx.edit_message_text("Updated after click!")
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Pattern 7: Error Wrapping
|
|
79
|
+
|
|
80
|
+
```ruby
|
|
81
|
+
begin
|
|
82
|
+
response = ctx.reply(some_text)
|
|
83
|
+
# Process response
|
|
84
|
+
rescue => e
|
|
85
|
+
ctx.reply("Error: #{e.message}")
|
|
86
|
+
end
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Complete bot1.rb Explained
|
|
90
|
+
|
|
91
|
+
Setup
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
require 'telegem'
|
|
95
|
+
require 'dotenv/load'
|
|
96
|
+
bot = Telegem.new(ENV['BOT_TOKEN'])
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
/start Command
|
|
100
|
+
|
|
101
|
+
Sends welcome, stores message ID in session.
|
|
102
|
+
|
|
103
|
+
/help Command
|
|
104
|
+
|
|
105
|
+
Simple reply with command list.
|
|
106
|
+
|
|
107
|
+
/edit Command
|
|
108
|
+
|
|
109
|
+
Edits the stored message, checks edit response.
|
|
110
|
+
|
|
111
|
+
/photo Command
|
|
112
|
+
|
|
113
|
+
Sends photo, confirms delivery.
|
|
114
|
+
|
|
115
|
+
/error Command
|
|
116
|
+
|
|
117
|
+
Demonstrates error handling.
|
|
118
|
+
|
|
119
|
+
Callback Handler
|
|
120
|
+
|
|
121
|
+
Answers inline button clicks.
|
|
122
|
+
|
|
123
|
+
Startup Logic
|
|
124
|
+
|
|
125
|
+
```ruby
|
|
126
|
+
if ENV['RACK_ENV'] == 'production'
|
|
127
|
+
# Webhook mode
|
|
128
|
+
server = bot.webhook(port: ENV['PORT'] || 3000)
|
|
129
|
+
server.run
|
|
130
|
+
server.set_webhook
|
|
131
|
+
else
|
|
132
|
+
# Polling mode (development)
|
|
133
|
+
bot.start_polling(timeout: 30, limit: 100)
|
|
134
|
+
end
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Key Takeaways
|
|
138
|
+
|
|
139
|
+
1. Always check response.status (200 = success)
|
|
140
|
+
2. Call .json to get data from response
|
|
141
|
+
3. Check data['ok'] before using result
|
|
142
|
+
4. Store message_id for later editing
|
|
143
|
+
5. Wrap in begin/rescue for network issues
|
|
144
|
+
|
|
145
|
+
This pattern ensures your bot handles all API scenarios correctly.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
require 'telegem'
|
|
2
|
+
require 'dotenv/load'
|
|
3
|
+
|
|
4
|
+
bot = Telegem.new(ENV['BOT_TOKEN'])
|
|
5
|
+
|
|
6
|
+
bot.command('start') do |ctx|
|
|
7
|
+
ctx.reply("Welcome! Use /help for commands.")
|
|
8
|
+
|
|
9
|
+
response = ctx.reply("Processing your request...")
|
|
10
|
+
|
|
11
|
+
if response && response.status == 200
|
|
12
|
+
data = response.json
|
|
13
|
+
if data && data['ok']
|
|
14
|
+
ctx.session[:start_msg_id] = data['result']['message_id']
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
bot.command('help') do |ctx|
|
|
20
|
+
help_text = <<~HELP
|
|
21
|
+
Available commands:
|
|
22
|
+
/start - Start the bot
|
|
23
|
+
/help - This help message
|
|
24
|
+
/edit - Edit the start message
|
|
25
|
+
/error - Test error handling
|
|
26
|
+
/photo - Send a photo
|
|
27
|
+
HELP
|
|
28
|
+
|
|
29
|
+
ctx.reply(help_text)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
bot.command('edit') do |ctx|
|
|
33
|
+
if ctx.session[:start_msg_id]
|
|
34
|
+
edit_response = ctx.edit_message_text(
|
|
35
|
+
"✅ Updated at #{Time.now.strftime('%H:%M:%S')}",
|
|
36
|
+
message_id: ctx.session[:start_msg_id]
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
if edit_response && edit_response.status == 200
|
|
40
|
+
ctx.reply("Message edited successfully!")
|
|
41
|
+
else
|
|
42
|
+
status = edit_response ? edit_response.status : 'no response'
|
|
43
|
+
ctx.reply("Edit failed (status: #{status})")
|
|
44
|
+
end
|
|
45
|
+
else
|
|
46
|
+
ctx.reply("Send /start first to create a message to edit.")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
bot.command('photo') do |ctx|
|
|
51
|
+
photo_response = ctx.photo(
|
|
52
|
+
"https://picsum.photos/400/300",
|
|
53
|
+
caption: "Random image - #{Time.now.strftime('%H:%M:%S')}"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
if photo_response && photo_response.status == 200
|
|
57
|
+
ctx.reply("Photo sent successfully!")
|
|
58
|
+
else
|
|
59
|
+
ctx.reply("Failed to send photo.")
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
bot.command('error') do |ctx|
|
|
64
|
+
begin
|
|
65
|
+
invalid_response = ctx.reply(nil)
|
|
66
|
+
|
|
67
|
+
if invalid_response && invalid_response.status != 200
|
|
68
|
+
error_data = invalid_response.json rescue nil
|
|
69
|
+
error_msg = error_data ? error_data['description'] : "Unknown error"
|
|
70
|
+
ctx.reply("API Error: #{error_msg}")
|
|
71
|
+
end
|
|
72
|
+
rescue => e
|
|
73
|
+
ctx.reply("Ruby Error: #{e.message}")
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
bot.on(:callback_query) do |ctx|
|
|
78
|
+
ctx.answer_callback_query(text: "Button clicked: #{ctx.data}")
|
|
79
|
+
|
|
80
|
+
if ctx.data == 'test'
|
|
81
|
+
ctx.edit_message_text("You clicked the test button!")
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
if ENV['RACK_ENV'] == 'production'
|
|
86
|
+
server = bot.webhook(port: ENV['PORT'] || 3000)
|
|
87
|
+
server.run
|
|
88
|
+
server.set_webhook
|
|
89
|
+
else
|
|
90
|
+
bot.start_polling(timeout: 30, limit: 100)
|
|
91
|
+
end
|
|
Binary file
|