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.
@@ -0,0 +1,258 @@
1
+
2
+ # ๐Ÿš€ Quick Start: Your First Bot in 5 Minutes
3
+
4
+ Welcome! This guide will help you create your first Telegram bot with Telegem. No prior bot experience needed!
5
+
6
+ ## ๐Ÿ“‹ What You'll Need
7
+
8
+ 1. **Ruby installed** (version 3.0 or newer)
9
+ 2. **A Telegram account**
10
+ 3. **A bot token** (we'll get this next)
11
+
12
+ ---
13
+
14
+ ## ๐Ÿ”‘ Step 1: Get Your Bot Token
15
+
16
+ 1. Open Telegram and search for **@BotFather**
17
+ 2. Start a chat and send: `/newbot`
18
+ 3. Choose a name for your bot (e.g., `My Test Bot`)
19
+ 4. Choose a username ending in `bot` (e.g., `my_test_123_bot`)
20
+ 5. **Copy the token** that looks like this:
21
+ ```
22
+
23
+ 1234567890:ABCdefGHIjklMNOpqrSTUvwxYZ-123456789
24
+
25
+ ```
26
+ โš ๏ธ **Keep this token secret!** It's your bot's password.
27
+
28
+ ---
29
+
30
+ ## ๐Ÿ“ฆ Step 2: Install Telegem
31
+
32
+ Open your terminal and run:
33
+
34
+ ```bash
35
+ gem install telegem
36
+ ```
37
+
38
+ You should see something like:
39
+
40
+ ```
41
+ Successfully installed telegem-0.1.0
42
+ 1 gem installed
43
+ ```
44
+
45
+ ---
46
+
47
+ ๐Ÿค– Step 3: Create Your First Bot
48
+
49
+ Create a new file called my_first_bot.rb:
50
+
51
+ ```ruby
52
+ # my_first_bot.rb
53
+ require 'telegem'
54
+
55
+ # 1. Paste your token here (replace the example)
56
+ BOT_TOKEN = "1234567890:ABCdefGHIjklMNOpqrSTUvwxYZ"
57
+
58
+ # 2. Create your bot
59
+ bot = Telegem.new(BOT_TOKEN)
60
+
61
+ # 3. Add your first command
62
+ bot.command('start') do |ctx|
63
+ ctx.reply "Hello! I'm your new bot. ๐Ÿ‘‹"
64
+ ctx.reply "Try sending me /help"
65
+ end
66
+
67
+ # 4. Add a help command
68
+ bot.command('help') do |ctx|
69
+ help_text = <<~TEXT
70
+ ๐Ÿค– **My First Bot Commands:**
71
+
72
+ /start - Start the bot
73
+ /help - Show this message
74
+ /echo [text] - Repeat your text
75
+
76
+ Just send me any message and I'll reply!
77
+ TEXT
78
+
79
+ ctx.reply help_text
80
+ end
81
+
82
+ # 5. Add an echo command
83
+ bot.command('echo') do |ctx|
84
+ if ctx.message.text == "/echo"
85
+ ctx.reply "Please add some text: /echo hello world"
86
+ else
87
+ # Remove "/echo " from the beginning
88
+ text = ctx.message.text.sub('/echo ', '')
89
+ ctx.reply "You said: #{text}"
90
+ end
91
+ end
92
+
93
+ # 6. Reply to ANY message
94
+ bot.on(:message) do |ctx|
95
+ # Don't reply to commands (they're handled above)
96
+ next if ctx.message.command?
97
+
98
+ ctx.reply "I got your message: #{ctx.message.text}"
99
+ end
100
+
101
+ # 7. Start the bot
102
+ puts "๐Ÿค– Bot starting... (Press Ctrl+C to stop)"
103
+ bot.start_polling
104
+ ```
105
+
106
+ ---
107
+
108
+ โ–ถ๏ธ Step 4: Run Your Bot
109
+
110
+ In your terminal, run:
111
+
112
+ ```bash
113
+ ruby my_first_bot.rb
114
+ ```
115
+
116
+ You should see:
117
+
118
+ ```
119
+ ๐Ÿค– Bot starting... (Press Ctrl+C to stop)
120
+ ```
121
+
122
+ Congratulations! Your bot is now running! ๐ŸŽ‰
123
+
124
+ ---
125
+
126
+ ๐Ÿ’ฌ Step 5: Test Your Bot
127
+
128
+ 1. Open Telegram and search for your bot's username (e.g., @my_test_123_bot)
129
+ 2. Click "Start"
130
+ 3. Try these commands:
131
+ ยท /start - Should say hello
132
+ ยท /help - Should show commands
133
+ ยท /echo hello - Should repeat "hello"
134
+ ยท Send any normal message - Should echo it back
135
+
136
+ It should work like this:
137
+
138
+ ```
139
+ You: /start
140
+ Bot: Hello! I'm your new bot. ๐Ÿ‘‹
141
+ Bot: Try sending me /help
142
+
143
+ You: Hello bot!
144
+ Bot: I got your message: Hello bot!
145
+
146
+ You: /echo testing
147
+ Bot: You said: testing
148
+ ```
149
+
150
+ ---
151
+
152
+ ๐ŸŽจ Step 6: Add a Simple Keyboard
153
+
154
+ Let's make it more interactive! Update your bot with this:
155
+
156
+ ```ruby
157
+ # Add this new command
158
+ bot.command('menu') do |ctx|
159
+ # Create a simple keyboard
160
+ keyboard = [
161
+ ["Option 1", "Option 2"],
162
+ ["Option 3", "Cancel"]
163
+ ]
164
+
165
+ ctx.reply "Choose an option:", reply_markup: { keyboard: keyboard }
166
+ end
167
+
168
+ # Handle the keyboard button presses
169
+ bot.on(:message) do |ctx|
170
+ next if ctx.message.command?
171
+
172
+ text = ctx.message.text
173
+
174
+ case text
175
+ when "Option 1"
176
+ ctx.reply "You chose Option 1! โœ…"
177
+ when "Option 2"
178
+ ctx.reply "Option 2 selected! ๐Ÿ‘"
179
+ when "Option 3"
180
+ ctx.reply "Option 3 picked! ๐ŸŽฏ"
181
+ when "Cancel"
182
+ ctx.reply "Cancelled! โŒ"
183
+ else
184
+ ctx.reply "I got: #{text}"
185
+ end
186
+ end
187
+ ```
188
+
189
+ Restart your bot and try /menu to see the keyboard!
190
+
191
+ ---
192
+
193
+ ๐Ÿ› ๏ธ Step 7: Common Fixes
194
+
195
+ "Token is invalid" error?
196
+
197
+ ยท Make sure you copied the entire token
198
+ ยท Check there are no spaces before/after
199
+ ยท Try creating a new bot with @BotFather
200
+
201
+ "gem not found" error?
202
+
203
+ ยท Run gem install telegem again
204
+ ยท Check Ruby version: ruby -v (should be 3.0+)
205
+
206
+ Bot not responding?
207
+
208
+ ยท Make sure your bot is running (ruby my_first_bot.rb)
209
+ ยท Check you've started the bot in Telegram (send /start)
210
+ ยท Wait a few seconds - sometimes there's a small delay
211
+
212
+ Want to stop the bot?
213
+
214
+ Press Ctrl+C in your terminal.
215
+
216
+ ---
217
+
218
+ ๐Ÿš€ Next Steps
219
+
220
+ Your bot is working! Now try:
221
+
222
+ 1. Change the replies - Make the bot say different things
223
+ 2. Add more commands - Try /time to send current time
224
+ 3. Send a photo - Add this to your bot:
225
+ ```ruby
226
+ bot.command('photo') do |ctx|
227
+ ctx.reply "Here's a cat! ๐Ÿฑ"
228
+ # Send a cat photo from the internet
229
+ ctx.photo("https://placekitten.com/400/400")
230
+ end
231
+ ```
232
+ 4. Check the examples - Look in the /examples folder for more ideas
233
+ 5. Read the API Reference - When you're ready for more features, check api.md
234
+
235
+ ---
236
+
237
+ ๐Ÿ’ก Tips for Beginners
238
+
239
+ ยท Save your token safely - You'll need it every time
240
+ ยท Restart after changes - Stop (Ctrl+C) and restart your bot when you change the code
241
+ ยท Start simple - Get one thing working before adding more
242
+ ยท Use puts for debugging - Add puts "Got here!" to see what's happening
243
+
244
+ ---
245
+
246
+ ๐Ÿ†˜ Need Help?
247
+
248
+ 1. Check your code against the examples above
249
+ 2. Read error messages - They often tell you what's wrong
250
+ 3. Ask for help - Open an issue on GitLab
251
+
252
+ ---
253
+
254
+ ๐ŸŽ‰ You did it! You've built your first Telegram bot. What will you create next?
255
+
256
+ ```
257
+
258
+ ---