telegem 2.0.8 โ†’ 2.1.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.
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
@@ -1,348 +0,0 @@
1
-
2
- # ๐Ÿš€ Getting Started with Telegem
3
-
4
- Welcome to Telegem! This guide will help you build your first Telegram bot in minutes.
5
-
6
- ## ๐Ÿ“ฆ Installation
7
-
8
- Add to your `Gemfile`:
9
- ```ruby
10
- gem 'telegem'
11
- ```
12
-
13
- Or install directly:
14
-
15
- ```bash
16
- gem install telegem
17
- ```
18
-
19
- ๐Ÿค– Create Your First Bot
20
-
21
- 1. Get a Bot Token
22
-
23
- 1. Open Telegram, search for @BotFather
24
- 2. Send /newbot and follow instructions
25
- 3. Copy the token (looks like: 1234567890:ABCdefGHIjklMNOpqrsTUVwxyz)
26
-
27
- 2. Basic Bot Setup
28
-
29
- ```ruby
30
- require 'telegem'
31
-
32
- # Create bot instance
33
- bot = Telegem.new("YOUR_BOT_TOKEN")
34
-
35
- # Echo bot - replies with same message
36
- bot.on(:message) do |ctx|
37
- ctx.reply("You said: #{ctx.message.text}")
38
- end
39
-
40
- # Start polling (for development)
41
- bot.start_polling
42
- ```
43
-
44
- Save as bot.rb and run:
45
-
46
- ```bash
47
- ruby bot.rb
48
- ```
49
-
50
- ๐Ÿ“ Core Concepts
51
-
52
- Context (ctx)
53
-
54
- Every handler receives a Context object with everything you need:
55
-
56
- ```ruby
57
- bot.on(:message) do |ctx|
58
- ctx.reply("Hello!") # Send message
59
- ctx.chat.id # Chat ID: 123456789
60
- ctx.from.username # User: @username
61
- ctx.message.text # Message text
62
- ctx.message.command? # Is it a command?
63
- ctx.message.command_name # Command without "/"
64
- end
65
- ```
66
-
67
- Message Types
68
-
69
- ```ruby
70
- # Handle different update types
71
- bot.on(:message) { |ctx| } # Messages
72
- bot.on(:callback_query) { |ctx| } # Button clicks
73
- bot.on(:inline_query) { |ctx| } # Inline queries
74
- ```
75
-
76
- ๐ŸŽฏ Common Patterns
77
-
78
- 1. Command Handler
79
-
80
- ```ruby
81
- bot.command("start") do |ctx|
82
- ctx.reply("Welcome! Use /help to see commands.")
83
- end
84
-
85
- bot.command("help") do |ctx|
86
- help_text = <<~TEXT
87
- Available commands:
88
- /start - Start bot
89
- /help - Show this help
90
- /echo [text] - Echo text
91
- TEXT
92
- ctx.reply(help_text)
93
- end
94
- ```
95
-
96
- 2. Text Matching
97
-
98
- ```ruby
99
- # Regex pattern
100
- bot.hears(/hello|hi|hey/i) do |ctx|
101
- ctx.reply("Hello there! ๐Ÿ‘‹")
102
- end
103
-
104
- # String contains
105
- bot.on(:message, text: "ping") do |ctx|
106
- ctx.reply("pong! ๐Ÿ“")
107
- end
108
- ```
109
-
110
- 3. Send Media
111
-
112
- ```ruby
113
- bot.command("photo") do |ctx|
114
- ctx.photo("path/to/image.jpg", caption: "Nice pic!")
115
- end
116
-
117
- bot.command("document") do |ctx|
118
- ctx.document("file.pdf", caption: "Here's your PDF")
119
- end
120
- ```
121
-
122
- โŒจ๏ธ Keyboards
123
-
124
- Reply Keyboard (Shown below input)
125
-
126
- ```ruby
127
- bot.command("menu") do |ctx|
128
- keyboard = Telegem.keyboard do
129
- row "Option 1", "Option 2"
130
- row "Cancel"
131
- resize true # Fit to screen
132
- end
133
-
134
- ctx.reply("Choose option:", reply_markup: keyboard)
135
- end
136
- ```
137
-
138
- Inline Keyboard (Inside message)
139
-
140
- ```ruby
141
- bot.command("settings") do |ctx|
142
- inline = Telegem.inline do
143
- row do
144
- callback "Enable", "enable"
145
- callback "Disable", "disable"
146
- end
147
- row do
148
- url "Documentation", "https://gitlab.com/ruby-telegem/telegem"
149
- end
150
- end
151
-
152
- ctx.reply("Settings:", reply_markup: inline)
153
- end
154
-
155
- # Handle button clicks
156
- bot.on(:callback_query) do |ctx|
157
- if ctx.data == "enable"
158
- ctx.answer_callback_query(text: "Enabled!")
159
- ctx.edit_message_text("โœ… Settings enabled!")
160
- end
161
- end
162
- ```
163
-
164
- ๐ŸŽญ Scene System (Multi-step Conversations)
165
-
166
- ```ruby
167
- # Define a scene
168
- bot.scene("registration") do
169
- step :ask_name do |ctx|
170
- ctx.reply("What's your name?")
171
- next_step :ask_age
172
- end
173
-
174
- step :ask_age do |ctx|
175
- ctx.state[:name] = ctx.message.text
176
- ctx.reply("How old are you?")
177
- next_step :confirm
178
- end
179
-
180
- step :confirm do |ctx|
181
- ctx.state[:age] = ctx.message.text
182
- ctx.reply("Confirm: Name: #{ctx.state[:name]}, Age: #{ctx.state[:age]}")
183
- keyboard = Telegem.inline do
184
- row do
185
- callback "โœ… Confirm", "confirm_registration"
186
- callback "โŒ Cancel", "cancel_registration"
187
- end
188
- end
189
- ctx.reply("Is this correct?", reply_markup: keyboard)
190
- end
191
-
192
- on_enter do |ctx|
193
- ctx.reply("Starting registration...")
194
- end
195
- end
196
-
197
- # Start the scene
198
- bot.command("register") do |ctx|
199
- ctx.enter_scene("registration")
200
- end
201
- ```
202
-
203
- ๐Ÿ”ง Middleware (Global Handlers)
204
-
205
- ```ruby
206
- # Log all updates
207
- bot.use do |ctx, next_handler|
208
- puts "๐Ÿ“ฉ Update from #{ctx.from.username}: #{ctx.message&.text}"
209
- next_handler.call(ctx)
210
- end
211
-
212
- # Authentication middleware
213
- class AuthMiddleware
214
- def initialize(allowed_users)
215
- @allowed_users = allowed_users
216
- end
217
-
218
- def call(ctx, next_handler)
219
- if @allowed_users.include?(ctx.from.id)
220
- next_handler.call(ctx)
221
- else
222
- ctx.reply("๐Ÿšซ Access denied!")
223
- end
224
- end
225
- end
226
-
227
- bot.use(AuthMiddleware.new([123456789]))
228
- ```
229
-
230
- ๐Ÿ’พ Session Management
231
-
232
- ```ruby
233
- # Enable sessions (auto-saves user data)
234
- bot.command("counter") do |ctx|
235
- ctx.session[:count] ||= 0
236
- ctx.session[:count] += 1
237
- ctx.reply("Count: #{ctx.session[:count]}")
238
- end
239
-
240
- # Persistent across bot restarts
241
- bot.command("remember") do |ctx|
242
- ctx.session[:name] = ctx.message.text
243
- ctx.reply("I'll remember that!")
244
- end
245
-
246
- bot.command("recall") do |ctx|
247
- name = ctx.session[:name] || "I don't know your name"
248
- ctx.reply("Your name is: #{name}")
249
- end
250
- ```
251
-
252
- โ˜๏ธ Webhook Setup (Production)
253
-
254
- For Cloud Platforms (Render, Railway, Heroku):
255
-
256
- ```ruby
257
- # In config.ru or similar
258
- require 'telegem'
259
-
260
- bot = Telegem.new("YOUR_TOKEN")
261
- bot.on(:message) { |ctx| ctx.reply("Hello from webhook!") }
262
-
263
- # Auto-starts server and sets webhook
264
- server = Telegem.webhook(bot)
265
-
266
- # Or manually:
267
- # server = bot.webhook
268
- # server.run
269
- # server.set_webhook
270
- ```
271
-
272
- Environment Variables:
273
-
274
- ```bash
275
- export TELEGRAM_BOT_TOKEN="your_token"
276
- export PORT="3000" # Cloud platforms set this
277
- ```
278
-
279
- ๐Ÿš€ Deployment Quick Start
280
-
281
- 1. Create bot.rb:
282
-
283
- ```ruby
284
- require 'telegem'
285
-
286
- bot = Telegem.new(ENV['TELEGRAM_BOT_TOKEN'])
287
-
288
- bot.command("start") { |ctx| ctx.reply("Bot is running! ๐Ÿš€") }
289
- bot.on(:message) { |ctx| ctx.reply("Echo: #{ctx.message.text}") }
290
-
291
- # For webhook (production)
292
- if ENV['RACK_ENV'] == 'production'
293
- Telegem.webhook(bot)
294
- else
295
- # For local development
296
- bot.start_polling
297
- end
298
- ```
299
-
300
- 2. Create Gemfile:
301
-
302
- ```ruby
303
- source 'https://rubygems.org'
304
- gem 'telegem'
305
- ```
306
-
307
- 3. Create config.ru (for webhook):
308
-
309
- ```ruby
310
- require './bot'
311
- run ->(env) { [200, {}, ['']] }
312
- ```
313
-
314
- 4. Deploy to Render (Free):
315
-
316
- 1. Push to GitLab/GitHub
317
- 2. Go to render.com
318
- 3. New โ†’ Web Service โ†’ Connect repo
319
- 4. Set build command: bundle install
320
- 5. Set start command: bundle exec puma -p $PORT
321
- 6. Add env var: TELEGRAM_BOT_TOKEN=your_token
322
- 7. Deploy! ๐ŸŽ‰
323
-
324
- ๐Ÿ“š Next Steps
325
-
326
- Explore Examples:
327
-
328
- Check the examples/ directory for:
329
-
330
- ยท echo_bot.rb - Basic echo bot
331
- ยท keyboard_bot.rb - Interactive keyboards
332
- ยท scene_bot.rb - Multi-step conversations
333
- ยท webhook_bot.rb - Production webhook setup
334
-
335
- Need Help?
336
-
337
- ยท Documentation
338
- ยท Issue Tracker
339
- ยท Telegram: @sick_phantom
340
-
341
- ๐ŸŽ‰ Congratulations!
342
-
343
- You've built your first Telegram bot with Telegem! Now go build something amazing! ๐Ÿค–
344
-
345
- ---
346
-
347
- Telegem v2.0.0 โ€ข Made with โค๏ธ by sick_phantom
348
-