telegem 3.3.1 → 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.
@@ -0,0 +1,91 @@
1
+ # lib/session/redis_store.rb
2
+ require 'json'
3
+ require 'time'
4
+
5
+ module Telegem
6
+ module Session
7
+ class RedisStore
8
+ def initialize(redis_url: nil, default_ttl: 300, **options)
9
+ @default_ttl = default_ttl
10
+
11
+ # Load redis gem only when needed
12
+ begin
13
+ require 'redis'
14
+ rescue LoadError
15
+ raise "Redis store requires 'redis' gem. Add 'gem \"redis\"' to your Gemfile."
16
+ end
17
+
18
+ @redis = if redis_url
19
+ Redis.new(url: redis_url, **options)
20
+ else
21
+ Redis.new(**options)
22
+ end
23
+ end
24
+
25
+ def set(key, value, ttl: nil)
26
+ key_s = key.to_s
27
+ serialized = JSON.generate(value)
28
+ ttl_sec = ttl || @default_ttl
29
+
30
+ @redis.setex(key_s, ttl_sec, serialized)
31
+ value
32
+ end
33
+
34
+ def get(key)
35
+ key_s = key.to_s
36
+ data = @redis.get(key_s)
37
+ return nil unless data
38
+
39
+ JSON.parse(data)
40
+ rescue JSON::ParserError
41
+ nil
42
+ end
43
+
44
+ def delete(key)
45
+ key_s = key.to_s
46
+ @redis.del(key_s) > 0
47
+ end
48
+
49
+ def increment(key, amount = 1, ttl: nil)
50
+ key_s = key.to_s
51
+ ttl_sec = ttl || @default_ttl
52
+
53
+ # Atomic increment using Redis
54
+ new_val = @redis.incrby(key_s, amount)
55
+
56
+ # Set expiry if this is a new key or if TTL changed
57
+ if ttl_sec
58
+ @redis.expire(key_s, tttl_sec)
59
+ end
60
+
61
+ new_val
62
+ end
63
+
64
+ def clear_all
65
+ # Be careful with this in production
66
+ @redis.flushdb
67
+ end
68
+
69
+ def close
70
+ @redis.close
71
+ end
72
+
73
+ private
74
+
75
+ def with_retry(max_retries = 3, &block)
76
+ retries = 0
77
+ begin
78
+ block.call
79
+ rescue Redis::BaseError => e
80
+ retries += 1
81
+ if retries <= max_retries
82
+ sleep 0.1 * retries
83
+ retry
84
+ else
85
+ raise
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
data/lib/telegem.rb CHANGED
@@ -3,7 +3,7 @@ require 'logger'
3
3
  require 'json'
4
4
 
5
5
  module Telegem
6
- VERSION = "3.3.1".freeze
6
+ VERSION = "3.4.0"
7
7
  end
8
8
 
9
9
  #
@@ -50,7 +50,7 @@ module Telegem
50
50
 
51
51
  def self.webhook(bot, **options)
52
52
  require_relative 'webhook/server'
53
- Webhook::Server.setup(bot, **options)
53
+ Webhook::Server.new(bot, **options)
54
54
  end
55
55
 
56
56
  def self.info
@@ -68,7 +68,7 @@ module Telegem
68
68
  • Fluent keyboard DSL
69
69
  • Cloud-ready webhook server
70
70
 
71
- Website: https://gitlab.com/ruby-telegem/telegem
71
+ Website: https://github.com/slick-lab/telegem
72
72
  INFO
73
73
  end
74
74
  end
@@ -116,6 +116,9 @@ module Telegem
116
116
 
117
117
  def handle_webhook_request(request)
118
118
  return [405, {}, ["Method Not Allowed"]] unless request.post?
119
+ received = request.headers['X-Telegram-Bot-Api-Secret-Token'] ||
120
+ request.headers['x-telegram-bot-api-secret-token']
121
+ return [403, {}, ["Forbidden"]] unless received == @secret_token
119
122
 
120
123
  begin
121
124
  body = request.body.read
@@ -163,8 +166,7 @@ module Telegem
163
166
 
164
167
  def set_webhook(**options)
165
168
  url = webhook_url
166
- params = { url: url }.merge(options)
167
- @bot.set_webhook(**params)
169
+ @bot.set_webhook(url, **options)
168
170
  @logger.info("Webhook set to: #{url}")
169
171
  url
170
172
  end
@@ -183,4 +185,4 @@ module Telegem
183
185
  end
184
186
  end
185
187
  end
186
- end
188
+ end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegem
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zendrx
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-24 00:00:00.000000000 Z
11
+ date: 2026-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: concurrent-ruby
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 1.3.6
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 1.3.6
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: securerandom
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -124,33 +110,50 @@ dependencies:
124
110
  version: '1.50'
125
111
  description: |
126
112
  Telegem is a modern Telegram Bot Framework for Ruby inspired by Telegraf.js.
127
- Built with async-first design using HTTPX, featuring scenes, middleware,
113
+ Built with async-first design using async-http, featuring scenes, middleware,
128
114
  and a clean DSL. Perfect for building scalable Telegram bots.
129
115
  email:
130
116
  - ynwghosted@icloud.com
131
117
  executables:
132
118
  - telegem-ssl
133
- - telegem-init
134
119
  extensions: []
135
120
  extra_rdoc_files: []
136
121
  files:
122
+ - ".rubocop.yml"
137
123
  - CHANGELOG.md
138
124
  - CODE_OF_CONDUCT.md
139
- - Contributing.md
140
125
  - Gemfile
141
126
  - Gemfile.lock
142
127
  - LICENSE
143
- - Readme.md
128
+ - README.md
144
129
  - Starts_HallofFame.md
145
130
  - assets/.gitkeep
146
131
  - assets/logo.png
147
132
  - bin/.gitkeep
148
- - bin/telegem-init
149
133
  - bin/telegem-ssl
134
+ - contributing.md
150
135
  - docs/.gitkeep
136
+ - docs/api.md
137
+ - docs/bot.md
138
+ - docs/changelog.md
139
+ - docs/context.md
140
+ - docs/core_concepts.md
151
141
  - docs/ctx.md
142
+ - docs/deployment.md
143
+ - docs/error_handling.md
144
+ - docs/examples.md
152
145
  - docs/file_extract.md
153
- - examples/.gitkeep
146
+ - docs/getting_started.md
147
+ - docs/handlers.md
148
+ - docs/keyboards.md
149
+ - docs/middleware.md
150
+ - docs/plugins.md
151
+ - docs/scenes.md
152
+ - docs/sessions.md
153
+ - docs/testing.md
154
+ - docs/troubleshooting.md
155
+ - docs/types.md
156
+ - docs/webhooks.md
154
157
  - lib/api/client.rb
155
158
  - lib/api/types.rb
156
159
  - lib/core/bot.rb
@@ -162,14 +165,16 @@ files:
162
165
  - lib/markup/inline.rb
163
166
  - lib/markup/keyboard.rb
164
167
  - lib/plugins/.gitkeep
168
+ - lib/plugins/cc
165
169
  - lib/plugins/file_extract.rb
170
+ - lib/plugins/translate.rb
166
171
  - lib/session/memory_store.rb
167
172
  - lib/session/middleware.rb
173
+ - lib/session/redis.rb
168
174
  - lib/session/scene_middleware.rb
169
175
  - lib/telegem.rb
170
176
  - lib/webhook/.gitkeep
171
177
  - lib/webhook/server.rb
172
- - public/.gitkeep
173
178
  homepage: https://github.com/slick-lab/telegem
174
179
  licenses:
175
180
  - MIT
@@ -178,12 +183,19 @@ metadata:
178
183
  source_code_uri: https://github.com/slick-lab/telegem
179
184
  changelog_uri: https://github.com/slick-lab/telegem/-/blob/main/CHANGELOG.md
180
185
  bug_tracker_uri: https://github.com/slick-lab/telegem/-/issues
181
- documentation_uri: https://gitlab.com/ruby-telegem/telegem/-/tree/main/docs-src?ref_type=heads
186
+ documentation_uri: https://github.com/slick-lab/telegem/tree/main/docs
182
187
  rubygems_mfa_required: 'false'
183
- post_install_message: "Thanks for installing Telegem 3.3.1!\n\n\U0001F4DA Documentation:
184
- https://github.com/slick-lab/telegem\n\n\U0001F510 For SSL Webhooks:\nRun: telegem-ssl
185
- your-domain.com\nThis sets up Let's Encrypt certificates automatically.\n\n\U0001F916
186
- Happy bot building!\n"
188
+ post_install_message: |
189
+ Thanks for installing Telegem 3.4.0!
190
+
191
+ Documentation: https://github.com/slick-lab/telegem
192
+
193
+ For SSL Webhooks:
194
+ Run: telegem-ssl your-domain.com
195
+ This sets up Let's Encrypt certificates automatically.
196
+
197
+ join the official telegram group: https://t.me/r_telegem
198
+ Happy bot building!
187
199
  rdoc_options: []
188
200
  require_paths:
189
201
  - lib
@@ -191,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
203
  requirements:
192
204
  - - ">="
193
205
  - !ruby/object:Gem::Version
194
- version: 3.1.0
206
+ version: 3.4.0
195
207
  required_rubygems_version: !ruby/object:Gem::Requirement
196
208
  requirements:
197
209
  - - ">="
data/Contributing.md DELETED
@@ -1,161 +0,0 @@
1
- # 🤝 contributing to Telegem
2
-
3
- Thank you for your interest in contributing to Telegem! This document provides guidelines and instructions for contributing to Telegem.
4
- whether you are fixing bugs, improving documentation or proposing new features, your contributions are welcome
5
-
6
- ## 📋 Table of Contents
7
- - [Code of Conduct](#-code-of-conduct)
8
- - [Getting Started](#-getting-started)
9
- - [How to Contribute](#-how-to-contribute)
10
- - [Reporting Bugs](#reporting-bugs)
11
- - [Suggesting Features](#suggesting-features)
12
- - [Code Contributions](#code-contributions)
13
- - [Documentation](#documentation)
14
- - [Development Setup](#-development-setup)
15
- - [Pull Request Process](#-pull-request-process)
16
- - [Style Guides](#-style-guides)
17
- - [Community](#-community)
18
- - [Recognition](#-recognition)
19
-
20
- ## code of conduct
21
-
22
- We are committed to providing a welcoming and inspiring community for all. Please read our [Code of Conduct](CODE_OF_CONDUCT.md) before participating.
23
-
24
- ## 🚀 Getting Started
25
-
26
- ### Prerequisites
27
- - Ruby v3.x
28
- - Git
29
-
30
- ### Quick Start
31
- 1. **Fork the repository** on GitLab
32
- 2. **Clone your fork:**
33
- ```bash
34
- git clone https://gitlab.com/your-username/telegem.git
35
- cd telegem
36
- ```
37
- 3. Install dependencies
38
- ```bash
39
- $ gem install
40
- ```
41
- 4. run test
42
- ```bash
43
- $ rspec test/spec.rb
44
- ```
45
- ## How to contribute
46
-
47
- ##reporting bugs
48
- Bugs are tracked as Gitlab Issues
49
-
50
- **before submitting a bug report:**
51
- - check if the issue has already been reported
52
- - update to the latest version to see if issues persists
53
- - check the documentation and existing solutions to the issue
54
- **A good report includes:**
55
- 1. clear descriptive title
56
- 2. steps to be reproduced (be specific)
57
- 3. expected behavior
58
- 4. relevant logs or message
59
-
60
- Code Contributions
61
-
62
- 1. Find an issue to work on:
63
- - Check issues labeled good first issue or help wanted
64
- - Comment on the issue to let us know you're working on it
65
- 2. Create a feature branch:
66
- ```bash
67
- git checkout -b feature/your-feature-name
68
- # or
69
- git checkout -b fix/issue-description
70
- ```
71
- 3. Make your changes
72
- 4. Write/update tests
73
- 5. Update documentation if needed
74
- 6. Run tests locally:
75
- ```bash
76
- rspec test/spec.rb
77
- ```
78
-
79
- Documentation
80
-
81
- Good documentation is crucial! You can help by:
82
-
83
- - Fixing typos or unclear explanations
84
- - Adding examples to existing documentation
85
- - Writing tutorials or how-to guides
86
- - Improving API documentation
87
- - Translating documentation
88
-
89
- Testing
90
-
91
- ```bash
92
- # Run all tests
93
- rspec test/spec.rb
94
-
95
- bundle exec bundle-audit
96
- ```
97
-
98
- 🎯 Pull Request Process
99
-
100
- 1. Update your fork with the latest changes from upstream:
101
- ```bash
102
- git remote add upstream https://gitlab.com/ruby-telegem/telegem.git
103
- git fetch upstream
104
- git rebase upstream/main
105
- ```
106
- 2. Ensure all tests pass
107
- 3. Update documentation if your changes affect functionality
108
- 4. Create a Merge Request (MR) on GitLab:
109
- - Use a clear, descriptive title
110
- - Reference any related issues (e.g., "Closes #123")
111
- 5. Address review feedback promptly
112
- 6. Once approved, a maintainer will merge your changes
113
-
114
-
115
-
116
-
117
-
118
- 👥 Community
119
-
120
- Discussion
121
-
122
- - Issues: GitLab Issues
123
- - Merge Requests: GitLab MRs
124
-
125
- Getting Help
126
-
127
- - Search existing issues and documentation first
128
- - Be respectful and patient with other community members
129
- - Provide as much context as possible when asking for help
130
-
131
- 🏆 Recognition
132
-
133
- All contributors are recognized in our HALL_OF_FAME.md. We appreciate every contribution, big or small!
134
-
135
- Contributors who make significant impact may be:
136
-
137
- - Added to the "Active Contributors" section
138
- - Given commit access (for trusted, regular contributors)
139
- - Featured in release notes
140
-
141
-
142
-
143
- Release Cycle
144
-
145
- - We follow Semantic Versioning
146
- - Major releases
147
- - Minor releases
148
- - Patch releases
149
-
150
- License
151
-
152
- By contributing, you agree that your contributions will be licensed under the project's LICENSE.
153
-
154
- ---
155
-
156
- Thank you for contributing to Telegem! Your efforts help make this project better for everyone. 🚀
157
-
158
- ```
159
-
160
-
161
-