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.
- checksums.yaml +4 -4
- data/Test-Projects/Movie-tracker-bot/Gemfile +2 -0
- data/Test-Projects/Movie-tracker-bot/bot.rb +62 -0
- data/Test-Projects/Movie-tracker-bot/handlers/.gitkeep +0 -0
- data/Test-Projects/Movie-tracker-bot/handlers/add_1_.rb +160 -0
- data/Test-Projects/Movie-tracker-bot/handlers/add_2_.rb +139 -0
- data/Test-Projects/Movie-tracker-bot/handlers/premium.rb +13 -0
- data/Test-Projects/Movie-tracker-bot/handlers/report.rb +31 -0
- data/Test-Projects/Movie-tracker-bot/handlers/search.rb +150 -0
- data/Test-Projects/Movie-tracker-bot/handlers/sponsor.rb +14 -0
- data/Test-Projects/Movie-tracker-bot/handlers/start.rb +48 -0
- data/Test-Projects/Movie-tracker-bot/handlers/watch.rb +210 -0
- data/Test-Projects/Test-submitted-by-marvel/.gitkeep +0 -0
- data/Test-Projects/Test-submitted-by-marvel/Marvel-bot.md +3 -0
- data/docs-src/.gitkeep +0 -0
- data/docs-src/Bot-registration_.PNG +0 -0
- data/docs-src/bot.md +295 -0
- data/docs-src/context|ctx|.md +531 -0
- data/docs-src/getting-started.md +328 -0
- data/docs-src/keyboard_inline.md +413 -0
- data/docs-src/scene.md +509 -0
- data/docs-src/understanding-ctx.md +581 -0
- data/lib/api/client.rb +3 -0
- data/lib/core/bot.rb +31 -27
- data/lib/telegem.rb +1 -1
- data/lib/webhook/server.rb +1 -1
- metadata +26 -15
- data/docs/Api.md +0 -211
- data/docs/Cookbook(copy_paste).md +0 -644
- data/docs/Getting_started.md +0 -348
- data/docs/How_to_use.md +0 -571
- data/docs/QuickStart.md +0 -258
- data/docs/Understanding_Scene.md +0 -434
- data/docs/Usage.md +0 -717
- data/docs/webhook_setup.md +0 -199
- /data/{docs → Test-Projects/Movie-tracker-bot}/.gitkeep +0 -0
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: telegem
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- sick_phantom
|
|
@@ -164,17 +164,30 @@ files:
|
|
|
164
164
|
- LICENSE
|
|
165
165
|
- Readme.md
|
|
166
166
|
- Test-Projects/.gitkeep
|
|
167
|
+
- Test-Projects/Movie-tracker-bot/.gitkeep
|
|
168
|
+
- Test-Projects/Movie-tracker-bot/Gemfile
|
|
169
|
+
- Test-Projects/Movie-tracker-bot/bot.rb
|
|
170
|
+
- Test-Projects/Movie-tracker-bot/handlers/.gitkeep
|
|
171
|
+
- Test-Projects/Movie-tracker-bot/handlers/add_1_.rb
|
|
172
|
+
- Test-Projects/Movie-tracker-bot/handlers/add_2_.rb
|
|
173
|
+
- Test-Projects/Movie-tracker-bot/handlers/premium.rb
|
|
174
|
+
- Test-Projects/Movie-tracker-bot/handlers/report.rb
|
|
175
|
+
- Test-Projects/Movie-tracker-bot/handlers/search.rb
|
|
176
|
+
- Test-Projects/Movie-tracker-bot/handlers/sponsor.rb
|
|
177
|
+
- Test-Projects/Movie-tracker-bot/handlers/start.rb
|
|
178
|
+
- Test-Projects/Movie-tracker-bot/handlers/watch.rb
|
|
179
|
+
- Test-Projects/Test-submitted-by-marvel/.gitkeep
|
|
180
|
+
- Test-Projects/Test-submitted-by-marvel/Marvel-bot.md
|
|
167
181
|
- Test-Projects/bot_test1.rb
|
|
168
182
|
- Test-Projects/pizza_test_bot_guide.md
|
|
169
|
-
- docs/.gitkeep
|
|
170
|
-
- docs/
|
|
171
|
-
- docs/
|
|
172
|
-
- docs/
|
|
173
|
-
- docs/
|
|
174
|
-
- docs/
|
|
175
|
-
- docs/
|
|
176
|
-
- docs/
|
|
177
|
-
- docs/webhook_setup.md
|
|
183
|
+
- docs-src/.gitkeep
|
|
184
|
+
- docs-src/Bot-registration_.PNG
|
|
185
|
+
- docs-src/bot.md
|
|
186
|
+
- docs-src/context|ctx|.md
|
|
187
|
+
- docs-src/getting-started.md
|
|
188
|
+
- docs-src/keyboard_inline.md
|
|
189
|
+
- docs-src/scene.md
|
|
190
|
+
- docs-src/understanding-ctx.md
|
|
178
191
|
- lib/api/client.rb
|
|
179
192
|
- lib/api/types.rb
|
|
180
193
|
- lib/core/bot.rb
|
|
@@ -196,11 +209,9 @@ metadata:
|
|
|
196
209
|
source_code_uri: https://gitlab.com/ruby-telegem/telegem
|
|
197
210
|
changelog_uri: https://gitlab.com/ruby-telegem/telegem/-/blob/main/CHANGELOG.md
|
|
198
211
|
bug_tracker_uri: https://gitlab.com/ruby-telegem/telegem/-/issues
|
|
199
|
-
documentation_uri: https://gitlab.com/ruby-telegem/telegem/-/
|
|
212
|
+
documentation_uri: https://gitlab.com/ruby-telegem/telegem/-/tree/main/docs-src?ref_type=heads
|
|
200
213
|
rubygems_mfa_required: 'false'
|
|
201
|
-
post_install_message: "Thanks for installing Telegem 2.0.
|
|
202
|
-
= Telegem.new(\"YOUR_TOKEN\")\n bot.on(:message) { |ctx| ctx.reply(\"Hello!\")
|
|
203
|
-
}\n bot.start_polling\n\nDocumentation: https://gitlab.com/ruby-telegem/telegem\nHappy
|
|
214
|
+
post_install_message: "Thanks for installing Telegem 2.0.9!\nDocumentation: https://gitlab.com/ruby-telegem/telegem\nHappy
|
|
204
215
|
bot building! \U0001F916\n"
|
|
205
216
|
rdoc_options: []
|
|
206
217
|
require_paths:
|
|
@@ -209,7 +220,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
209
220
|
requirements:
|
|
210
221
|
- - ">="
|
|
211
222
|
- !ruby/object:Gem::Version
|
|
212
|
-
version:
|
|
223
|
+
version: 3.1.0
|
|
213
224
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
225
|
requirements:
|
|
215
226
|
- - ">="
|
data/docs/Api.md
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
# Telegem API Reference (v2.0.0)
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-

|
|
5
|
-

|
|
6
|
-

|
|
7
|
-
|
|
8
|
-
Modern Telegram Bot Framework for Ruby. This guide details the core methods provided by the Telegem library, your modern toolkit for building Telegram bots with Ruby. Built on the official Telegram Bot API. For detailed parameter info, always check the official docs.
|
|
9
|
-
|
|
10
|
-
[](https://t.me/telegem_ruby)
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
## 1. 🤖 Core Bot Setup & Lifecycle
|
|
15
|
-
|
|
16
|
-
"First, solve the problem. Then, write the code." - John Johnson
|
|
17
|
-
|
|
18
|
-
These methods get your bot online and talking.
|
|
19
|
-
|
|
20
|
-
- **Telegem.new(token, **options)**
|
|
21
|
-
- What it does: Creates your bot instance. This is your starting point.
|
|
22
|
-
- Key Options: logger, timeout, max_threads, session_store.
|
|
23
|
-
- Returns: A shiny new Telegem::Core::Bot object.
|
|
24
|
-
|
|
25
|
-
- **bot.start_polling(**options)**
|
|
26
|
-
- What it does: Starts the classic "call-and-check" method for updates. Perfect for development.
|
|
27
|
-
- Pro-tip: Don't use this if you have a webhook active (it's like trying to receive mail at two different houses).
|
|
28
|
-
|
|
29
|
-
- **bot.webhook(...)** or **Telegem.webhook(bot, ...)**
|
|
30
|
-
- What it does: Sets up a production-grade server so Telegram can push updates directly to your bot. It's the recommended way for serious bots.
|
|
31
|
-
- Telegem Superpowers:
|
|
32
|
-
- Production-ready: Uses the Puma web server out of the box.
|
|
33
|
-
- Cloud-Smart: Automatically figures out if you're on Render, Heroku, etc.
|
|
34
|
-
- Secure: Validates incoming requests with a secret_token.
|
|
35
|
-
- Helper: Call server.set_webhook() after server.run to tell Telegram where to find you.
|
|
36
|
-
|
|
37
|
-
- **bot.shutdown**
|
|
38
|
-
- What it does: The polite way to tell your bot to stop. Closes connections and cleans up threads.
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
## 2. 📨 Update Handling & Events
|
|
43
|
-
|
|
44
|
-
"Programming is 10% writing code and 90% figuring out why it doesn't work." - Unknown Bot Developer
|
|
45
|
-
|
|
46
|
-
Tell your bot how to react to the world.
|
|
47
|
-
|
|
48
|
-
- **bot.on(type, filters = {}, &block)**
|
|
49
|
-
- What it does: Your main tool for handling any event. Runs your code block when a matching update arrives.
|
|
50
|
-
- Types: :message, :callback_query, :inline_query, :edited_message, etc.
|
|
51
|
-
- Examples:
|
|
52
|
-
```ruby
|
|
53
|
-
# Respond to text matching a regex
|
|
54
|
-
bot.on(:message, text: /hello/i) { |ctx| ctx.reply("Hi there!") }
|
|
55
|
-
# Handle a specific inline button press
|
|
56
|
-
bot.on(:callback_query, data: "confirm") { |ctx| ctx.answer_callback_query(text: "Done!") }
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
- **bot.command(name, **options, &block)**
|
|
60
|
-
- What it does: The easy way to handle slash commands like /start or /help.
|
|
61
|
-
- Example:
|
|
62
|
-
```ruby
|
|
63
|
-
bot.command("start") do |ctx|
|
|
64
|
-
ctx.reply("Welcome to the future of Telegram bots!")
|
|
65
|
-
end
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
- **bot.hears(pattern, **options, &block)**
|
|
69
|
-
- What it does: A shortcut specifically for catching text messages with a regex pattern.
|
|
70
|
-
|
|
71
|
-
- **bot.use(middleware, *args, &block)**
|
|
72
|
-
- What it does: Adds a middleware to the processing chain. Great for logging every request, checking user permissions, or adding timings.
|
|
73
|
-
- Joke: Why did the developer go broke? He used up all his cache.
|
|
74
|
-
|
|
75
|
-
- **bot.error(&block)**
|
|
76
|
-
- What it does: Sets up a global safety net to catch any errors that happen inside your handlers, so your bot doesn't just crash silently.
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
## 3. 🔄 The Context (ctx) Object - Your Swiss Army Knife
|
|
81
|
-
|
|
82
|
-
Inside every handler, you get a ctx object. It's your interface to do everything, from sending messages to managing chats. These methods return async HTTPX request objects.
|
|
83
|
-
|
|
84
|
-
"Talk is cheap. Show me the code." - Linus Torvalds (Probably while debugging a context method)
|
|
85
|
-
|
|
86
|
-
### A. Sending Messages & Content
|
|
87
|
-
|
|
88
|
-
- **ctx.reply(text, **options)** - Your bread and butter. Sends a text reply.
|
|
89
|
-
- **ctx.photo(photo, caption: nil, **options)** - Sends an image.
|
|
90
|
-
- **ctx.document(document, caption: nil, **options)** - Sends a file.
|
|
91
|
-
- **ctx.audio(audio, caption: nil, **options)** - Sends an audio file.
|
|
92
|
-
- **ctx.video(video, caption: nil, **options)** - Sends a video.
|
|
93
|
-
- **ctx.voice(voice, caption: nil, **options)** - Sends a voice message.
|
|
94
|
-
- **ctx.sticker(sticker, **options)** - Sends a sticker. Because communication is serious business.
|
|
95
|
-
- **ctx.location(latitude, longitude, **options)** - Shares a location.
|
|
96
|
-
|
|
97
|
-
### B. Managing Existing Messages
|
|
98
|
-
|
|
99
|
-
- **ctx.edit_message_text(text, **options)** - Changes the text of a message you sent.
|
|
100
|
-
- **ctx.delete_message(message_id = nil)** - Poof! Makes a message disappear. Defaults to the current message.
|
|
101
|
-
- **ctx.forward_message(from_chat_id, message_id, **options)** - Forwards a message from elsewhere.
|
|
102
|
-
- **ctx.copy_message(from_chat_id, message_id, **options)** - Copies a message (with forward info).
|
|
103
|
-
- **ctx.pin_message(message_id, **options)** - Pins a message in the chat.
|
|
104
|
-
- **ctx.unpin_message(**options)** - Unpins it.
|
|
105
|
-
|
|
106
|
-
### C. Chat Actions & Info
|
|
107
|
-
|
|
108
|
-
- **ctx.send_chat_action(action, **options)** - Shows a status like "typing..." or "uploading photo..." to users. Required: Be polite and use this for long operations!
|
|
109
|
-
- **ctx.get_chat(**options)** - Gets info about the current chat.
|
|
110
|
-
- **ctx.get_chat_administrators(**options)** - Lists the chat admins.
|
|
111
|
-
- **ctx.get_chat_members_count(**options)** - Counts chat members.
|
|
112
|
-
|
|
113
|
-
### D. Callback & Inline Queries
|
|
114
|
-
|
|
115
|
-
- **ctx.answer_callback_query(text: nil, show_alert: false, **options)** - Responds to a button press. Stops the loading animation on the button.
|
|
116
|
-
- **ctx.answer_inline_query(results, **options)** - Answers an inline query with a list of results.
|
|
117
|
-
|
|
118
|
-
### E. Chat Administration
|
|
119
|
-
|
|
120
|
-
- **ctx.kick_chat_member(user_id, **options)** - Removes a user from the chat.
|
|
121
|
-
- **ctx.ban_chat_member(user_id, **options)** - Bans a user.
|
|
122
|
-
- **ctx.unban_chat_member(user_id, **options)** - Unbans a user.
|
|
123
|
-
|
|
124
|
-
### F. Convenience Shortcuts
|
|
125
|
-
|
|
126
|
-
- **ctx.typing(**options)** - Shortcut for send_chat_action('typing').
|
|
127
|
-
- **ctx.uploading_photo(**options)** - Shortcut for send_chat_action('upload_photo').
|
|
128
|
-
- **ctx.with_typing(&block)** - A helper that shows "typing..." while your code block executes.
|
|
129
|
-
- **ctx.command?** - Returns true if the current message is a command.
|
|
130
|
-
- **ctx.command_args** - Returns the arguments provided after a command (e.g., for /search ruby, it returns "ruby").
|
|
131
|
-
|
|
132
|
-
---
|
|
133
|
-
|
|
134
|
-
## 4. ⌨️ Building Keyboards & Interactions
|
|
135
|
-
|
|
136
|
-
"The best interface is one that the user doesn't notice." - Let's help them not notice it's awesome.
|
|
137
|
-
|
|
138
|
-
Telegem provides a clean DSL for creating interactive keyboards.
|
|
139
|
-
|
|
140
|
-
- **Telegem.keyboard(&block)** - Creates a reply keyboard (appears where users type).
|
|
141
|
-
```ruby
|
|
142
|
-
keyboard = Telegem.keyboard do
|
|
143
|
-
row "Yes", "No"
|
|
144
|
-
row "Maybe", "Cancel"
|
|
145
|
-
resize true # Fits to screen width
|
|
146
|
-
one_time true # Hides after one use
|
|
147
|
-
end
|
|
148
|
-
ctx.reply("Choose wisely:", reply_markup: keyboard)
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
· Telegem.inline(&block) - Creates an inline keyboard (appears inside the message).
|
|
152
|
-
```ruby
|
|
153
|
-
inline_kb = Telegem.inline do
|
|
154
|
-
row do
|
|
155
|
-
callback_button "Approve", "approve_123"
|
|
156
|
-
url_button "Read Docs", "https://gitlab.com/ruby-telegem/telegem"
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
ctx.reply("What next?", reply_markup: inline_kb)
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
---
|
|
163
|
-
|
|
164
|
-
5. 🎭 Scene System & Session Management
|
|
165
|
-
|
|
166
|
-
"Good programmers write code that works. Great programmers write code that manages state." - Ancient Developer Proverb
|
|
167
|
-
|
|
168
|
-
Manage multi-step conversations (like a signup flow) easily.
|
|
169
|
-
|
|
170
|
-
· bot.scene(id, &block) - Defines a new scene with multiple steps.
|
|
171
|
-
· **ctx.enter_scene(scene_name, options) - Puts a user into a scene.
|
|
172
|
-
· ctx.leave_scene(options)** - Takes them out of it.
|
|
173
|
-
· ctx.session - A hash that automatically persists data for each user across different interactions. No setup required!
|
|
174
|
-
|
|
175
|
-
Scene Example:
|
|
176
|
-
|
|
177
|
-
```ruby
|
|
178
|
-
bot.scene("order") do
|
|
179
|
-
step :ask_item do |ctx|
|
|
180
|
-
ctx.reply("What would you like to order?")
|
|
181
|
-
next_step :ask_quantity
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
step :ask_quantity do |ctx|
|
|
185
|
-
ctx.state[:item] = ctx.message.text # Temp storage for this flow
|
|
186
|
-
ctx.reply("How many?")
|
|
187
|
-
next_step :confirm
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
step :confirm do |ctx|
|
|
191
|
-
ctx.session[:last_order] = ctx.state[:item] # Save to persistent session
|
|
192
|
-
ctx.reply("Order placed for #{ctx.state[:item]}! Thanks.")
|
|
193
|
-
leave_scene
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
# Start the scene with a command
|
|
198
|
-
bot.command("pizza") { |ctx| ctx.enter_scene("order") }
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
---
|
|
202
|
-
|
|
203
|
-
Quick Reference Table
|
|
204
|
-
|
|
205
|
-
Category Key Methods What it's for
|
|
206
|
-
Setup new, start_polling, webhook, shutdown Creating, running, and stopping your bot.
|
|
207
|
-
Events on, command, hears, use, error Defining how your bot reacts to messages and errors.
|
|
208
|
-
Actions ctx.reply, ctx.photo, ctx.edit_message_text Sending and managing messages and media.
|
|
209
|
-
Chat ctx.get_chat, ctx.ban_chat_member, ctx.pin_message Getting info and managing groups/channels.
|
|
210
|
-
UI Telegem.keyboard, Telegem.inline Creating interactive buttons for users.
|
|
211
|
-
Flow bot.scene, ctx.session, ctx.enter_scene Managing complex user conversations and data.
|