telegem 3.3.1 → 3.4.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/.rubocop.yml +57 -0
- data/CHANGELOG.md +19 -1
- data/README.md +147 -0
- data/bin/telegem-ssl +71 -25
- data/contributing.md +375 -0
- data/docs/api.md +663 -0
- data/docs/bot.md +332 -0
- data/docs/changelog.md +182 -0
- data/docs/context.md +554 -0
- data/docs/core_concepts.md +218 -0
- data/docs/deployment.md +702 -0
- data/docs/error_handling.md +435 -0
- data/docs/examples.md +752 -0
- data/docs/getting_started.md +151 -0
- data/docs/handlers.md +580 -0
- data/docs/keyboards.md +446 -0
- data/docs/middleware.md +536 -0
- data/docs/plugins.md +384 -0
- data/docs/scenes.md +517 -0
- data/docs/sessions.md +544 -0
- data/docs/testing.md +612 -0
- data/docs/troubleshooting.md +574 -0
- data/docs/types.md +538 -0
- data/docs/webhooks.md +456 -0
- data/lib/api/client.rb +38 -10
- data/lib/api/types.rb +129 -106
- data/lib/core/composer.rb +3 -3
- data/lib/core/context.rb +17 -11
- data/lib/plugins/cc +3 -0
- data/lib/plugins/translate.rb +43 -0
- data/lib/session/redis.rb +91 -0
- data/lib/telegem.rb +3 -3
- data/lib/webhook/server.rb +5 -3
- metadata +41 -29
- data/Contributing.md +0 -161
- data/Readme.md +0 -298
- data/bin/telegem-init +0 -32
- data/examples/.gitkeep +0 -0
- data/public/.gitkeep +0 -0
data/Readme.md
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
Modern, blazing-fast async Telegram Bot API for Ruby - Inspired by Telegraf, built for performance.
|
|
4
|
-
|
|
5
|
-
    
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Blazing-fast, modern Telegram Bot framework for Ruby. Inspired by Telegraf.js, built for performance with true async/await patterns.
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
✨ Features
|
|
15
|
-
|
|
16
|
-
- ⚡ True Async I/O - Built on async gem, not blocking threads
|
|
17
|
-
- 🎯 Telegraf-style DSL - Familiar API for JavaScript developers
|
|
18
|
-
- 🔌 Middleware System - Compose behavior like Express.js
|
|
19
|
-
- 🧙 Scene System - Multi-step conversations (wizards/forms)
|
|
20
|
-
- 💾 Session Management - Redis, memory, or custom stores
|
|
21
|
-
- ⌨️ Keyboard DSL - Clean markup builders with fluent API
|
|
22
|
-
- 🌐 Webhook Server - Production-ready async HTTP server
|
|
23
|
-
- 🏗️ Type-Safe Objects - Ruby classes for all Telegram types
|
|
24
|
-
- 📦 Minimal Dependencies - Just async gems + mime-types
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
🚀 Quick Start
|
|
29
|
-
|
|
30
|
-
Installation
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
gem install telegem
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Or add to your Gemfile:
|
|
37
|
-
|
|
38
|
-
```ruby
|
|
39
|
-
gem 'telegem'
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Your First Bot (in 60 seconds)
|
|
43
|
-
|
|
44
|
-
```ruby
|
|
45
|
-
require 'telegem'
|
|
46
|
-
|
|
47
|
-
# 1. Get token from @BotFather on Telegram
|
|
48
|
-
bot = Telegem.new('YOUR_BOT_TOKEN')
|
|
49
|
-
|
|
50
|
-
# 2. Add commands
|
|
51
|
-
bot.command('start') do |ctx|
|
|
52
|
-
ctx.reply "Hello #{ctx.from.first_name}! 👋"
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
bot.command('help') do |ctx|
|
|
56
|
-
ctx.reply "I'm your friendly Telegem bot!"
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# 3. Start listening
|
|
60
|
-
puts "🤖 Bot starting..."
|
|
61
|
-
bot.start_polling
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
Interactive Example
|
|
65
|
-
|
|
66
|
-
```ruby
|
|
67
|
-
# Pizza ordering bot example
|
|
68
|
-
bot.command('order') do |ctx|
|
|
69
|
-
keyboard = Telegem.keyboard do
|
|
70
|
-
row "🍕 Margherita", "🍕 Pepperoni"
|
|
71
|
-
row "🥤 Drinks", "🍰 Dessert"
|
|
72
|
-
row "📞 Support", "❌ Cancel"
|
|
73
|
-
end.resize.one_time
|
|
74
|
-
|
|
75
|
-
ctx.reply "What would you like?", reply_markup: keyboard
|
|
76
|
-
end
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
---
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
---
|
|
83
|
-
|
|
84
|
-
🎯 Why Telegem?
|
|
85
|
-
|
|
86
|
-
vs. Other Ruby Telegram Libraries
|
|
87
|
-
|
|
88
|
-
| Telegem | telegram-bot-ruby |
|
|
89
|
-
| ------ | ------ |
|
|
90
|
-
| fast async | multiple thread |
|
|
91
|
-
| non blocking request | slow thread based |
|
|
92
|
-
| clean telegraf dsl | no dsl |
|
|
93
|
-
| scene management. | verbose |
|
|
94
|
-
| middleware | raw json |
|
|
95
|
-
| clean markup dsl|. |
|
|
96
|
-
|
|
97
|
-
Perfect For:
|
|
98
|
-
|
|
99
|
-
- High-traffic bots needing async performance
|
|
100
|
-
- Complex conversations with multi-step flows
|
|
101
|
-
- Production deployments with webhooks & scaling
|
|
102
|
-
- Developers familiar with Telegraf.js/Express
|
|
103
|
-
- Modern Ruby (3.0+) applications
|
|
104
|
-
|
|
105
|
-
---
|
|
106
|
-
|
|
107
|
-
[📚 Documentation](https://rubydoc.info/gems/telegem/3.2.3/index)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
🧩 Advanced Features
|
|
112
|
-
|
|
113
|
-
Scene System (Multi-step Conversations)
|
|
114
|
-
|
|
115
|
-
```ruby
|
|
116
|
-
bot.scene :registration do
|
|
117
|
-
step :ask_name do |ctx|
|
|
118
|
-
ctx.reply "What's your name?"
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
step :save_name do |ctx|
|
|
122
|
-
ctx.session[:name] = ctx.message.text
|
|
123
|
-
ctx.reply "Hi #{ctx.session[:name]}! What's your email?"
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
step :complete do |ctx|
|
|
127
|
-
ctx.session[:email] = ctx.message.text
|
|
128
|
-
ctx.reply "Registration complete! ✅"
|
|
129
|
-
ctx.leave_scene
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
Middleware Pipeline
|
|
135
|
-
|
|
136
|
-
```ruby
|
|
137
|
-
# Add cross-cutting concerns
|
|
138
|
-
bot.use AuthenticationMiddleware.new
|
|
139
|
-
bot.use RateLimiter.new(limit: 10)
|
|
140
|
-
bot.use LoggingMiddleware.new
|
|
141
|
-
|
|
142
|
-
# Custom middleware
|
|
143
|
-
bot.use do |ctx, next_middleware|
|
|
144
|
-
puts "Processing message from #{ctx.from.username}"
|
|
145
|
-
next_middleware.call(ctx)
|
|
146
|
-
end
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
Multiple Session Stores
|
|
150
|
-
|
|
151
|
-
```ruby
|
|
152
|
-
# Memory (development)
|
|
153
|
-
Telegem::Session::MemoryStore.new
|
|
154
|
-
|
|
155
|
-
# Redis (production)
|
|
156
|
-
require 'redis'
|
|
157
|
-
redis = Redis.new(url: ENV['REDIS_URL'])
|
|
158
|
-
Telegem::Session::RedisStore.new(redis)
|
|
159
|
-
|
|
160
|
-
# Custom (database, etc.)
|
|
161
|
-
class DatabaseStore
|
|
162
|
-
def get(user_id); end
|
|
163
|
-
def set(user_id, data); end
|
|
164
|
-
end
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
---
|
|
168
|
-
|
|
169
|
-
🌐 Production Deployment
|
|
170
|
-
|
|
171
|
-
Webhook Mode (Recommended)
|
|
172
|
-
|
|
173
|
-
```ruby
|
|
174
|
-
# Production setup
|
|
175
|
-
server = bot.webhook_server(
|
|
176
|
-
port: ENV['PORT'] || 3000,
|
|
177
|
-
endpoint: Async::HTTP::Endpoint.parse("https://#{ENV['DOMAIN']}")
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
# Set webhook automatically
|
|
181
|
-
bot.set_webhook(
|
|
182
|
-
url: "https://#{ENV['DOMAIN']}/webhook/#{bot.token}",
|
|
183
|
-
max_connections: 40
|
|
184
|
-
)
|
|
185
|
-
|
|
186
|
-
server.run
|
|
187
|
-
end
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
Docker Deployment
|
|
191
|
-
|
|
192
|
-
```dockerfile
|
|
193
|
-
FROM ruby:3.2-alpine
|
|
194
|
-
WORKDIR /app
|
|
195
|
-
COPY Gemfile Gemfile.lock ./
|
|
196
|
-
RUN bundle install
|
|
197
|
-
COPY . .
|
|
198
|
-
CMD ["ruby", "bot.rb"]
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
---
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
---
|
|
205
|
-
|
|
206
|
-
📦 Project Structure
|
|
207
|
-
|
|
208
|
-
```
|
|
209
|
-
my_bot/
|
|
210
|
-
├── bot.rb # Main bot file
|
|
211
|
-
├── Gemfile
|
|
212
|
-
├── config/
|
|
213
|
-
│ ├── initializers/ # Middleware, database setup
|
|
214
|
-
│ └── environments/ # Development/production configs
|
|
215
|
-
├── lib/
|
|
216
|
-
│ ├── middleware/ # Custom middleware classes
|
|
217
|
-
│ ├── scenes/ # Scene definitions
|
|
218
|
-
│ └── services/ # Business logic
|
|
219
|
-
├── db/ # Database migrations
|
|
220
|
-
└── spec/ # Tests
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
---
|
|
224
|
-
|
|
225
|
-
[🤝 contributing](https://gitlab.com/ruby-telegem/telegem/-/blob/main/Contributing.md)
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
Development Setup:
|
|
230
|
-
|
|
231
|
-
```bash
|
|
232
|
-
git clone https://gitlab.com/ruby-telegem/telegem.git
|
|
233
|
-
cd telegem
|
|
234
|
-
bundle install
|
|
235
|
-
rake spec # Run tests
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
Need Help?
|
|
239
|
-
|
|
240
|
-
- Issues - Bug reports and feature requests
|
|
241
|
-
- Merge Requests - Code contributions
|
|
242
|
-
- Discussions - Questions and ideas
|
|
243
|
-
|
|
244
|
-
---
|
|
245
|
-
|
|
246
|
-
🚧 Roadmap
|
|
247
|
-
|
|
248
|
-
Coming Soon
|
|
249
|
-
|
|
250
|
-
- Plugin System - Community plugins ecosystem
|
|
251
|
-
- More Session Stores - PostgreSQL, MySQL, MongoDB
|
|
252
|
-
- Built-in Analytics - Usage tracking & insights
|
|
253
|
-
- Admin Dashboard - Web interface for bot management
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
---
|
|
257
|
-
|
|
258
|
-
📄 License
|
|
259
|
-
|
|
260
|
-
MIT License - see LICENSE.txt for details.
|
|
261
|
-
|
|
262
|
-
---
|
|
263
|
-
|
|
264
|
-
🙏 Acknowledgments
|
|
265
|
-
|
|
266
|
-
- Inspired by Telegraf.js - Amazing Node.js Telegram framework
|
|
267
|
-
- Built on async - Ruby's async I/O gem
|
|
268
|
-
- Thanks to the Telegram team for the excellent Bot API
|
|
269
|
-
- Community - All contributors and users
|
|
270
|
-
|
|
271
|
-
---
|
|
272
|
-
|
|
273
|
-
🌟 Star History
|
|
274
|
-
|
|
275
|
-
[history](https://api.star-history.com/svg?repos=ruby-telegem/telegem&type=Date)
|
|
276
|
-
|
|
277
|
-
---
|
|
278
|
-
|
|
279
|
-
📞 Support & Community
|
|
280
|
-
|
|
281
|
-
- GitLab Issues: Report bugs & request features
|
|
282
|
-
- Examples: Example bots repository
|
|
283
|
-
- Chat: Join our community (Telegram group)
|
|
284
|
-
|
|
285
|
-
---
|
|
286
|
-
|
|
287
|
-
🎉 Ready to Build?
|
|
288
|
-
|
|
289
|
-
```bash
|
|
290
|
-
# Start building your bot now!
|
|
291
|
-
gem install telegem
|
|
292
|
-
ruby -r telegem -e "puts 'Welcome to Telegem! 🚀'"
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
---
|
|
297
|
-
|
|
298
|
-
Built with ❤️ for the Ruby community. Happy bot building! 🤖✨
|
data/bin/telegem-init
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# bin/telegem-init
|
|
3
|
-
|
|
4
|
-
require 'fileutils'
|
|
5
|
-
|
|
6
|
-
puts " Creating a telegem application..."
|
|
7
|
-
|
|
8
|
-
# Create the nested directory structure
|
|
9
|
-
FileUtils.mkdir_p("src/handlers")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
code = <<~RUBY
|
|
13
|
-
require 'telegem'
|
|
14
|
-
require 'dotenv/load'
|
|
15
|
-
|
|
16
|
-
# Load all handlers from the handlers directory relative to this file
|
|
17
|
-
Dir[File.join(__dir__, 'handlers', '*.rb')].each { |file| require file }
|
|
18
|
-
|
|
19
|
-
bot = Telegem.new(ENV['BOT_TOKEN'])
|
|
20
|
-
|
|
21
|
-
puts "Bot is starting..."
|
|
22
|
-
bot.start_polling
|
|
23
|
-
RUBY
|
|
24
|
-
|
|
25
|
-
File.write('src/bot.rb', code)
|
|
26
|
-
|
|
27
|
-
# Optional: Create a blank .env file so the bot doesn't crash on load
|
|
28
|
-
File.write('.env', "BOT_TOKEN=your_token_here") unless File.exist?('.env')
|
|
29
|
-
|
|
30
|
-
puts "Successfully created src/bot.rb"
|
|
31
|
-
puts " Structure created: src/handlers/"
|
|
32
|
-
puts " Done working. Run your bot with: ruby src/bot.rb"
|
data/examples/.gitkeep
DELETED
|
File without changes
|
data/public/.gitkeep
DELETED
|
File without changes
|