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,199 +0,0 @@
1
-
2
- # 🌐 Webhook Setup Guide for Telegem
3
-
4
- Webhooks are the **recommended way** to run your Telegram bot in production. Instead of your bot constantly asking Telegram for updates ("polling"), Telegram pushes updates directly to your bot's server.
5
-
6
- **Join the official channel for help and updates!** [![Official Telegem Channel](https://img.shields.io/badge/🚀-t.me/telegem__me2-blue?style=flat&logo=telegram)](https://t.me/telegem_me2)
7
-
8
- ## 🤔 Polling vs. Webhook: A Quick Analogy
9
- * **Polling** is like refreshing your email every 5 seconds to check for new messages. It works, but it's inefficient.
10
- * **Webhook** is like giving Telegram your email address and saying, "Send new messages directly to my inbox as they arrive." It's instant, efficient, and scales beautifully.
11
-
12
- ## 🚀 Quick-Start: One-Line Webhook Setup
13
-
14
- The easiest way to get a production webhook server running is with our `webhook` helper. It handles **everything**: starting the server, getting your public URL, and configuring Telegram.
15
-
16
- ```ruby
17
- require 'telegem'
18
-
19
- bot = Telegem.new("YOUR_BOT_TOKEN")
20
-
21
- bot.on(:message) do |ctx|
22
- ctx.reply("Hello from my webhook-powered bot! 🚀")
23
- end
24
-
25
- # This single line does the magic:
26
- # 1. Starts a production Puma web server
27
- # 2. Configures a secure webhook endpoint
28
- # 3. Tells Telegram where to send updates
29
- server = Telegem.webhook(bot)
30
- ```
31
-
32
- That's it! Your bot is now live with a webhook. The server runs in the background until you call server.stop.
33
-
34
- 🔧 Understanding the Setup (How it Works)
35
-
36
- Let's break down what the helper does. Here's the equivalent manual setup:
37
-
38
- ```ruby
39
- require 'telegem'
40
-
41
- bot = Telegem.new("YOUR_BOT_TOKEN")
42
- bot.on(:message) { |ctx| ctx.reply("Manual setup works!") }
43
-
44
- # 1. Create a webhook server instance
45
- server = bot.webhook(port: 3000) # Uses PORT env variable on cloud platforms
46
-
47
- # 2. Start the server (listens for incoming requests)
48
- server.run
49
-
50
- # 3. Tell Telegram your webhook URL with a secret token
51
- server.set_webhook
52
- ```
53
-
54
- What's happening behind the scenes?
55
-
56
- 1. Server Creation: Telegem creates a secure, production-ready Puma web server.
57
- 2. Endpoint Setup: It creates a /webhook endpoint that validates incoming requests using a secret_token (for security).
58
- 3. Cloud Detection: It automatically detects if you're running on Render, Railway, Heroku, Fly.io, or Vercel and configures the public URL accordingly.
59
- 4. Telegram Configuration: The set_webhook method registers your bot's public URL with Telegram's servers.
60
-
61
- ☁️ Deployment to Cloud Platforms
62
-
63
- Telegem's webhook server is optimized for modern cloud platforms. Here's how to deploy:
64
-
65
- Option A: Deploy to Render (Free Tier Friendly)
66
-
67
- 1. Create these files in your project:
68
- bot.rb
69
- ```ruby
70
- require 'telegem'
71
-
72
- bot = Telegem.new(ENV['TELEGRAM_BOT_TOKEN'])
73
-
74
- bot.command("start") { |ctx| ctx.reply("Bot is live on Render! ☁️") }
75
- bot.on(:message) { |ctx| ctx.reply("You said: #{ctx.message.text}") }
76
-
77
- # This auto-starts the webhook server in production
78
- Telegem.webhook(bot) if ENV['RACK_ENV'] == 'production'
79
- ```
80
- Gemfile
81
- ```ruby
82
- source 'https://rubygems.org'
83
- gem 'telegem'
84
- ```
85
- config.ru (required for Render to recognize it as a web service)
86
- ```ruby
87
- require './bot'
88
- # The server is started by Telegem.webhook
89
- run ->(env) { [200, {}, ['Telegem Bot Server']] }
90
- ```
91
- 2. Push to GitLab/GitHub.
92
- 3. On Render.com:
93
- · Click "New +" → "Web Service"
94
- · Connect your repository
95
- · Set the following:
96
- · Name: telegem-bot (or your choice)
97
- · Environment: Ruby
98
- · Build Command: bundle install
99
- · Start Command: bundle exec puma -p $PORT
100
- · Click "Advanced" and add an Environment Variable:
101
- · Key: TELEGRAM_BOT_TOKEN
102
- · Value: Your bot token from @BotFather
103
- 4. Click "Create Web Service". Your bot will build, deploy, and automatically configure its webhook!
104
-
105
- Option B: Deploy with Existing Rack Apps (Rails, Sinatra, etc.)
106
-
107
- If you already have a Rack application, use the Telegem Middleware:
108
-
109
- ```ruby
110
- # In your config.ru (or similar)
111
- require 'telegem'
112
- require './your_main_app'
113
-
114
- bot = Telegem.new(ENV['TELEGRAM_BOT_TOKEN'])
115
- bot.on(:message) { |ctx| ctx.reply("Hello from middleware!") }
116
-
117
- # Insert the middleware into your app's stack
118
- use Telegem::Webhook::Middleware, bot, secret_token: ENV['TELEGRAM_SECRET_TOKEN']
119
-
120
- run YourApp
121
- ```
122
-
123
- Then, set the webhook URL manually:
124
-
125
- ```ruby
126
- # Run this once (e.g., in a script or console)
127
- bot.set_webhook(
128
- url: "https://your-app.com/webhook",
129
- secret_token: ENV['TELEGRAM_SECRET_TOKEN']
130
- )
131
- ```
132
-
133
- 🔐 Security & Configuration
134
-
135
- Secret Token: Your Webhook's Bouncer
136
-
137
- The secret_token is a password that ensures only Telegram can talk to your webhook. Telegram sends it in the X-Telegram-Bot-Api-Secret-Token header with every request.
138
-
139
- · Generate a strong one: Use SecureRandom.hex(32).
140
- · Set it in production: Pass it when creating the server or via the TELEGRAM_SECRET_TOKEN environment variable.
141
- · Never commit it to git!
142
-
143
- Manual Webhook Management
144
-
145
- Use these methods for fine-grained control:
146
-
147
- ```ruby
148
- # Check your current webhook status
149
- info = bot.get_webhook_info
150
- puts info.url # => "https://your-app.com/webhook"
151
-
152
- # Delete the webhook (switch back to polling)
153
- bot.delete_webhook
154
-
155
- # Set a custom webhook with specific options
156
- bot.set_webhook(
157
- url: "https://api.example.com/custom-path",
158
- secret_token: "your_super_secret_token_here",
159
- max_connections: 40,
160
- allowed_updates: ["message", "callback_query"], # Only receive these updates
161
- drop_pending_updates: true # Clears old updates when setting
162
- )
163
- ```
164
-
165
- 🚨 Common Issues & Troubleshooting
166
-
167
- · "My bot works locally but not on Render!"
168
- · Check the Render logs for errors.
169
- · Ensure the TELEGRAM_BOT_TOKEN environment variable is set correctly in Render's dashboard.
170
- · Verify your bot's code doesn't have any syntax errors by running ruby bot.rb locally.
171
- · "I'm getting duplicate messages or missed updates!"
172
- · You likely have both polling and webhook active. Call bot.delete_webhook if you used start_polling before, or ensure you're not accidentally running start_polling in your webhook deployment.
173
- · "How do I update my bot's code?"
174
- · Simply push your changes to git. Your cloud platform (like Render) will automatically rebuild and redeploy. The webhook URL stays the same, so no reconfiguration is needed.
175
- · "I need to stop the webhook server."
176
- · Call server.stop on the server object, or send a SIGTERM signal to the process.
177
-
178
- 🧪 Testing Webhooks Locally
179
-
180
- For local development, you can still use polling. But if you want to test the webhook flow:
181
-
182
- 1. Use a tunneling service like ngrok:
183
- ```bash
184
- ngrok http 3000
185
- ```
186
- 2. Copy the HTTPS URL ngrok provides (e.g., https://abc123.ngrok.io).
187
- 3. Set your webhook manually:
188
- ```ruby
189
- bot.set_webhook(url: "https://abc123.ngrok.io/webhook")
190
- ```
191
- 4. Telegram will now send updates to your local machine through the tunnel!
192
-
193
- ---
194
-
195
- Pro Tip: The one-liner Telegem.webhook(bot) is perfect for 95% of use cases. It embodies the Telegem philosophy: powerful functionality with a simple, elegant API.
196
-
197
- For more help and community discussion, remember to join our official channel: https://img.shields.io/badge/💬-Join_t.me/telegem__me2-blue?style=flat&logo=telegram.
198
-
199
- Happy Building! The future of your Telegram bot is just a webhook away. 🚀
File without changes