telegem 3.3.0 → 3.4.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +57 -0
- data/CHANGELOG.md +121 -0
- data/Gemfile +1 -1
- data/README.md +147 -0
- data/bin/telegem-ssl +71 -25
- data/contributing.md +375 -0
- data/docs/api.md +663 -0
- data/docs/bot.md +332 -0
- data/docs/changelog.md +182 -0
- data/docs/context.md +554 -0
- data/docs/core_concepts.md +218 -0
- data/docs/deployment.md +702 -0
- data/docs/error_handling.md +435 -0
- data/docs/examples.md +752 -0
- data/docs/getting_started.md +151 -0
- data/docs/handlers.md +580 -0
- data/docs/keyboards.md +446 -0
- data/docs/middleware.md +536 -0
- data/docs/plugins.md +384 -0
- data/docs/scenes.md +517 -0
- data/docs/sessions.md +544 -0
- data/docs/testing.md +612 -0
- data/docs/troubleshooting.md +574 -0
- data/docs/types.md +538 -0
- data/docs/webhooks.md +456 -0
- data/lib/api/client.rb +38 -10
- data/lib/api/types.rb +433 -172
- data/lib/core/composer.rb +3 -3
- data/lib/core/context.rb +17 -11
- data/lib/plugins/cc +3 -0
- data/lib/plugins/file_extract.rb +2 -2
- data/lib/plugins/translate.rb +43 -0
- data/lib/session/memory_store.rb +90 -103
- data/lib/session/redis.rb +91 -0
- data/lib/telegem.rb +4 -4
- data/lib/webhook/server.rb +5 -3
- metadata +51 -35
- data/CHANGELOG +0 -95
- data/Contributing.md +0 -161
- data/Readme.md +0 -302
- data/examples/.gitkeep +0 -0
- data/public/.gitkeep +0 -0
data/contributing.md
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
We welcome contributions to Telegem! This document provides guidelines for contributing to the project.
|
|
4
|
+
|
|
5
|
+
## Code of Conduct
|
|
6
|
+
|
|
7
|
+
This project follows a code of conduct to ensure a welcoming environment for all contributors. By participating, you agree to:
|
|
8
|
+
|
|
9
|
+
- Be respectful and inclusive
|
|
10
|
+
- Focus on constructive feedback
|
|
11
|
+
- Accept responsibility for mistakes
|
|
12
|
+
- Show empathy towards other contributors
|
|
13
|
+
- Help create a positive community
|
|
14
|
+
|
|
15
|
+
## Getting Started
|
|
16
|
+
|
|
17
|
+
### Development Setup
|
|
18
|
+
|
|
19
|
+
1. **Fork and clone the repository:**
|
|
20
|
+
```bash
|
|
21
|
+
git clone https://github.com/your-username/telegem.git
|
|
22
|
+
cd telegem
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
2. **Install dependencies:**
|
|
26
|
+
```bash
|
|
27
|
+
bundle install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
3. **Set up development environment:**
|
|
31
|
+
```bash
|
|
32
|
+
# Copy environment template
|
|
33
|
+
cp .env.example .env
|
|
34
|
+
|
|
35
|
+
# Edit with your values
|
|
36
|
+
nano .env
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
4. **Run tests:**
|
|
40
|
+
```bash
|
|
41
|
+
bundle exec rspec
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Project Structure
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
telegem/
|
|
48
|
+
├── lib/ # Core library code
|
|
49
|
+
│ ├── telegem.rb # Main module
|
|
50
|
+
│ ├── core/ # Core functionality
|
|
51
|
+
│ ├── api/ # Telegram API client
|
|
52
|
+
│ ├── markup/ # Keyboard DSL
|
|
53
|
+
│ ├── session/ # Session management
|
|
54
|
+
│ ├── plugins/ # Built-in plugins
|
|
55
|
+
│ └── webhook/ # Webhook server
|
|
56
|
+
├── test/ # Test files
|
|
57
|
+
├── docs/ # Documentation
|
|
58
|
+
├── examples/ # Example bots
|
|
59
|
+
├── bin/ # Executables
|
|
60
|
+
└── spec/ # RSpec tests
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Development Workflow
|
|
64
|
+
|
|
65
|
+
### 1. Choose an Issue
|
|
66
|
+
|
|
67
|
+
- Check [GitHub Issues](https://github.com/telegem/telegem/issues) for open tasks
|
|
68
|
+
- Look for issues labeled `good first issue` or `help wanted`
|
|
69
|
+
- Comment on the issue to indicate you're working on it
|
|
70
|
+
|
|
71
|
+
### 2. Create a Branch
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Create feature branch
|
|
75
|
+
git checkout -b feature/your-feature-name
|
|
76
|
+
|
|
77
|
+
# Or for bug fixes
|
|
78
|
+
git checkout -b fix/issue-number-description
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 3. Make Changes
|
|
82
|
+
|
|
83
|
+
- Write clear, concise commit messages
|
|
84
|
+
- Follow the existing code style
|
|
85
|
+
- Add tests for new functionality
|
|
86
|
+
- Update documentation as needed
|
|
87
|
+
|
|
88
|
+
### 4. Test Your Changes
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Run full test suite
|
|
92
|
+
bundle exec rspec
|
|
93
|
+
|
|
94
|
+
# Run specific test
|
|
95
|
+
bundle exec rspec spec/path/to/test_spec.rb
|
|
96
|
+
|
|
97
|
+
# Run with coverage
|
|
98
|
+
COVERAGE=true bundle exec rspec
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 5. Submit a Pull Request
|
|
102
|
+
|
|
103
|
+
- Push your branch to GitHub
|
|
104
|
+
- Create a pull request with a clear description
|
|
105
|
+
- Reference any related issues
|
|
106
|
+
- Wait for review and address feedback
|
|
107
|
+
|
|
108
|
+
## Coding Standards
|
|
109
|
+
|
|
110
|
+
### Ruby Style Guide
|
|
111
|
+
|
|
112
|
+
We follow the [Ruby Style Guide](https://rubystyle.guide/) with some modifications:
|
|
113
|
+
|
|
114
|
+
- Use 2 spaces for indentation
|
|
115
|
+
- Use single quotes for strings unless interpolation is needed
|
|
116
|
+
- Use snake_case for methods and variables
|
|
117
|
+
- Use CamelCase for classes and modules
|
|
118
|
+
- Limit lines to 100 characters
|
|
119
|
+
- Use trailing commas in multi-line structures
|
|
120
|
+
|
|
121
|
+
### Example Code Style
|
|
122
|
+
|
|
123
|
+
```ruby
|
|
124
|
+
# Good
|
|
125
|
+
class UserHandler
|
|
126
|
+
def initialize(bot, user_id)
|
|
127
|
+
@bot = bot
|
|
128
|
+
@user_id = user_id
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def send_welcome_message
|
|
132
|
+
@bot.api.call('sendMessage',
|
|
133
|
+
chat_id: @user_id,
|
|
134
|
+
text: 'Welcome!')
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Bad
|
|
139
|
+
class userHandler
|
|
140
|
+
def initialize bot,user_id
|
|
141
|
+
@bot=bot
|
|
142
|
+
@user_id=user_id
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def sendWelcomeMessage()
|
|
146
|
+
@bot.api.call('sendMessage',{chat_id:@user_id,text:'Welcome!'})
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Naming Conventions
|
|
152
|
+
|
|
153
|
+
- **Classes/Modules:** `CamelCase`
|
|
154
|
+
- **Methods:** `snake_case`
|
|
155
|
+
- **Constants:** `SCREAMING_SNAKE_CASE`
|
|
156
|
+
- **Files:** `snake_case.rb`
|
|
157
|
+
- **Directories:** `snake_case`
|
|
158
|
+
|
|
159
|
+
### Documentation
|
|
160
|
+
|
|
161
|
+
- Use YARD format for documentation
|
|
162
|
+
- Document all public methods
|
|
163
|
+
- Include examples for complex functionality
|
|
164
|
+
- Keep documentation up to date
|
|
165
|
+
|
|
166
|
+
```ruby
|
|
167
|
+
# Good
|
|
168
|
+
class Bot
|
|
169
|
+
# Sends a message to a chat
|
|
170
|
+
#
|
|
171
|
+
# @param chat_id [Integer] The chat ID to send to
|
|
172
|
+
# @param text [String] The message text
|
|
173
|
+
# @return [Hash] The API response
|
|
174
|
+
# @example
|
|
175
|
+
# bot.send_message(123, 'Hello!')
|
|
176
|
+
def send_message(chat_id, text)
|
|
177
|
+
# implementation
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Testing
|
|
183
|
+
|
|
184
|
+
### Test Structure
|
|
185
|
+
|
|
186
|
+
- Use RSpec for testing
|
|
187
|
+
- Place tests in `spec/` directory
|
|
188
|
+
- Mirror the `lib/` structure in `spec/`
|
|
189
|
+
- Name test files with `_spec.rb` suffix
|
|
190
|
+
|
|
191
|
+
### Test Best Practices
|
|
192
|
+
|
|
193
|
+
```ruby
|
|
194
|
+
# spec/bot_spec.rb
|
|
195
|
+
RSpec.describe Telegem::Bot do
|
|
196
|
+
let(:bot) { Telegem::Bot.new(token: 'test_token') }
|
|
197
|
+
|
|
198
|
+
describe '#send_message' do
|
|
199
|
+
it 'sends a message successfully' do
|
|
200
|
+
allow(bot.api).to receive(:call).and_return({'ok' => true})
|
|
201
|
+
|
|
202
|
+
result = bot.send_message(123, 'test')
|
|
203
|
+
|
|
204
|
+
expect(result['ok']).to be true
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
it 'handles API errors' do
|
|
208
|
+
allow(bot.api).to receive(:call).and_raise(Telegem::API::APIError.new('error'))
|
|
209
|
+
|
|
210
|
+
expect { bot.send_message(123, 'test') }.to raise_error(Telegem::API::APIError)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Test Coverage
|
|
217
|
+
|
|
218
|
+
- Aim for >90% code coverage
|
|
219
|
+
- Test both success and failure scenarios
|
|
220
|
+
- Mock external dependencies
|
|
221
|
+
- Test edge cases and error conditions
|
|
222
|
+
|
|
223
|
+
## Plugin Development
|
|
224
|
+
|
|
225
|
+
### Plugin Guidelines
|
|
226
|
+
|
|
227
|
+
1. **Create plugin class:**
|
|
228
|
+
```ruby
|
|
229
|
+
module Telegem
|
|
230
|
+
module Plugins
|
|
231
|
+
class MyPlugin
|
|
232
|
+
def initialize(bot, *args, **options)
|
|
233
|
+
@bot = bot
|
|
234
|
+
@options = options
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def do_something
|
|
238
|
+
# Plugin logic
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
2. **Add comprehensive tests**
|
|
246
|
+
3. **Include documentation**
|
|
247
|
+
4. **Handle errors gracefully**
|
|
248
|
+
5. **Make configuration optional**
|
|
249
|
+
|
|
250
|
+
### Plugin Checklist
|
|
251
|
+
|
|
252
|
+
- [ ] Plugin follows naming conventions
|
|
253
|
+
- [ ] Comprehensive error handling
|
|
254
|
+
- [ ] Configuration options documented
|
|
255
|
+
- [ ] Tests included
|
|
256
|
+
- [ ] Documentation added
|
|
257
|
+
- [ ] Dependencies listed
|
|
258
|
+
- [ ] Examples provided
|
|
259
|
+
|
|
260
|
+
## Documentation
|
|
261
|
+
|
|
262
|
+
### Documentation Standards
|
|
263
|
+
|
|
264
|
+
- Use Markdown for documentation
|
|
265
|
+
- Place docs in `docs/` directory
|
|
266
|
+
- Include code examples
|
|
267
|
+
- Cover edge cases and error scenarios
|
|
268
|
+
- Keep documentation current
|
|
269
|
+
|
|
270
|
+
### Documentation Checklist
|
|
271
|
+
|
|
272
|
+
- [ ] Installation instructions
|
|
273
|
+
- [ ] Usage examples
|
|
274
|
+
- [ ] API reference
|
|
275
|
+
- [ ] Configuration options
|
|
276
|
+
- [ ] Troubleshooting guide
|
|
277
|
+
- [ ] Changelog updates
|
|
278
|
+
|
|
279
|
+
## Pull Request Process
|
|
280
|
+
|
|
281
|
+
### Before Submitting
|
|
282
|
+
|
|
283
|
+
1. **Update tests and documentation**
|
|
284
|
+
2. **Ensure all tests pass**
|
|
285
|
+
3. **Check code style**
|
|
286
|
+
4. **Update CHANGELOG.md**
|
|
287
|
+
5. **Squash commits if needed**
|
|
288
|
+
|
|
289
|
+
### Pull Request Template
|
|
290
|
+
|
|
291
|
+
```markdown
|
|
292
|
+
## Description
|
|
293
|
+
Brief description of the changes
|
|
294
|
+
|
|
295
|
+
## Type of Change
|
|
296
|
+
- [ ] Bug fix
|
|
297
|
+
- [ ] New feature
|
|
298
|
+
- [ ] Breaking change
|
|
299
|
+
- [ ] Documentation update
|
|
300
|
+
- [ ] Refactoring
|
|
301
|
+
|
|
302
|
+
## Testing
|
|
303
|
+
- [ ] Tests added/updated
|
|
304
|
+
- [ ] All tests pass
|
|
305
|
+
- [ ] Manual testing performed
|
|
306
|
+
|
|
307
|
+
## Checklist
|
|
308
|
+
- [ ] Code follows style guide
|
|
309
|
+
- [ ] Documentation updated
|
|
310
|
+
- [ ] CHANGELOG.md updated
|
|
311
|
+
- [ ] Commit messages are clear
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Review Process
|
|
315
|
+
|
|
316
|
+
1. **Automated checks run**
|
|
317
|
+
2. **Code review by maintainers**
|
|
318
|
+
3. **Feedback addressed**
|
|
319
|
+
4. **Approval and merge**
|
|
320
|
+
|
|
321
|
+
## Issue Reporting
|
|
322
|
+
|
|
323
|
+
### Bug Reports
|
|
324
|
+
|
|
325
|
+
When reporting bugs, please include:
|
|
326
|
+
|
|
327
|
+
- **Telegem version**
|
|
328
|
+
- **Ruby version**
|
|
329
|
+
- **Operating system**
|
|
330
|
+
- **Steps to reproduce**
|
|
331
|
+
- **Expected behavior**
|
|
332
|
+
- **Actual behavior**
|
|
333
|
+
- **Error messages/logs**
|
|
334
|
+
- **Minimal code example**
|
|
335
|
+
|
|
336
|
+
### Feature Requests
|
|
337
|
+
|
|
338
|
+
For feature requests, include:
|
|
339
|
+
|
|
340
|
+
- **Use case description**
|
|
341
|
+
- **Proposed implementation**
|
|
342
|
+
- **Benefits**
|
|
343
|
+
- **Potential drawbacks**
|
|
344
|
+
|
|
345
|
+
## Community
|
|
346
|
+
|
|
347
|
+
### Communication Channels
|
|
348
|
+
|
|
349
|
+
- **GitHub Issues:** Bug reports and feature requests
|
|
350
|
+
- **GitHub Discussions:** General discussion and questions
|
|
351
|
+
- **Pull Requests:** Code contributions
|
|
352
|
+
|
|
353
|
+
### Getting Help
|
|
354
|
+
|
|
355
|
+
- Check existing documentation
|
|
356
|
+
- Search GitHub issues
|
|
357
|
+
- Ask in GitHub discussions
|
|
358
|
+
- Review examples in `examples/` directory
|
|
359
|
+
|
|
360
|
+
## Recognition
|
|
361
|
+
|
|
362
|
+
Contributors will be:
|
|
363
|
+
- Listed in CHANGELOG.md
|
|
364
|
+
- Added to CONTRIBUTORS file
|
|
365
|
+
- Recognized in release notes
|
|
366
|
+
- Invited to become maintainers (for significant contributions)
|
|
367
|
+
|
|
368
|
+
## License
|
|
369
|
+
|
|
370
|
+
By contributing to Telegem, you agree that your contributions will be licensed under the same license as the project (MIT License).
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
Thank you for contributing to Telegem! Your help makes the framework better for everyone.</content>
|
|
375
|
+
<parameter name="filePath">/home/slick/telegem/docs/contributing.md
|