telegem 2.0.8 โ†’ 2.0.9

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/Test-Projects/Movie-tracker-bot/Gemfile +2 -0
  3. data/Test-Projects/Movie-tracker-bot/bot.rb +62 -0
  4. data/Test-Projects/Movie-tracker-bot/handlers/.gitkeep +0 -0
  5. data/Test-Projects/Movie-tracker-bot/handlers/add_1_.rb +160 -0
  6. data/Test-Projects/Movie-tracker-bot/handlers/add_2_.rb +139 -0
  7. data/Test-Projects/Movie-tracker-bot/handlers/premium.rb +13 -0
  8. data/Test-Projects/Movie-tracker-bot/handlers/report.rb +31 -0
  9. data/Test-Projects/Movie-tracker-bot/handlers/search.rb +150 -0
  10. data/Test-Projects/Movie-tracker-bot/handlers/sponsor.rb +14 -0
  11. data/Test-Projects/Movie-tracker-bot/handlers/start.rb +48 -0
  12. data/Test-Projects/Movie-tracker-bot/handlers/watch.rb +210 -0
  13. data/Test-Projects/Test-submitted-by-marvel/.gitkeep +0 -0
  14. data/Test-Projects/Test-submitted-by-marvel/Marvel-bot.md +3 -0
  15. data/docs-src/.gitkeep +0 -0
  16. data/docs-src/Bot-registration_.PNG +0 -0
  17. data/docs-src/bot.md +295 -0
  18. data/docs-src/context|ctx|.md +531 -0
  19. data/docs-src/getting-started.md +328 -0
  20. data/docs-src/keyboard_inline.md +413 -0
  21. data/docs-src/scene.md +509 -0
  22. data/docs-src/understanding-ctx.md +581 -0
  23. data/lib/api/client.rb +3 -0
  24. data/lib/core/bot.rb +31 -27
  25. data/lib/telegem.rb +1 -1
  26. data/lib/webhook/server.rb +1 -1
  27. metadata +26 -15
  28. data/docs/Api.md +0 -211
  29. data/docs/Cookbook(copy_paste).md +0 -644
  30. data/docs/Getting_started.md +0 -348
  31. data/docs/How_to_use.md +0 -571
  32. data/docs/QuickStart.md +0 -258
  33. data/docs/Understanding_Scene.md +0 -434
  34. data/docs/Usage.md +0 -717
  35. data/docs/webhook_setup.md +0 -199
  36. /data/{docs โ†’ Test-Projects/Movie-tracker-bot}/.gitkeep +0 -0
@@ -0,0 +1,328 @@
1
+
2
+ # Getting Started with Telegem ๐Ÿš€
3
+
4
+ Build your first Telegram bot in 5 minutes with Ruby!
5
+
6
+ ## ๐Ÿ“‹ Prerequisites
7
+
8
+ ### 1. Install Ruby
9
+ ```bash
10
+ # Check your Ruby version
11
+ ruby --version
12
+ # Should be 2.7 or higher (Ruby 3.0+ recommended)
13
+ ```
14
+
15
+ 2. Install Bundler (Optional but recommended)
16
+
17
+ ```bash
18
+ gem install bundler
19
+ ```
20
+
21
+ ๐ŸŽฏ Quick Start - Your First Bot in 5 Minutes
22
+
23
+ Step 1: Get Your Bot Token
24
+
25
+ 1. Open Telegram, search for @BotFather
26
+ 2. Send /newbot and follow the prompts
27
+ 3. Copy your token (looks like: 1234567890:ABCdefGHIjklMNOpqrsTUVwxyz)
28
+
29
+ <img src="Bot-registration_.PNG" width="600" alt="BotFather Conversation">
30
+
31
+
32
+ Step 2: Create Your Bot
33
+
34
+ Option A: Using Bundler (Recommended)
35
+
36
+ ```bash
37
+ # Create a new directory
38
+ mkdir my-telegram-bot
39
+ cd my-telegram-bot
40
+
41
+ # Create Gemfile
42
+ echo "source 'https://rubygems.org'
43
+ gem 'telegem'" > Gemfile
44
+
45
+ # Install gem
46
+ bundle install
47
+ ```
48
+
49
+ Option B: Direct Install
50
+
51
+ ```bash
52
+ gem install telegem
53
+ ```
54
+
55
+ Step 3: Write Your Bot Code
56
+
57
+ Create bot.rb:
58
+
59
+ ```ruby
60
+ require 'telegem'
61
+
62
+ # Initialize with your token
63
+ bot = Telegem.new(ENV['BOT_TOKEN'])
64
+
65
+ # Handle /start command
66
+ bot.command('start') do |ctx|
67
+ ctx.reply("Hello #{ctx.from.first_name}! ๐Ÿ‘‹")
68
+ ctx.reply("I'm your first Telegem bot!")
69
+ end
70
+
71
+ # Echo messages
72
+ bot.on(:message) do |ctx|
73
+ ctx.reply("You said: #{ctx.message.text}")
74
+ end
75
+
76
+ # Start the bot (polling mode for development)
77
+ bot.start_polling
78
+ ```
79
+
80
+ Step 4: Run Your Bot
81
+
82
+ ```bash
83
+ # Set your token (on Linux/Mac)
84
+ export BOT_TOKEN="your_token_here"
85
+
86
+ # On Windows:
87
+ # set BOT_TOKEN=your_token_here
88
+
89
+ # Run the bot
90
+ ruby bot.rb
91
+ ```
92
+
93
+ Expected Output:
94
+
95
+ ```
96
+ ๐Ÿค– Starting Telegem bot (polling mode)...
97
+ โœ… Bot is running!
98
+ ```
99
+
100
+ Step 5: Test Your Bot
101
+
102
+ 1. Open Telegram, search for your bot (the username you gave @BotFather)
103
+ 2. Send /start
104
+ 3. You should see: "Hello [Your Name]! ๐Ÿ‘‹"
105
+
106
+ ๐ŸŽ‰ Congratulations! Your bot is alive!
107
+
108
+ ๐Ÿš€ Next Steps
109
+
110
+ Choose Your Development Mode
111
+
112
+ Polling Mode (Development/Local)
113
+
114
+ ```ruby
115
+ # Good for testing
116
+ bot.start_polling(
117
+ timeout: 30,
118
+ limit: 100
119
+ )
120
+ ```
121
+
122
+ Webhook Mode (Production)
123
+
124
+ ```ruby
125
+ # One line - auto-detects cloud platform
126
+ bot.webhook.run
127
+ # Works with: Render, Railway, Heroku, Fly.io
128
+ ```
129
+
130
+ Add More Features
131
+
132
+ Keyboard Example:
133
+
134
+ ```ruby
135
+ bot.command('menu') do |ctx|
136
+ keyboard = Telegem.keyboard do
137
+ row "Option 1", "Option 2"
138
+ row "Cancel"
139
+ end
140
+
141
+ ctx.reply("Choose an option:", reply_markup: keyboard)
142
+ end
143
+ ```
144
+
145
+ Inline Keyboard Example:
146
+
147
+ ```ruby
148
+ bot.command('vote') do |ctx|
149
+ inline = Telegem.inline do
150
+ row button "๐Ÿ‘ Like", callback_data: "like"
151
+ row button "๐Ÿ‘Ž Dislike", callback_data: "dislike"
152
+ end
153
+
154
+ ctx.reply("Rate this:", reply_markup: inline)
155
+ end
156
+
157
+ # Handle button clicks
158
+ bot.on(:callback_query) do |ctx|
159
+ ctx.answer_callback_query(text: "Thanks for voting!")
160
+ end
161
+ ```
162
+
163
+ ๐Ÿ“ Project Structure
164
+
165
+ For larger projects, organize your code:
166
+
167
+ ```
168
+ my-bot/
169
+ โ”œโ”€โ”€ bot.rb # Main entry point
170
+ โ”œโ”€โ”€ Gemfile
171
+ โ”œโ”€โ”€ Gemfile.lock
172
+ โ”œโ”€โ”€ config/
173
+ โ”‚ โ””โ”€โ”€ environment.rb # Load environment
174
+ โ”œโ”€โ”€ handlers/
175
+ โ”‚ โ”œโ”€โ”€ commands.rb # Command handlers
176
+ โ”‚ โ”œโ”€โ”€ messages.rb # Message handlers
177
+ โ”‚ โ””โ”€โ”€ callbacks.rb # Callback handlers
178
+ โ””โ”€โ”€ .env # Environment variables
179
+ ```
180
+
181
+ Example modular structure: See examples/modular-bot
182
+
183
+ ๐Ÿ”ง Configuration
184
+
185
+ Environment Variables
186
+
187
+ Create .env file:
188
+
189
+ ```bash
190
+ BOT_TOKEN=your_token_here
191
+ RACK_ENV=development
192
+ PORT=3000
193
+ ```
194
+
195
+ Load with dotenv gem:
196
+
197
+ ```ruby
198
+ # Gemfile
199
+ gem 'dotenv', groups: [:development, :test]
200
+
201
+ # In your bot.rb
202
+ require 'dotenv'
203
+ Dotenv.load
204
+ ```
205
+
206
+ Bot Options
207
+
208
+ ```ruby
209
+ bot = Telegem.new(ENV['BOT_TOKEN'],
210
+ logger: Logger.new('bot.log'), # Custom logger
211
+ timeout: 60, # API timeout
212
+ max_threads: 20, # Worker threads
213
+ session_store: custom_store # Custom session storage
214
+ )
215
+ ```
216
+
217
+ ๐Ÿ› Troubleshooting
218
+
219
+ Common Issues
220
+
221
+ 1. Bot not responding?
222
+
223
+ ```bash
224
+ # Check if bot is running
225
+ ps aux | grep ruby
226
+
227
+ # Check logs
228
+ tail -f bot.log
229
+ ```
230
+
231
+ 2. Token invalid?
232
+
233
+ ยท Verify with @BotFather using /token
234
+ ยท Make sure token starts with numbers and has a colon
235
+
236
+ 3. Webhook failing on cloud platforms?
237
+
238
+ ยท Set PORT environment variable
239
+ ยท Enable "Always On" on Render ($7/month)
240
+ ยท Check platform logs
241
+
242
+ 4. Getting rate limited?
243
+
244
+ ```ruby
245
+ bot.start_polling(
246
+ timeout: 30, # Increase timeout
247
+ limit: 10 # Reduce updates per request
248
+ )
249
+ ```
250
+
251
+ ๐ŸŽฎ Example Bots
252
+
253
+ See real working bots built with Telegem:
254
+
255
+ Beginner Examples
256
+
257
+ ยท Echo Bot - Simple message repeater
258
+ ยท Pizza Order Bot - Food ordering with scenes
259
+ ยท Survey Bot - Multi-question surveys
260
+
261
+ Intermediate Examples
262
+
263
+ ยท Crypto Price Bot - Real-time price updates
264
+ ยท File Converter Bot - Convert images/PDFs
265
+ ยท GitHub Notifier - GitHub webhook receiver
266
+
267
+ Advanced Examples
268
+
269
+ ยท E-commerce Store - Full shopping experience
270
+ ยท Multi-language Support Bot - Supports 5 languages
271
+ ยท AI Chat Bot - OpenAI integration
272
+
273
+ (Links will be added as community builds bots! Submit yours via PR!)
274
+
275
+ ๐Ÿ“š Learning Path
276
+
277
+ 1. Week 1: Build echo bot, menu bot
278
+ 2. Week 2: Add database, user sessions
279
+ 3. Week 3: Deploy to Render/Railway
280
+ 4. Week 4: Integrate external APIs (weather, news, etc.)
281
+
282
+ ๐Ÿ†˜ Need Help?
283
+
284
+ Quick Questions
285
+
286
+ 1. Check the API Reference
287
+ 2. Look at examples/
288
+ 3. Search GitHub Issues
289
+
290
+ Community Support
291
+
292
+ ยท GitHub Discussions: Ask questions
293
+ ยท Stack Overflow: Use tag [telegem]
294
+ ยท Telegram Group: @telegem_ruby
295
+
296
+ ๐Ÿš€ Ready for Production?
297
+
298
+ Deployment Checklist
299
+
300
+ ยท Use webhook mode (bot.webhook.run)
301
+ ยท Set up environment variables
302
+ ยท Add error monitoring (Sentry, etc.)
303
+ ยท Configure logging
304
+ ยท Set up backup for session data
305
+
306
+ One-Click Deploy
307
+
308
+ https://render.com/images/deploy-to-render-button.svg
309
+ https://railway.app/button.svg
310
+
311
+ ๐Ÿ“ What's Next?
312
+
313
+ 1. Master Scenes for multi-step conversations
314
+ 2. Add Database for persistent storage
315
+ 3. Integrate Payments for monetization
316
+ 4. Build Admin Panel for bot management
317
+
318
+ ---
319
+
320
+ Built something cool? Submit your bot to examples/ via Pull Request!
321
+
322
+ Need a feature? Open a GitHub Issue
323
+
324
+ Found a bug? Report it with reproduction steps
325
+
326
+ ---
327
+
328
+ Happy building! ๐ŸŽ‰ Your Telegram bot journey starts here!