telegem 3.3.1 → 3.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d2afc9e262ffced76a28974a69c6e652bf433b2b6da80c6827d45e6da43002a
4
- data.tar.gz: 61f440f2523473e3f5435075bfece0519c374f4aa498d789cc6752c5ce285abf
3
+ metadata.gz: 45cc39ffb7a5897950caff2309dbeb1e5d479d8d20e13e2219fc9165ec4026d5
4
+ data.tar.gz: '039472d0308d1e42b752cee2a93a0cdd0880ee1677608964911d5ba6e947a750'
5
5
  SHA512:
6
- metadata.gz: 378d55910d0b38b255b35ea357af4cb88f45000362b9d16688dff82a02fe3e5119e71e591c2cec61556d9c9cc82c0edd914ba7cd153ba1cae04c0e97b3f6d229
7
- data.tar.gz: 527cb2833282c03d7f19145d7421e6df5d867ffbb479846ac9e969a8be339450c7358fdefaced5952dfc7d96b999348253a2494b2a2fe3d9c55480073587a421
6
+ metadata.gz: 8108374c406751c497c309a50a40a7aa99776f1c6871a2f1cc700b96bfa328046bdcaf2e9848cd9aa28b90dcb780f42f1c790ad03f85261d3a16c1802186c812
7
+ data.tar.gz: 37f9fd3006d5702f049f79817e9a9fe0054c04b4ecbdedd4e06daa2fe314f28eb98fdfb539fdcba4280c12a9eeff82c2b7851eb2edb2c28c5285a8eb94e223a8
data/.rubocop.yml ADDED
@@ -0,0 +1,57 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.3
3
+ NewCops: enable
4
+ DisplayCopNames: true
5
+ Exclude:
6
+ - 'bin/**/*'
7
+ - 'node_modules/**/*'
8
+ - 'vendor/**/*'
9
+ - 'tmp/**/*'
10
+ - 'log/**/*'
11
+ - 'db/schema.rb'
12
+
13
+ # Optional: enable extra cops if you add gems (rubocop-performance, rubocop-rspec, rubocop-security)
14
+ # require:
15
+ # - rubocop-performance
16
+ # - rubocop-rspec
17
+ # - rubocop-security
18
+
19
+ Layout/LineLength:
20
+ Max: 100
21
+
22
+ Layout/IndentationWidth:
23
+ Width: 2
24
+
25
+ Metrics/MethodLength:
26
+ Max: 30
27
+ CountComments: false
28
+
29
+ Metrics/BlockLength:
30
+ Exclude:
31
+ - 'spec/**/*'
32
+ - 'test/**/*'
33
+ Max: 200
34
+
35
+ Style/StringLiterals:
36
+ EnforcedStyle: single_quotes
37
+
38
+ Style/FrozenStringLiteralComment:
39
+ Enabled: true
40
+
41
+ Naming/PredicateName:
42
+ Enabled: true
43
+
44
+ Lint/UnusedMethodArgument:
45
+ Enabled: true
46
+
47
+ Lint/UselessAssignment:
48
+ Enabled: true
49
+
50
+ Style/Documentation:
51
+ Enabled: false
52
+
53
+ # Allow longer files for generated code
54
+ Metrics/LineLength:
55
+ Exclude:
56
+ - 'assets/**/*'
57
+ - 'vendor/**/*'
data/CHANGELOG.md CHANGED
@@ -1,6 +1,50 @@
1
1
  # Telegem Changelog
2
2
 
3
- ## v3.3.1(lastest)
3
+ ## v3.5.0 (latest)
4
+
5
+ ### Added
6
+ - **Bot API 10.0 Full Support**
7
+ - Guest mode support: `SentGuestMessage` type and `guest_message` update type
8
+ - Message reactions: Support for deleting reactions via `call('deleteAllMessageReactions', ...)` and `call('deleteMessageReaction', ...)`
9
+ - Live photos: `LivePhoto`, `InputMediaLivePhoto`, `PaidMediaLivePhoto`, `InputPaidMediaLivePhoto` types
10
+ - Poll media enhancements: `PollMedia`, `InputPollMedia`, `InputPollOptionMedia` types
11
+ - Business access: New types and methods accessible via generic `call` method
12
+ - Enhanced chat administrators: Support for `return_bots` parameter in `getChatAdministrators`
13
+ - User guest query support: `supports_guest_queries` field in User type
14
+ - Message guest fields: `guest_bot_caller_user`, `guest_bot_caller_chat`, `guest_query_id`, `live_photo` in Message type
15
+ - Poll media fields: `media`, `explanation_media` in Poll type; `media` in PollOption type
16
+ - Reaction permissions: `can_react_to_messages` in ChatPermissions and ChatMemberRestricted types
17
+
18
+ ### Changed
19
+ - Updated API version support to Bot API 10.0
20
+ - All new API methods automatically supported through generic `call()` and `call!()` methods
21
+
22
+ ## v3.4.0
23
+
24
+ - added bot api 9.6 full support
25
+ - all fixes from v3.3.2-rc.1
26
+ - enhanced install message
27
+ - requires ruby v >= 3.4.x
28
+ - added bot api 9.6 helper to ctx
29
+ - introduced redis store to `session/redis_store.rb`
30
+ - new translate plugin
31
+ - added more docs to support telegem -v 3.x
32
+ - improved error message on invalid middlewares
33
+ - removed `concurrent-ruby` gem to keep telegem lightweight
34
+
35
+ ## v3.3.2-rc.1
36
+
37
+ ### Fixed
38
+ - Webhook `set_webhook` now correctly passes URL as positional argument
39
+ - Removed unsafe thread usage in `Context#with_typing` (async-safe now)
40
+ - Added automatic retry with exponential backoff in API client
41
+ - Improved `telegem-ssl` to detect dnf/yum on Fedora/RHEL
42
+
43
+ ### Changed
44
+ - No breaking changes. Safe upgrade from v3.3.1.
45
+
46
+
47
+ ## v3.3.1
4
48
  ### Features
5
49
  - improved memeorystore to include diskbackup
6
50
  - added 'telegem-init' cli
data/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # Telegem Documentation
2
+
3
+ Welcome to the comprehensive documentation for Telegem, a modern Ruby framework for building Telegram bots.
4
+
5
+ [![CodeQl](https://github.com/slick-lab/telegem/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/slick-lab/telegem/actions/workflows/github-code-scanning/codeql)
6
+ [![Gem Version](https://badge.fury.io/rb/telegem.svg)](https://badge.fury.io/rb/telegem)
7
+ [![Join Telegram Group](https://img.shields.io/badge/Telegram-Join%20Group-2CA5E0?style=flat-square&logo=telegram&logoColor=white)](https://t.me/r_telegem)
8
+
9
+
10
+
11
+ ## Table of Contents
12
+
13
+ ### Getting Started
14
+ - [README](README.md) - Main project README
15
+ - [Getting Started](getting_started.md) - Installation and basic setup
16
+ - [Core Concepts](core_concepts.md) - Understanding Telegem architecture
17
+
18
+ ### Core Components
19
+ - [Bot](bot.md) - Main bot class and configuration
20
+ - [Context](context.md) - Update context and response methods
21
+ - [Handlers](handlers.md) - Command, hears, and event handlers
22
+ - [Middleware](middleware.md) - Request processing pipeline
23
+ - [Scenes](scenes.md) - Multi-step conversation flows
24
+ - [Sessions](sessions.md) - Data persistence between updates
25
+
26
+ ### API & Types
27
+ - [API](api.md) - Telegram API client usage
28
+ - [Types](types.md) - Type-safe API response handling
29
+ - [Keyboards](keyboards.md) - Inline and reply keyboard DSL
30
+
31
+ ### Advanced Features
32
+ - [Plugins](plugins.md) - Built-in and custom plugins
33
+ - [Webhooks](webhooks.md) - Production webhook deployment
34
+ - [Error Handling](error_handling.md) - Comprehensive error management
35
+ - [Testing](testing.md) - Unit and integration testing
36
+ - [Deployment](deployment.md) - Production deployment guides
37
+
38
+ ### Examples & Guides
39
+ - [Examples](examples.md) - Complete bot examples
40
+ - [Troubleshooting](troubleshooting.md) - Common issues and solutions
41
+ - [Contributing](contributing.md) - Development guidelines
42
+ - [Changelog](changelog.md) - Version history and changes
43
+
44
+ ## Quick Start
45
+
46
+ 1. **Install Telegem:**
47
+ ```bash
48
+ gem install telegem
49
+ ```
50
+
51
+ 2. **Create your first bot:**
52
+ ```ruby
53
+ require 'telegem'
54
+
55
+ bot = Telegem.new(token: 'YOUR_BOT_TOKEN')
56
+
57
+ bot.command('start') do |ctx|
58
+ ctx.reply('Hello, World!')
59
+ end
60
+
61
+ bot.start_polling
62
+ ```
63
+
64
+ 3. **Explore features:**
65
+ - Add [handlers](handlers.md) for different message types
66
+ - Use [sessions](sessions.md) for data persistence
67
+ - Implement [scenes](scenes.md) for complex conversations
68
+ - Deploy with [webhooks](webhooks.md) for production
69
+
70
+ ## Key Features
71
+
72
+ - **Async I/O**: Built on the Async gem for high performance
73
+ - **Type Safety**: Automatic type conversion for API responses
74
+ - **Session Management**: Built-in session stores (Memory, Redis)
75
+ - **Plugin System**: Extensible with custom plugins
76
+ - **Scene System**: Complex conversation flows
77
+ - **Middleware**: Request processing pipeline
78
+ - **Error Handling**: Comprehensive error recovery
79
+ - **Testing**: Full test suite with mocking support
80
+
81
+ ## Architecture Overview
82
+
83
+ ```
84
+ ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
85
+ │ Telegram API │◄──►│ API Client │◄──►│ Handlers │
86
+ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
87
+ ā–²
88
+ │
89
+ ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
90
+ │ Middleware │
91
+ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
92
+ ā–²
93
+ │
94
+ ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
95
+ │ Sessions │
96
+ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
97
+ ```
98
+
99
+ ## Support
100
+
101
+ - **Documentation**: You're reading it!
102
+ - **Issues**: [GitHub Issues](https://github.com/telegem/telegem/issues)
103
+ - **Discussions**: [GitHub Discussions](https://github.com/telegem/telegem/discussions)
104
+ - **Examples**: Check the `examples/` directory
105
+
106
+ ## Contributing
107
+
108
+ We welcome contributions! See our [contributing guide](contributing.md) for details.
109
+
110
+ ## License
111
+
112
+ Telegem is released under the MIT License. See the main README for details.
113
+
114
+ ---
115
+
116
+ **Happy bot building with Telegem! šŸ¤–**
117
+
118
+ ```ruby
119
+ gem 'telegem'
120
+ ```
121
+
122
+ ## Basic Usage
123
+
124
+ ```ruby
125
+ require 'telegem'
126
+
127
+ bot = Telegem.new('YOUR_BOT_TOKEN')
128
+
129
+ bot.command('start') do |ctx|
130
+ ctx.reply("Hello, #{ctx.from.first_name}!")
131
+ end
132
+
133
+ bot.start_polling
134
+ ```
135
+
136
+ ## Requirements
137
+
138
+ - Ruby 3.0+
139
+ - Telegram Bot Token from [@BotFather](https://t.me/botfather)
140
+
141
+ ## License
142
+
143
+ MIT License - see [LICENSE](../LICENSE) file for details.
144
+
145
+ ## Contributing
146
+
147
+ See [Contributing Guide](contributing.md) for development setup and contribution guidelines.</content>
148
+ <parameter name="filePath">/home/slick/telegem/docs/README.md
data/bin/telegem-ssl CHANGED
@@ -4,48 +4,94 @@
4
4
  require 'fileutils'
5
5
  require 'yaml'
6
6
 
7
- puts "šŸ” Telegem SSL Setup"
8
- puts "=" * 10
7
+ puts "Telegem SSL Setup"
8
+ puts "=" * 40
9
9
 
10
+ # Check for existing config
10
11
  if File.exist?('.telegem-ssl')
11
- puts "🚫 SSL config already exists at .telegem-ssl"
12
+ puts "SSL config already exists at .telegem-ssl"
12
13
  print "Overwrite? (y/n): "
13
- exit unless gets.chomp.downcase == 'y'
14
+ response = gets.chomp.downcase
15
+ unless response == 'y'
16
+ puts "Setup cancelled."
17
+ exit 1
18
+ end
14
19
  end
15
20
 
16
21
  # Get domain
17
22
  domain = ARGV[0]
18
23
  unless domain
19
- print "🌐 Enter domain (e.g., bot.example.com): "
24
+ print "Enter domain (e.g., bot.example.com): "
20
25
  domain = gets.chomp
21
26
  end
22
27
 
23
- # Get email
28
+ # Get email
24
29
  email = ARGV[1] || "admin@#{domain}"
25
30
 
26
- # Check certbot
27
- unless system("which certbot > /dev/null")
28
- puts "šŸ“¦ Installing certbot..."
29
- system("sudo apt update && sudo apt install -y certbot")
31
+ # Detect package manager and install certbot
32
+ def install_certbot
33
+ return true if system("command -v certbot > /dev/null 2>&1")
34
+
35
+ puts "Installing certbot..."
36
+
37
+ case
38
+ when system("command -v apt > /dev/null 2>&1")
39
+ system("sudo apt update && sudo apt install -y certbot")
40
+ when system("command -v dnf > /dev/null 2>&1")
41
+ system("sudo dnf install -y certbot")
42
+ when system("command -v yum > /dev/null 2>&1")
43
+ system("sudo yum install -y certbot")
44
+ when system("command -v brew > /dev/null 2>&1")
45
+ system("brew install certbot")
46
+ else
47
+ puts "Could not detect package manager. Please install certbot manually:"
48
+ puts " https://certbot.eff.org/instructions"
49
+ return false
50
+ end
51
+
52
+ system("command -v certbot > /dev/null 2>&1")
53
+ end
54
+
55
+ unless install_certbot
56
+ puts "Failed to install certbot. Exiting."
57
+ exit 1
30
58
  end
31
59
 
32
60
  # Generate certificate
33
- puts "\nšŸ“„ Getting SSL certificate..."
61
+ puts "Getting SSL certificate..."
62
+
63
+ # Try standalone mode first, fall back to webroot
34
64
  cert_cmd = "sudo certbot certonly --standalone -d #{domain} --email #{email} --agree-tos --non-interactive"
35
65
  puts "Running: #{cert_cmd}"
36
66
 
37
- if system(cert_cmd)
38
- # Create config
39
- config = {
40
- domain: domain,
41
- cert_path: "/etc/letsencrypt/live/#{domain}/fullchain.pem",
42
- key_path: "/etc/letsencrypt/live/#{domain}/privkey.pem"
43
- }
67
+ unless system(cert_cmd)
68
+ puts "Standalone mode failed. Trying webroot mode..."
69
+ print "Enter webroot path (e.g., /var/www/html): "
70
+ webroot = gets.chomp
44
71
 
45
- File.write(".telegem-ssl", config.to_yaml)
46
- puts "āœ… SSL configured! Certificate valid for 90 days."
47
- puts "šŸ“ Config saved to .telegem-ssl"
48
- puts "\nšŸš€ Start your bot: ruby bot.rb"
49
- else
50
- puts "āŒ Failed to get certificate. Check domain and try again."
51
- end
72
+ cert_cmd = "sudo certbot certonly --webroot -w #{webroot} -d #{domain} --email #{email} --agree-tos --non-interactive"
73
+ puts "Running: #{cert_cmd}"
74
+
75
+ unless system(cert_cmd)
76
+ puts "Failed to get certificate. Check domain and try again."
77
+ exit 1
78
+ end
79
+ end
80
+
81
+ # Create config
82
+ config = {
83
+ domain: domain,
84
+ cert_path: "/etc/letsencrypt/live/#{domain}/fullchain.pem",
85
+ key_path: "/etc/letsencrypt/live/#{domain}/privkey.pem"
86
+ }
87
+
88
+ File.write(".telegem-ssl", config.to_yaml)
89
+ puts "SSL configured. Certificate valid for 90 days."
90
+ puts "Config saved to .telegem-ssl"
91
+
92
+ # Auto-renewal instructions
93
+ puts "\nAuto-renewal setup (recommended):"
94
+ puts " Add this to crontab (crontab -e):"
95
+ puts " 0 0 1 * * certbot renew --quiet && systemctl reload your-bot"
96
+
97
+ puts "\nStart your bot: ruby bot.rb"