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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 156ed056e2f5201d26aaa636b1bd2fdace0499dedca7aa52cff1692546480733
4
- data.tar.gz: b0fef7cc585db195c4eeef5c0d656a659b1d12f8e9ea25506745c9318bc5dca8
3
+ metadata.gz: 3a7cc82173aa5648e1b1d119971c9fec495db0bb9f2764135ffa15bd5c641e1e
4
+ data.tar.gz: ec409f5eecba8209c1f1f7e6237f2eddddebb67251fe9ffe4d8f329845256758
5
5
  SHA512:
6
- metadata.gz: a99c675b08fec66843ecc4d41880a74043a0498a486db404049e63eeb523ab746f186c482ce828550e010fa8f4f4ebd1102507e73532fb681c912c48c144417e
7
- data.tar.gz: 0dc7360428b2d1fcfe383941f54c0b44f75af45c35eb7cb9cfbbfee190445c095bd5fac6007cd2ec885736ec8eea38ca9e286030b9b4486cd97ac4bef353d96c
6
+ metadata.gz: 0e3eaf7311d7cf248b0b59bfa1e0fd7a4ae745129dae8abc0d6a50be55b85c8d86a399913585e72b70fbff935e07450418d6085d2e3ce7ba8e6de3999235593c
7
+ data.tar.gz: 93f600342a065a36014d8e3d0c37c455ec1bfe1db9ac43801ce5b9cb04d66906dd036b7b239f2e47359bb36cb324ed2fdb3894d56ea146abafd9c20612670a06
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 ADDED
@@ -0,0 +1,121 @@
1
+ # Telegem Changelog
2
+
3
+ ## v3.4.0(latest)
4
+
5
+ - added bot api 9.6 full support
6
+ - all fixes from v3.3.2-rc.1
7
+
8
+
9
+ ## v3.3.2-rc.1
10
+
11
+ ### Fixed
12
+ - Webhook `set_webhook` now correctly passes URL as positional argument
13
+ - Removed unsafe thread usage in `Context#with_typing` (async-safe now)
14
+ - Added automatic retry with exponential backoff in API client
15
+ - Improved `telegem-ssl` to detect dnf/yum on Fedora/RHEL
16
+
17
+ ### Changed
18
+ - No breaking changes. Safe upgrade from v3.3.1.
19
+
20
+
21
+ ## v3.3.1
22
+ ### Features
23
+ - improved memeorystore to include diskbackup
24
+ - added 'telegem-init' cli
25
+
26
+
27
+ ## v3.1.1
28
+
29
+ ### New Features
30
+
31
+ -FileExtractor Plugin: New plugin for extracting content from various file types (PDF, JSON, HTML, TXT)
32
+ - Async File Download: Added download method to API client for downloading Telegram files
33
+ - Context File Helpers: Added download_file, download_photo, download_document methods to Context
34
+ - Extended File Support: Plugin supports PDF text extraction, JSON parsing, HTML/raw text processing
35
+ - Async/Sync Dual Mode: All file operations available in both sync (download) and async (download!) modes
36
+
37
+ ## v3.1.0
38
+
39
+ ### features
40
+ - BREAKING: Rewrote polling system to prevent duplicate messages
41
+ - Fixed thread deadlock in async polling loop
42
+ - Added scene_middleware.rb for scene-based conversations
43
+ - Improved MemoryStore with TTL and thread safety
44
+ - Enhanced keyboard markup builder with web_app support
45
+ - Added message reaction and chat boost update types
46
+ - Fixed callback query handling for inline keyboards
47
+
48
+ ## v3.0.0
49
+ ### features
50
+
51
+ - BREAKING: Complete async rewrite with async gem
52
+ - New HTTP client using HTTPX with proper async/await pattern
53
+ - Added scene system for multi-step conversations
54
+ - Middleware composer system for plugin architecture
55
+ - Type system with dynamic accessors for Telegram objects
56
+ - Session management with memory store
57
+ - Rate limiting middleware
58
+ - File upload support via multipart forms
59
+
60
+ ## v2.0.0
61
+
62
+ - BREAKING: Ruby 3.0+ requirement
63
+ - Added webhook support with Rack middleware
64
+ - Inline query and callback query handlers
65
+ - Location, contact, and poll answer handlers
66
+ - Keyboard markup helpers (Telegem::Markup)
67
+ - Improved error handling with custom error classes
68
+ - Logging integration with configurable loggers
69
+
70
+ ## v1.5.0
71
+
72
+ - Added command argument parsing (ctx.command_args)
73
+ - Message entity parsing (mentions, hashtags, bot commands)
74
+ - Chat member update handlers
75
+ - Pre-checkout and shipping query support
76
+ - File download helper methods
77
+ - Context helper methods for common API calls
78
+
79
+ ## v1.0.0
80
+
81
+ - Stable API release
82
+ - Message handlers with text pattern matching
83
+ - Command handlers with regex support
84
+ - Basic context object with chat/message accessors
85
+ - Simple API client with error handling
86
+ - Polling and webhook modes
87
+ - Configuration options for timeout and limits
88
+
89
+ ## v0.5.0
90
+
91
+ - Added callback query support
92
+ - Inline keyboard builder
93
+ - Message editing and deletion helpers
94
+ - Media sending methods (photo, document, audio, video)
95
+ - Chat action methods (typing, upload indicators)
96
+
97
+ ## v0.3.0
98
+
99
+ - Middleware system with bot.use
100
+ - Session management foundation
101
+ - Basic rate limiting
102
+ - Command filtering by chat type
103
+ - Improved logging with debug levels
104
+
105
+ ## v0.2.0
106
+
107
+ - Basic polling implementation
108
+ - Message type detection (text, photo, document)
109
+ - Command parsing with arguments
110
+ - Simple reply methods
111
+ - Error handling for API calls
112
+
113
+ ## v0.1.0 (Initial Release)
114
+
115
+ - Basic Telegram Bot API wrapper
116
+ - Send/receive messages
117
+ - Simple command handling
118
+ - Minimal dependencies (just httparty)
119
+ - Support for basic message types
120
+
121
+ ---
data/Gemfile CHANGED
@@ -5,5 +5,5 @@ gemspec
5
5
  group :development do
6
6
  gem 'rake', '~> 13.0'
7
7
  gem 'rspec', '~> 3.0'
8
- gem 'pry', '~> 0.14.0'
8
+ gem 'pry', '~> 0.16.0'
9
9
  end
data/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # Telegem Documentation
2
+
3
+ Welcome to the comprehensive documentation for Telegem, a modern Ruby framework for building Telegram bots.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/telegem.svg)](https://badge.fury.io/rb/telegem)
6
+ [![Join Telegram Group](https://img.shields.io/badge/Telegram-Join%20Group-2CA5E0?style=flat-square&logo=telegram&logoColor=white)](https://t.me/r_telegem)
7
+
8
+
9
+
10
+ ## Table of Contents
11
+
12
+ ### Getting Started
13
+ - [README](README.md) - Main project README
14
+ - [Getting Started](getting_started.md) - Installation and basic setup
15
+ - [Core Concepts](core_concepts.md) - Understanding Telegem architecture
16
+
17
+ ### Core Components
18
+ - [Bot](bot.md) - Main bot class and configuration
19
+ - [Context](context.md) - Update context and response methods
20
+ - [Handlers](handlers.md) - Command, hears, and event handlers
21
+ - [Middleware](middleware.md) - Request processing pipeline
22
+ - [Scenes](scenes.md) - Multi-step conversation flows
23
+ - [Sessions](sessions.md) - Data persistence between updates
24
+
25
+ ### API & Types
26
+ - [API](api.md) - Telegram API client usage
27
+ - [Types](types.md) - Type-safe API response handling
28
+ - [Keyboards](keyboards.md) - Inline and reply keyboard DSL
29
+
30
+ ### Advanced Features
31
+ - [Plugins](plugins.md) - Built-in and custom plugins
32
+ - [Webhooks](webhooks.md) - Production webhook deployment
33
+ - [Error Handling](error_handling.md) - Comprehensive error management
34
+ - [Testing](testing.md) - Unit and integration testing
35
+ - [Deployment](deployment.md) - Production deployment guides
36
+
37
+ ### Examples & Guides
38
+ - [Examples](examples.md) - Complete bot examples
39
+ - [Troubleshooting](troubleshooting.md) - Common issues and solutions
40
+ - [Contributing](contributing.md) - Development guidelines
41
+ - [Changelog](changelog.md) - Version history and changes
42
+
43
+ ## Quick Start
44
+
45
+ 1. **Install Telegem:**
46
+ ```bash
47
+ gem install telegem
48
+ ```
49
+
50
+ 2. **Create your first bot:**
51
+ ```ruby
52
+ require 'telegem'
53
+
54
+ bot = Telegem.new(token: 'YOUR_BOT_TOKEN')
55
+
56
+ bot.command('start') do |ctx|
57
+ ctx.reply('Hello, World!')
58
+ end
59
+
60
+ bot.start_polling
61
+ ```
62
+
63
+ 3. **Explore features:**
64
+ - Add [handlers](handlers.md) for different message types
65
+ - Use [sessions](sessions.md) for data persistence
66
+ - Implement [scenes](scenes.md) for complex conversations
67
+ - Deploy with [webhooks](webhooks.md) for production
68
+
69
+ ## Key Features
70
+
71
+ - **Async I/O**: Built on the Async gem for high performance
72
+ - **Type Safety**: Automatic type conversion for API responses
73
+ - **Session Management**: Built-in session stores (Memory, Redis)
74
+ - **Plugin System**: Extensible with custom plugins
75
+ - **Scene System**: Complex conversation flows
76
+ - **Middleware**: Request processing pipeline
77
+ - **Error Handling**: Comprehensive error recovery
78
+ - **Testing**: Full test suite with mocking support
79
+
80
+ ## Architecture Overview
81
+
82
+ ```
83
+ ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā” ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
84
+ │ Telegram API │◄──►│ API Client │◄──►│ Handlers │
85
+ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
86
+ ā–²
87
+ │
88
+ ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
89
+ │ Middleware │
90
+ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
91
+ ā–²
92
+ │
93
+ ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
94
+ │ Sessions │
95
+ ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
96
+ ```
97
+
98
+ ## Support
99
+
100
+ - **Documentation**: You're reading it!
101
+ - **Issues**: [GitHub Issues](https://github.com/telegem/telegem/issues)
102
+ - **Discussions**: [GitHub Discussions](https://github.com/telegem/telegem/discussions)
103
+ - **Examples**: Check the `examples/` directory
104
+
105
+ ## Contributing
106
+
107
+ We welcome contributions! See our [contributing guide](contributing.md) for details.
108
+
109
+ ## License
110
+
111
+ Telegem is released under the MIT License. See the main README for details.
112
+
113
+ ---
114
+
115
+ **Happy bot building with Telegem! šŸ¤–**
116
+
117
+ ```ruby
118
+ gem 'telegem'
119
+ ```
120
+
121
+ ## Basic Usage
122
+
123
+ ```ruby
124
+ require 'telegem'
125
+
126
+ bot = Telegem.new('YOUR_BOT_TOKEN')
127
+
128
+ bot.command('start') do |ctx|
129
+ ctx.reply("Hello, #{ctx.from.first_name}!")
130
+ end
131
+
132
+ bot.start_polling
133
+ ```
134
+
135
+ ## Requirements
136
+
137
+ - Ruby 3.0+
138
+ - Telegram Bot Token from [@BotFather](https://t.me/botfather)
139
+
140
+ ## License
141
+
142
+ MIT License - see [LICENSE](../LICENSE) file for details.
143
+
144
+ ## Contributing
145
+
146
+ See [Contributing Guide](contributing.md) for development setup and contribution guidelines.</content>
147
+ <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"