telegem 0.2.5 โ 1.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/.replit +13 -0
- data/Contributing.md +553 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +11 -0
- data/LICENSE +21 -0
- data/Readme.md +353 -0
- data/Test-Projects/.gitkeep +0 -0
- data/Test-Projects/bot_test1.rb +75 -0
- data/Test-Projects/pizza_test_bot_guide.md +163 -0
- data/docs/.gitkeep +0 -0
- data/docs/Api.md +419 -0
- data/docs/Cookbook.md +407 -0
- data/docs/How_to_use.md +571 -0
- data/docs/QuickStart.md +258 -0
- data/docs/Usage.md +717 -0
- data/lib/api/client.rb +89 -116
- data/lib/core/bot.rb +103 -92
- data/lib/core/composer.rb +36 -18
- data/lib/core/context.rb +180 -177
- data/lib/core/scene.rb +81 -71
- data/lib/session/memory_store.rb +1 -1
- data/lib/session/middleware.rb +20 -36
- data/lib/telegem.rb +57 -54
- data/lib/webhook/.gitkeep +0 -0
- data/lib/webhook/server.rb +193 -0
- metadata +38 -35
- data/telegem.gemspec +0 -43
- data/webhook/server.rb +0 -86
data/docs/How_to_use.md
ADDED
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
๐ How to Use Telegem: Your Friendly Guide
|
|
2
|
+
|
|
3
|
+
Welcome! This guide will walk you through everything Telegem can do, step by step. No prior bot experience needed!
|
|
4
|
+
|
|
5
|
+
๐ How This Guide Works
|
|
6
|
+
|
|
7
|
+
We'll learn by doing! Each section has:
|
|
8
|
+
|
|
9
|
+
ยท ๐งช Try This - Hands-on examples in IRB (Ruby's interactive console)
|
|
10
|
+
ยท ๐ก What's Happening - Plain English explanations
|
|
11
|
+
ยท ๐ง Real Example - Practical bot code you can use
|
|
12
|
+
ยท ๐ Key Points - Important things to remember
|
|
13
|
+
|
|
14
|
+
Ready? Let's begin our bot-building journey! ๐
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
๐ Part 1: Your First Bot (5 Minutes)
|
|
19
|
+
|
|
20
|
+
๐งช Try This First:
|
|
21
|
+
|
|
22
|
+
Open your terminal and type:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
irb
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Then type (or copy-paste):
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
require 'telegem'
|
|
32
|
+
puts "โ
Telegem loaded! Version: #{Telegem::VERSION}"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
You should see: โ
Telegem loaded! Version: 0.1.2
|
|
36
|
+
|
|
37
|
+
๐ก What's Happening:
|
|
38
|
+
|
|
39
|
+
You just loaded the Telegem library! This is like opening a toolbox before building something. The library is now ready to use in your Ruby session.
|
|
40
|
+
|
|
41
|
+
๐ง Real Example:
|
|
42
|
+
|
|
43
|
+
Let's create the simplest possible bot:
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
# simplest_bot.rb
|
|
47
|
+
require 'telegem'
|
|
48
|
+
|
|
49
|
+
# Create your bot (replace with real token)
|
|
50
|
+
bot = Telegem.new('YOUR_TOKEN_HERE')
|
|
51
|
+
|
|
52
|
+
# Add a command
|
|
53
|
+
bot.command('start') do |ctx|
|
|
54
|
+
ctx.reply "Hello! I'm alive! ๐"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Start listening for messages
|
|
58
|
+
bot.start_polling
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
๐ Key Points:
|
|
62
|
+
|
|
63
|
+
1. Every bot needs a token (from @BotFather on Telegram)
|
|
64
|
+
2. Commands start with / like /start, /help
|
|
65
|
+
3. ctx means "context" - it's your control panel for that chat
|
|
66
|
+
4. ctx.reply sends a message back
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
๐งฉ Part 2: Understanding the "Context" (ctx)
|
|
71
|
+
|
|
72
|
+
Think of ctx as your bot's hands and eyes in a conversation. It can:
|
|
73
|
+
|
|
74
|
+
ยท See the message
|
|
75
|
+
ยท Know who sent it
|
|
76
|
+
ยท Send replies
|
|
77
|
+
ยท Remember things
|
|
78
|
+
|
|
79
|
+
๐งช Try This in IRB:
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
# Let's explore what ctx can do
|
|
83
|
+
class MockContext
|
|
84
|
+
def from
|
|
85
|
+
OpenStruct.new(first_name: "Alex", id: 12345)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def chat
|
|
89
|
+
OpenStruct.new(id: 999, type: "private")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def message
|
|
93
|
+
OpenStruct.new(text: "/start", command?: true)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
ctx = MockContext.new
|
|
98
|
+
puts "User: #{ctx.from.first_name}"
|
|
99
|
+
puts "Chat ID: #{ctx.chat.id}"
|
|
100
|
+
puts "Is command? #{ctx.message.command?}"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
๐ก What ctx Contains:
|
|
104
|
+
|
|
105
|
+
ยท ctx.from - Who sent the message (name, ID, username)
|
|
106
|
+
ยท ctx.chat - Where it was sent (private chat, group, channel)
|
|
107
|
+
ยท ctx.message - The actual message text
|
|
108
|
+
ยท ctx.reply - Method to send messages back
|
|
109
|
+
ยท ctx.session - Memory for this user (more on this later!)
|
|
110
|
+
|
|
111
|
+
๐ง Real Example - Personal Greeting:
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
bot.command('hello') do |ctx|
|
|
115
|
+
# Use ctx.from to personalize
|
|
116
|
+
name = ctx.from.first_name
|
|
117
|
+
ctx.reply "Hi #{name}! ๐ Nice to meet you!"
|
|
118
|
+
|
|
119
|
+
# Use ctx.chat to know where we are
|
|
120
|
+
if ctx.chat.type == "group"
|
|
121
|
+
ctx.reply "Thanks for adding me to this group!"
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
๐ฃ๏ธ Part 3: Handling Different Message Types
|
|
129
|
+
|
|
130
|
+
Bots can handle more than just commands! Here's what you can listen for:
|
|
131
|
+
|
|
132
|
+
1. Commands (Start with /)
|
|
133
|
+
|
|
134
|
+
```ruby
|
|
135
|
+
bot.command('help') do |ctx|
|
|
136
|
+
ctx.reply "I'm here to help!"
|
|
137
|
+
end
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
2. Text Messages (Any text)
|
|
141
|
+
|
|
142
|
+
```ruby
|
|
143
|
+
bot.on(:message) do |ctx|
|
|
144
|
+
# Skip commands (they're handled above)
|
|
145
|
+
next if ctx.message.command?
|
|
146
|
+
|
|
147
|
+
user_text = ctx.message.text
|
|
148
|
+
ctx.reply "You said: #{user_text}"
|
|
149
|
+
end
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
3. Button Clicks (Inline keyboard buttons)
|
|
153
|
+
|
|
154
|
+
```ruby
|
|
155
|
+
bot.on(:callback_query) do |ctx|
|
|
156
|
+
# ctx.data contains what button was clicked
|
|
157
|
+
button_data = ctx.data
|
|
158
|
+
ctx.reply "You clicked: #{button_data}"
|
|
159
|
+
end
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
๐งช Try This Pattern:
|
|
163
|
+
|
|
164
|
+
```ruby
|
|
165
|
+
bot.on(:message) do |ctx|
|
|
166
|
+
if ctx.message.command?
|
|
167
|
+
puts "It's a command!"
|
|
168
|
+
elsif ctx.message.text.include?("?")
|
|
169
|
+
puts "It's a question!"
|
|
170
|
+
else
|
|
171
|
+
puts "Regular message"
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
๐จ Part 4: Making Interactive Bots (Keyboards!)
|
|
179
|
+
|
|
180
|
+
Why Keyboards?
|
|
181
|
+
|
|
182
|
+
Instead of typing commands, users can click buttons! Two types:
|
|
183
|
+
|
|
184
|
+
1. Reply Keyboard (Appears at bottom)
|
|
185
|
+
|
|
186
|
+
```ruby
|
|
187
|
+
keyboard = Telegem::Markup.keyboard do
|
|
188
|
+
row "Yes", "No", "Maybe"
|
|
189
|
+
row "Cancel"
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
ctx.reply "Do you agree?", reply_markup: keyboard
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
2. Inline Keyboard (Appears in message)
|
|
196
|
+
|
|
197
|
+
```ruby
|
|
198
|
+
inline = Telegem::Markup.inline do
|
|
199
|
+
row callback("๐ Like", "like_123"),
|
|
200
|
+
callback("๐ Dislike", "dislike_123")
|
|
201
|
+
row url("๐ Website", "https://example.com")
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
ctx.reply "Rate this:", reply_markup: inline
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
๐งช Try Building a Menu:
|
|
208
|
+
|
|
209
|
+
```ruby
|
|
210
|
+
# In IRB, try building this menu
|
|
211
|
+
require 'telegem'
|
|
212
|
+
|
|
213
|
+
menu = Telegem::Markup.keyboard do
|
|
214
|
+
row "๐ Pizza", "๐ Burger", "๐ฎ Taco"
|
|
215
|
+
row "๐ฅค Drinks", "๐ฐ Dessert"
|
|
216
|
+
row "๐ Call Staff", "โ Cancel"
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
puts "Your menu looks like:"
|
|
220
|
+
puts menu.to_h
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
๐พ Part 5: Remembering Things (Sessions)
|
|
226
|
+
|
|
227
|
+
Bots have short-term memory! This is called "session."
|
|
228
|
+
|
|
229
|
+
The Magic of ctx.session:
|
|
230
|
+
|
|
231
|
+
```ruby
|
|
232
|
+
bot.command('counter') do |ctx|
|
|
233
|
+
# Initialize if first time
|
|
234
|
+
ctx.session[:count] ||= 0
|
|
235
|
+
|
|
236
|
+
# Increase counter
|
|
237
|
+
ctx.session[:count] += 1
|
|
238
|
+
|
|
239
|
+
ctx.reply "You've used this command #{ctx.session[:count]} times!"
|
|
240
|
+
end
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
What Can You Store?
|
|
244
|
+
|
|
245
|
+
ยท Preferences (language, theme)
|
|
246
|
+
ยท Shopping carts (items being purchased)
|
|
247
|
+
ยท Game scores (points, levels)
|
|
248
|
+
ยท Form data (half-filled applications)
|
|
249
|
+
|
|
250
|
+
๐งช Try Session in IRB:
|
|
251
|
+
|
|
252
|
+
```ruby
|
|
253
|
+
# Simulate how session works
|
|
254
|
+
session = {}
|
|
255
|
+
|
|
256
|
+
# First visit
|
|
257
|
+
session[:visits] ||= 0
|
|
258
|
+
session[:visits] += 1
|
|
259
|
+
puts "Visit #{session[:visits]}"
|
|
260
|
+
|
|
261
|
+
# Second "visit"
|
|
262
|
+
session[:visits] += 1
|
|
263
|
+
puts "Visit #{session[:visits]}"
|
|
264
|
+
|
|
265
|
+
# It remembers!
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
๐ง Part 6: Multi-Step Conversations (Scenes)
|
|
271
|
+
|
|
272
|
+
Sometimes you need back-and-forth conversations. That's where Scenes shine!
|
|
273
|
+
|
|
274
|
+
Real World Example - Pizza Order:
|
|
275
|
+
|
|
276
|
+
1. Bot: "What pizza do you want?"
|
|
277
|
+
2. User: "Pepperoni"
|
|
278
|
+
3. Bot: "What size?"
|
|
279
|
+
4. User: "Large"
|
|
280
|
+
5. Bot: "Confirm order?"
|
|
281
|
+
|
|
282
|
+
Each step is a Scene Step!
|
|
283
|
+
|
|
284
|
+
๐ง Scene Example:
|
|
285
|
+
|
|
286
|
+
```ruby
|
|
287
|
+
bot.scene :order_pizza do
|
|
288
|
+
step :ask_type do |ctx|
|
|
289
|
+
ctx.reply "What pizza do you want? (Margherita/Pepperoni/Veggie)"
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
step :save_type do |ctx|
|
|
293
|
+
# Save their choice
|
|
294
|
+
ctx.session[:pizza_type] = ctx.message.text
|
|
295
|
+
ctx.reply "Great! Now what size? (Small/Medium/Large)"
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
step :save_size do |ctx|
|
|
299
|
+
ctx.session[:size] = ctx.message.text
|
|
300
|
+
ctx.reply "Order confirmed: #{ctx.session[:size]} #{ctx.session[:pizza_type]}!"
|
|
301
|
+
ctx.leave_scene # Conversation done!
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
# Start the scene
|
|
306
|
+
bot.command('order') do |ctx|
|
|
307
|
+
ctx.enter_scene(:order_pizza)
|
|
308
|
+
end
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
๐ก Scene Thinking:
|
|
312
|
+
|
|
313
|
+
Scenes are like mini-programs inside your bot. Each has:
|
|
314
|
+
|
|
315
|
+
1. Steps - Questions to ask
|
|
316
|
+
2. Memory - Remembers answers
|
|
317
|
+
3. Flow - Goes from step to step automatically
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
๐ Part 7: Adding Superpowers (Middleware)
|
|
322
|
+
|
|
323
|
+
Middleware are plugins that run on every message. Think of them as filters or enhancers.
|
|
324
|
+
|
|
325
|
+
Simple Logger Middleware:
|
|
326
|
+
|
|
327
|
+
```ruby
|
|
328
|
+
bot.use do |ctx, next_middleware|
|
|
329
|
+
# Runs BEFORE handling the message
|
|
330
|
+
puts "#{Time.now} - #{ctx.from.first_name}: #{ctx.message&.text}"
|
|
331
|
+
|
|
332
|
+
# Pass to next middleware (or the command handler)
|
|
333
|
+
next_middleware.call(ctx)
|
|
334
|
+
|
|
335
|
+
# Runs AFTER handling
|
|
336
|
+
puts "Message handled!"
|
|
337
|
+
end
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Built-in Middleware You Get:
|
|
341
|
+
|
|
342
|
+
1. Session Middleware - Automatic ctx.session
|
|
343
|
+
2. Error Handler - Catch and report errors
|
|
344
|
+
3. Rate Limiter (coming soon!) - Prevent spam
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
๐ Part 8: Going Live (Webhooks vs Polling)
|
|
349
|
+
|
|
350
|
+
Two Ways to Run Your Bot:
|
|
351
|
+
|
|
352
|
+
1. Polling (Easy - for development)
|
|
353
|
+
|
|
354
|
+
```ruby
|
|
355
|
+
bot.start_polling # Checks for messages every second
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
Like checking your mailbox every minute
|
|
359
|
+
|
|
360
|
+
2. Webhooks (Better - for production)
|
|
361
|
+
|
|
362
|
+
```ruby
|
|
363
|
+
server = bot.webhook_server(port: 3000)
|
|
364
|
+
server.run # Telegram sends messages to you
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Like having a mail slot - messages arrive immediately
|
|
368
|
+
|
|
369
|
+
๐งช Understanding the Difference:
|
|
370
|
+
|
|
371
|
+
```ruby
|
|
372
|
+
# Polling (YOU ask Telegram)
|
|
373
|
+
# Bot: "Any new messages?"
|
|
374
|
+
# Telegram: "No"
|
|
375
|
+
# Bot: "How about now?"
|
|
376
|
+
# Telegram: "Still no"
|
|
377
|
+
# ... (every second)
|
|
378
|
+
|
|
379
|
+
# Webhook (Telegram tells YOU)
|
|
380
|
+
# *Message arrives*
|
|
381
|
+
# Telegram: "Hey bot, here's a message!"
|
|
382
|
+
# Bot: "Thanks, I'll handle it!"
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
๐จ Part 9: Handling Problems (Error Handling)
|
|
388
|
+
|
|
389
|
+
When Things Go Wrong:
|
|
390
|
+
|
|
391
|
+
```ruby
|
|
392
|
+
bot.error do |error, ctx|
|
|
393
|
+
# Log the error
|
|
394
|
+
puts "ERROR: #{error.class}: #{error.message}"
|
|
395
|
+
|
|
396
|
+
# Tell user (politely!)
|
|
397
|
+
ctx.reply "Oops! Something went wrong. Try again? ๐ค"
|
|
398
|
+
|
|
399
|
+
# Or notify admin
|
|
400
|
+
ctx.api.call('sendMessage',
|
|
401
|
+
chat_id: ADMIN_ID,
|
|
402
|
+
text: "Bot error: #{error.message}"
|
|
403
|
+
)
|
|
404
|
+
end
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
Common Errors & Fixes:
|
|
408
|
+
|
|
409
|
+
1. Invalid Token - Check @BotFather for correct token
|
|
410
|
+
2. Network Issues - Bot can't reach Telegram servers
|
|
411
|
+
3. Rate Limits - Too many messages too fast
|
|
412
|
+
4. Bad Parameters - Sending wrong data to API
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
๐ฏ Part 10: Your First Real Project
|
|
417
|
+
|
|
418
|
+
Let's build a Mood Tracker Bot:
|
|
419
|
+
|
|
420
|
+
```ruby
|
|
421
|
+
require 'telegem'
|
|
422
|
+
|
|
423
|
+
bot = Telegem.new(ENV['BOT_TOKEN'])
|
|
424
|
+
|
|
425
|
+
bot.command('start') do |ctx|
|
|
426
|
+
ctx.reply "Welcome to MoodTracker! ๐"
|
|
427
|
+
ctx.reply "How are you feeling?"
|
|
428
|
+
|
|
429
|
+
keyboard = Telegem::Markup.keyboard do
|
|
430
|
+
row "๐ Happy", "๐ข Sad", "๐ก Angry"
|
|
431
|
+
row "๐ด Tired", "๐ค Thoughtful", "๐ Excited"
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
ctx.reply "Choose your mood:", reply_markup: keyboard
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
bot.on(:message) do |ctx|
|
|
438
|
+
next if ctx.message.command?
|
|
439
|
+
|
|
440
|
+
mood = ctx.message.text
|
|
441
|
+
ctx.session[:moods] ||= []
|
|
442
|
+
ctx.session[:moods] << { mood: mood, time: Time.now }
|
|
443
|
+
|
|
444
|
+
ctx.reply "Noted: #{mood}"
|
|
445
|
+
ctx.reply "You've logged #{ctx.session[:moods].size} moods today!"
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
bot.command('stats') do |ctx|
|
|
449
|
+
moods = ctx.session[:moods] || []
|
|
450
|
+
|
|
451
|
+
if moods.empty?
|
|
452
|
+
ctx.reply "No moods logged yet!"
|
|
453
|
+
else
|
|
454
|
+
# Count each mood
|
|
455
|
+
counts = moods.group_by { |m| m[:mood] }
|
|
456
|
+
.transform_values(&:size)
|
|
457
|
+
|
|
458
|
+
stats = counts.map { |mood, count| "#{mood}: #{count}x" }.join("\n")
|
|
459
|
+
ctx.reply "Your mood stats:\n#{stats}"
|
|
460
|
+
end
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
bot.start_polling
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
What this bot teaches you:
|
|
467
|
+
|
|
468
|
+
ยท โ
Commands (/start, /stats)
|
|
469
|
+
ยท โ
Keyboards (mood selection)
|
|
470
|
+
ยท โ
Sessions (storing mood history)
|
|
471
|
+
ยท โ
Data processing (counting moods)
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
๐ Part 11: Where to Go From Here
|
|
476
|
+
|
|
477
|
+
You've Learned:
|
|
478
|
+
|
|
479
|
+
ยท โ
Basics - Creating bots, sending messages
|
|
480
|
+
ยท โ
Interaction - Keyboards, buttons, commands
|
|
481
|
+
ยท โ
Memory - Sessions, multi-step conversations
|
|
482
|
+
ยท โ
Structure - Middleware, error handling
|
|
483
|
+
ยท โ
Deployment - Polling vs webhooks
|
|
484
|
+
|
|
485
|
+
Next Steps:
|
|
486
|
+
|
|
487
|
+
Level 1: Beginner (You are here!)
|
|
488
|
+
|
|
489
|
+
ยท Build the Mood Tracker bot above
|
|
490
|
+
ยท Add 2 more commands
|
|
491
|
+
ยท Try adding a keyboard
|
|
492
|
+
|
|
493
|
+
Level 2: Intermediate
|
|
494
|
+
|
|
495
|
+
ยท Create a scene for something (quiz, survey, game)
|
|
496
|
+
ยท Add file upload support (photos, documents)
|
|
497
|
+
ยท Store data in a database (SQLite, PostgreSQL)
|
|
498
|
+
|
|
499
|
+
Level 3: Advanced
|
|
500
|
+
|
|
501
|
+
ยท Create your own middleware
|
|
502
|
+
ยท Add webhook support with SSL
|
|
503
|
+
ยท Build a plugin system
|
|
504
|
+
|
|
505
|
+
๐ Recommended Learning Path:
|
|
506
|
+
|
|
507
|
+
1. Week 1: Build 3 simple bots (echo, counter, menu)
|
|
508
|
+
2. Week 2: Add sessions to remember things
|
|
509
|
+
3. Week 3: Create a scene (quiz or order form)
|
|
510
|
+
4. Week 4: Deploy to a server (Heroku, Render)
|
|
511
|
+
|
|
512
|
+
---
|
|
513
|
+
|
|
514
|
+
๐ Getting Help
|
|
515
|
+
|
|
516
|
+
When You're Stuck:
|
|
517
|
+
|
|
518
|
+
1. Check the error message - It often tells you what's wrong
|
|
519
|
+
2. Add puts statements - See what's happening step by step
|
|
520
|
+
3. Simplify - Remove code until it works, then add back
|
|
521
|
+
4. Ask for help - Community is there for you!
|
|
522
|
+
|
|
523
|
+
Resources:
|
|
524
|
+
|
|
525
|
+
ยท This guide - Bookmark it!
|
|
526
|
+
ยท API Reference - For all methods and options
|
|
527
|
+
ยท Example bots - In the examples/ folder
|
|
528
|
+
ยท GitLab Issues - Ask questions, report bugs
|
|
529
|
+
|
|
530
|
+
---
|
|
531
|
+
|
|
532
|
+
โจ Final Words of Encouragement
|
|
533
|
+
|
|
534
|
+
Remember:
|
|
535
|
+
|
|
536
|
+
1. Every expert was once a beginner - The Telegraf.js creator started just like you
|
|
537
|
+
2. Bugs are normal - Even big projects have them
|
|
538
|
+
3. Progress, not perfection - Each bot you build makes you better
|
|
539
|
+
4. You found this - That means you can definitely use it! ๐
|
|
540
|
+
|
|
541
|
+
Your First Mission:
|
|
542
|
+
|
|
543
|
+
```ruby
|
|
544
|
+
# Right now, create this file and run it
|
|
545
|
+
# bot_mission.rb
|
|
546
|
+
require 'telegem'
|
|
547
|
+
|
|
548
|
+
bot = Telegem.new('YOUR_TOKEN')
|
|
549
|
+
|
|
550
|
+
bot.command('mission') do |ctx|
|
|
551
|
+
ctx.reply "๐ฏ Mission accomplished!"
|
|
552
|
+
ctx.reply "You just built and ran your first bot!"
|
|
553
|
+
ctx.reply "Next: Try changing the message above."
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
bot.start_polling
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
Run it. See it work. You're a bot developer now! ๐
|
|
560
|
+
|
|
561
|
+
---
|
|
562
|
+
|
|
563
|
+
๐ Ready for More?
|
|
564
|
+
|
|
565
|
+
For advanced topics, API details, and complex examples:
|
|
566
|
+
|
|
567
|
+
๐ Check out USAGE.md for advanced patterns!
|
|
568
|
+
|
|
569
|
+
---
|
|
570
|
+
|
|
571
|
+
Happy bot building! Remember: Every great bot started with a single /start command. Your journey has begun! ๐
|