TeLLMgramBot 3.13.0__tar.gz → 3.13.2__tar.gz
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.
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/PKG-INFO +6 -4
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/README.md +5 -3
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/TeLLMgramBot.py +14 -13
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/initialize.py +57 -28
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot.egg-info/PKG-INFO +6 -4
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/setup.py +1 -1
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/LICENSE +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/__init__.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/archive.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/conversation.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/database.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/message_handlers.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/models.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/providers/__init__.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/providers/anthropic_provider.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/providers/base.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/providers/factory.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/providers/openai_provider.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/tools.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/utils.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot/web_utils.py +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot.egg-info/SOURCES.txt +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot.egg-info/dependency_links.txt +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot.egg-info/requires.txt +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/TeLLMgramBot.egg-info/top_level.txt +0 -0
- {tellmgrambot-3.13.0 → tellmgrambot-3.13.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: TeLLMgramBot
|
|
3
|
-
Version: 3.13.
|
|
3
|
+
Version: 3.13.2
|
|
4
4
|
Summary: LLM-powered Telegram bot (OpenAI + Anthropic)
|
|
5
5
|
Home-page: https://github.com/Digital-Heresy/TeLLMgramBot
|
|
6
6
|
Author: Digital Heresy
|
|
@@ -82,9 +82,9 @@ TeLLMgramBot creates the following directories:
|
|
|
82
82
|
- `test_personality.prmpt` - Sample bot personality (multi-provider, can be renamed)
|
|
83
83
|
- `url_analysis.prmpt` - URL summarization prompt template
|
|
84
84
|
- A system appendix is automatically appended to every persona at runtime, teaching the LLM about cross-chat memory and search behavior. User messages include speaker annotations with chat context and timestamps so the LLM always knows who is speaking, in which chat, and when.
|
|
85
|
-
- **`logs`** - Bot instance logs (one per startup, e.g. `
|
|
86
|
-
- Logs include anonymized Telegram IDs for privacy. Console shows INFO-level TeLLMgramBot messages only.
|
|
87
|
-
- Bot keeps the 10 most recent logs, automatically pruning older ones.
|
|
85
|
+
- **`logs`** - Bot instance logs (one per startup, named after the bot's Telegram username or `log_name` config, e.g. `my_bot_2026-03-29_10-30-45.log`)
|
|
86
|
+
- Logs include anonymized Telegram IDs for privacy. Console shows INFO-level TeLLMgramBot messages only, prefixed with an `[identity label]` (the bot's Telegram username by default, or `log_name` when configured).
|
|
87
|
+
- Bot keeps the 10 most recent logs per bot instance, automatically pruning older ones.
|
|
88
88
|
- Pass `-v` or `--verbose` on startup for DEBUG-level logging.
|
|
89
89
|
- **`data`** - SQLite database (default `conversations.db`, customizable via `db_name` config) storing all messages, users, and chats
|
|
90
90
|
- Users manage their data via `/forget` and `/private` commands.
|
|
@@ -153,9 +153,11 @@ When the bot is triggered in a group and about to respond (not deferring to anot
|
|
|
153
153
|
- `url_model`: LLM model for URL analysis (e.g. `gpt-4o` or `claude-haiku-4-5`)
|
|
154
154
|
- `bot_nickname` / `bot_initials`: Names the bot responds to in groups
|
|
155
155
|
- `db_name`: Optional custom database filename without extension (e.g. `MyBot` creates `MyBot.db`); omit for default `conversations.db`. Use distinct names when running multiple bot instances in the same directory.
|
|
156
|
+
- `log_name`: Optional label used for the console prefix and log filename (e.g. `MyBot` produces `[MyBot] INFO: ...` on the console and `MyBot_{timestamp}.log`); omit to use the bot's Telegram username. Useful for multi-platform deployments sharing the same config.
|
|
156
157
|
- `token_limit`: Max tokens (optional; defaults to model's maximum)
|
|
157
158
|
- `search_limit`: Max search results (optional; defaults to 30)
|
|
158
159
|
- `archive_days`: Days before messages are eligible for archival (optional; default 60, minimum 1). Older messages are distilled into daily summaries, then progressively compressed into monthly digests. Once archived their respective raw messages do not return to the LLM context any more, only when searching messages.
|
|
160
|
+
- `allow_local_webhooks`: Set to `true` to permit webhook/MCP URLs targeting loopback or link-local addresses (optional; default `false`). Useful when tools like Home Assistant run on the same host.
|
|
159
161
|
- `tools`: Optional list of webhook and MCP tool definitions (admin-only, private chat only). See [docs/tools.md](docs/tools.md) for schema and examples.
|
|
160
162
|
4. **Disable group privacy mode in BotFather:**
|
|
161
163
|
```
|
|
@@ -50,9 +50,9 @@ TeLLMgramBot creates the following directories:
|
|
|
50
50
|
- `test_personality.prmpt` - Sample bot personality (multi-provider, can be renamed)
|
|
51
51
|
- `url_analysis.prmpt` - URL summarization prompt template
|
|
52
52
|
- A system appendix is automatically appended to every persona at runtime, teaching the LLM about cross-chat memory and search behavior. User messages include speaker annotations with chat context and timestamps so the LLM always knows who is speaking, in which chat, and when.
|
|
53
|
-
- **`logs`** - Bot instance logs (one per startup, e.g. `
|
|
54
|
-
- Logs include anonymized Telegram IDs for privacy. Console shows INFO-level TeLLMgramBot messages only.
|
|
55
|
-
- Bot keeps the 10 most recent logs, automatically pruning older ones.
|
|
53
|
+
- **`logs`** - Bot instance logs (one per startup, named after the bot's Telegram username or `log_name` config, e.g. `my_bot_2026-03-29_10-30-45.log`)
|
|
54
|
+
- Logs include anonymized Telegram IDs for privacy. Console shows INFO-level TeLLMgramBot messages only, prefixed with an `[identity label]` (the bot's Telegram username by default, or `log_name` when configured).
|
|
55
|
+
- Bot keeps the 10 most recent logs per bot instance, automatically pruning older ones.
|
|
56
56
|
- Pass `-v` or `--verbose` on startup for DEBUG-level logging.
|
|
57
57
|
- **`data`** - SQLite database (default `conversations.db`, customizable via `db_name` config) storing all messages, users, and chats
|
|
58
58
|
- Users manage their data via `/forget` and `/private` commands.
|
|
@@ -121,9 +121,11 @@ When the bot is triggered in a group and about to respond (not deferring to anot
|
|
|
121
121
|
- `url_model`: LLM model for URL analysis (e.g. `gpt-4o` or `claude-haiku-4-5`)
|
|
122
122
|
- `bot_nickname` / `bot_initials`: Names the bot responds to in groups
|
|
123
123
|
- `db_name`: Optional custom database filename without extension (e.g. `MyBot` creates `MyBot.db`); omit for default `conversations.db`. Use distinct names when running multiple bot instances in the same directory.
|
|
124
|
+
- `log_name`: Optional label used for the console prefix and log filename (e.g. `MyBot` produces `[MyBot] INFO: ...` on the console and `MyBot_{timestamp}.log`); omit to use the bot's Telegram username. Useful for multi-platform deployments sharing the same config.
|
|
124
125
|
- `token_limit`: Max tokens (optional; defaults to model's maximum)
|
|
125
126
|
- `search_limit`: Max search results (optional; defaults to 30)
|
|
126
127
|
- `archive_days`: Days before messages are eligible for archival (optional; default 60, minimum 1). Older messages are distilled into daily summaries, then progressively compressed into monthly digests. Once archived their respective raw messages do not return to the LLM context any more, only when searching messages.
|
|
128
|
+
- `allow_local_webhooks`: Set to `true` to permit webhook/MCP URLs targeting loopback or link-local addresses (optional; default `false`). Useful when tools like Home Assistant run on the same host.
|
|
127
129
|
- `tools`: Optional list of webhook and MCP tool definitions (admin-only, private chat only). See [docs/tools.md](docs/tools.md) for schema and examples.
|
|
128
130
|
4. **Disable group privacy mode in BotFather:**
|
|
129
131
|
```
|
|
@@ -36,6 +36,7 @@ from .archive import run_archival
|
|
|
36
36
|
from .initialize import (
|
|
37
37
|
INIT_BOT_CONFIG,
|
|
38
38
|
ApiKeyStatus,
|
|
39
|
+
bind_log_identity,
|
|
39
40
|
init_logging,
|
|
40
41
|
init_structure,
|
|
41
42
|
)
|
|
@@ -102,6 +103,7 @@ class TelegramBot:
|
|
|
102
103
|
self.telegram['username'] = bot.username
|
|
103
104
|
self.telegram['first_name'] = bot.first_name
|
|
104
105
|
self.telegram['last_name'] = bot.last_name
|
|
106
|
+
bind_log_identity(bot.username, self._log_name)
|
|
105
107
|
except Exception as e:
|
|
106
108
|
# Fail fast if the bot's identity cannot be fetched to avoid
|
|
107
109
|
# continuing with an uninitialized self.telegram['username'].
|
|
@@ -962,7 +964,7 @@ class TelegramBot:
|
|
|
962
964
|
archive_days = INIT_BOT_CONFIG['archive_days'],
|
|
963
965
|
persona_prompt = INIT_BOT_CONFIG['persona_prompt'],
|
|
964
966
|
key_status: ApiKeyStatus | None = None,
|
|
965
|
-
log_name: str =
|
|
967
|
+
log_name: str | None = None,
|
|
966
968
|
webhook_schemas: list | None = None,
|
|
967
969
|
webhook_defs: dict | None = None,
|
|
968
970
|
):
|
|
@@ -981,6 +983,8 @@ class TelegramBot:
|
|
|
981
983
|
persona_temp: LLM temperature (0.0-2.0). If None, defaults to 1.0.
|
|
982
984
|
persona_prompt: System prompt defining the bot's behavior and personality.
|
|
983
985
|
key_status: ApiKeyStatus object indicating available features. If None, calls init_structure().
|
|
986
|
+
log_name: Optional label for console prefix and log file name (from config.yaml `log_name`).
|
|
987
|
+
Defaults to the bot's Telegram username when not set.
|
|
984
988
|
archive_days: Days before messages are eligible for Tier 1 archival (default: 60).
|
|
985
989
|
Must be an integer >= 1; invalid values log a warning and fall back to 60.
|
|
986
990
|
Tier 2 compression triggers at archive_days * 2.
|
|
@@ -997,10 +1001,11 @@ class TelegramBot:
|
|
|
997
1001
|
"""
|
|
998
1002
|
# Starting to initialize, not online yet
|
|
999
1003
|
self._online = False
|
|
1004
|
+
self._log_name = log_name
|
|
1000
1005
|
|
|
1001
1006
|
# Bootstrap structure and logging; init_logging() is a no-op if init_structure already ran it.
|
|
1002
|
-
self.key_status = key_status if key_status is not None else init_structure(
|
|
1003
|
-
init_logging(
|
|
1007
|
+
self.key_status = key_status if key_status is not None else init_structure()[0]
|
|
1008
|
+
init_logging()
|
|
1004
1009
|
|
|
1005
1010
|
# Initialize some variables
|
|
1006
1011
|
self.token_warning = {} # Determines whether user has reached token limit by AI model
|
|
@@ -1077,7 +1082,7 @@ class TelegramBot:
|
|
|
1077
1082
|
# Bot is now ready and active by default
|
|
1078
1083
|
self._online = True
|
|
1079
1084
|
|
|
1080
|
-
def set(config_file: str = 'config.yaml', prompt_file: str = 'test_personality.prmpt'
|
|
1085
|
+
def set(config_file: str = 'config.yaml', prompt_file: str = 'test_personality.prmpt'):
|
|
1081
1086
|
"""
|
|
1082
1087
|
Instantiate a TelegramBot from configuration and prompt files.
|
|
1083
1088
|
|
|
@@ -1092,8 +1097,6 @@ class TelegramBot:
|
|
|
1092
1097
|
Resolved relative to TELLMGRAMBOT_CONFIGS_PATH env var, not as a literal path.
|
|
1093
1098
|
prompt_file: Filename of the bot persona prompt (default: 'test_personality.prmpt').
|
|
1094
1099
|
Resolved relative to TELLMGRAMBOT_PROMPTS_PATH env var, not as a literal path.
|
|
1095
|
-
log_name: Base name for the log file (default: 'tellmgrambot').
|
|
1096
|
-
Produces e.g. 'mybot_2026-03-29_10-30-45.log' when set to 'mybot'.
|
|
1097
1100
|
|
|
1098
1101
|
Returns:
|
|
1099
1102
|
A fully initialized TelegramBot instance.
|
|
@@ -1102,16 +1105,14 @@ class TelegramBot:
|
|
|
1102
1105
|
- Calls init_structure() which creates directories, config/prompt files, and checks API keys.
|
|
1103
1106
|
- Calls discover_mcp_tools() if any 'mcp_server:' entries are in config (gracefully degrades if called from async context).
|
|
1104
1107
|
- Prints API key status summary and optional warnings if config values are missing or prompt is empty.
|
|
1108
|
+
- Log identity/file label is taken from config.yaml `log_name` when set; otherwise defaults to the bot's Telegram username once _tele_info() resolves.
|
|
1105
1109
|
"""
|
|
1106
1110
|
# Bootstrap directories, logging, config, prompt (with appendix), and API keys in one call.
|
|
1107
|
-
key_status, config, prompt = init_structure(config_file, prompt_file
|
|
1111
|
+
key_status, config, prompt = init_structure(config_file, prompt_file)
|
|
1108
1112
|
|
|
1109
1113
|
# Build the webhook tool registry from the optional 'tools:' block in config.yaml.
|
|
1110
|
-
allow_local = config
|
|
1111
|
-
webhook_schemas, webhook_defs = build_tool_registry(
|
|
1112
|
-
config.get('tools') or [],
|
|
1113
|
-
allow_local=allow_local,
|
|
1114
|
-
)
|
|
1114
|
+
allow_local = config['allow_local_webhooks'] or False
|
|
1115
|
+
webhook_schemas, webhook_defs = build_tool_registry(config.get('tools') or [], allow_local)
|
|
1115
1116
|
|
|
1116
1117
|
# Discover MCP tools from any 'mcp_server:' entries in the tools config.
|
|
1117
1118
|
mcp_entries = [
|
|
@@ -1144,7 +1145,7 @@ class TelegramBot:
|
|
|
1144
1145
|
archive_days = config['archive_days'],
|
|
1145
1146
|
persona_prompt = prompt,
|
|
1146
1147
|
key_status = key_status,
|
|
1147
|
-
log_name = log_name,
|
|
1148
|
+
log_name = config['log_name'],
|
|
1148
1149
|
webhook_schemas = webhook_schemas,
|
|
1149
1150
|
webhook_defs = webhook_defs,
|
|
1150
1151
|
)
|
|
@@ -103,19 +103,23 @@ INIT_BOT_CONFIG = {
|
|
|
103
103
|
'chat_model': 'gpt-5-mini',
|
|
104
104
|
'url_model': 'gpt-5',
|
|
105
105
|
'db_name': None,
|
|
106
|
+
'log_name': None,
|
|
106
107
|
'token_limit': None,
|
|
107
108
|
'search_limit': None,
|
|
108
109
|
'persona_temp': None,
|
|
109
110
|
'archive_days': None,
|
|
111
|
+
'allow_local_webhooks': None,
|
|
110
112
|
'persona_prompt': 'You are a generic test bot powered by a user-configured LLM.'
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
INIT_BOT_CONFIG_COMMENTS = {
|
|
114
116
|
'db_name': '# Optional, custom DB filename (e.g. MyBot -> MyBot.db). Defaults to conversations.db',
|
|
117
|
+
'log_name': '# Optional, label for console prefix and log file name. Defaults to the bot\'s Telegram username',
|
|
115
118
|
'token_limit': '# Optional, overrides the chat_model\'s default max token limit',
|
|
116
119
|
'search_limit': '# Optional, max results returned by message search (default: 30)',
|
|
117
120
|
'persona_temp': '# Optional, LLM temperature 0.0-2.0 (default: model\'s default)',
|
|
118
121
|
'archive_days': '# Optional, days before messages are eligible for Tier 1 archival (default: 60, min: 1). Tier 2 triggers at 2x this value.',
|
|
122
|
+
'allow_local_webhooks': '# Optional, set to true to permit webhook/MCP URLs targeting loopback or link-local addresses (default: false)',
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
# Append the framework-owned system appendix to the persona prompt.
|
|
@@ -130,27 +134,21 @@ _SYSTEM_APPENDIX = (
|
|
|
130
134
|
)
|
|
131
135
|
|
|
132
136
|
|
|
133
|
-
def init_logging(
|
|
137
|
+
def init_logging():
|
|
134
138
|
"""
|
|
135
|
-
Configure the Python logging system for TeLLMgramBot.
|
|
139
|
+
Configure the Python logging system for TeLLMgramBot (console handler only).
|
|
136
140
|
|
|
137
|
-
Sets up a console handler (INFO, TeLLMgramBot-only,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
instance log files on startup, keeping the 10 most recent.
|
|
141
|
+
Sets up a console handler (INFO, TeLLMgramBot-only, no ID redaction). The file handler
|
|
142
|
+
and console username prefix are added later by bind_log_identity() once the bot's Telegram
|
|
143
|
+
username is known.
|
|
141
144
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
Args:
|
|
145
|
-
log_name: Base name for the log file (e.g. 'mybot' -> 'mybot_2026-03-29_10-30-45.log').
|
|
146
|
-
Defaults to 'tellmgrambot'.
|
|
145
|
+
Does not depend on TELLMGRAMBOT_LOGS_PATH or init_directories(). Only
|
|
146
|
+
bind_log_identity() requires the logs path to have been resolved.
|
|
147
147
|
"""
|
|
148
148
|
global _logging_initialized
|
|
149
149
|
if _logging_initialized:
|
|
150
150
|
return
|
|
151
151
|
|
|
152
|
-
verbose = '-v' in sys.argv or '--verbose' in sys.argv
|
|
153
|
-
|
|
154
152
|
root_logger = logging.getLogger()
|
|
155
153
|
root_logger.setLevel(logging.DEBUG)
|
|
156
154
|
|
|
@@ -159,23 +157,57 @@ def init_logging(log_name: str = 'tellmgrambot'):
|
|
|
159
157
|
console_handler.setFormatter(_ConsoleFormatter('%(levelname)s: %(message)s'))
|
|
160
158
|
console_handler.addFilter(lambda r: r.name.startswith('TeLLMgramBot'))
|
|
161
159
|
|
|
162
|
-
logs_dir = os.environ.get('TELLMGRAMBOT_LOGS_PATH') or gettempdir()
|
|
163
|
-
os.makedirs(logs_dir, exist_ok=True)
|
|
164
|
-
log_path = os.path.join(logs_dir, generate_filename(log_name))
|
|
165
|
-
file_handler = logging.FileHandler(log_path, encoding='utf-8')
|
|
166
|
-
file_handler.setLevel(logging.DEBUG if verbose else logging.INFO)
|
|
167
|
-
file_handler.setFormatter(_RedactedFileFormatter('%(asctime)s %(levelname)s %(name)s: %(message)s'))
|
|
168
|
-
|
|
169
160
|
root_logger.addHandler(console_handler)
|
|
170
|
-
root_logger.addHandler(file_handler)
|
|
171
161
|
_logging_initialized = True
|
|
172
162
|
|
|
173
163
|
# Suppress noisy third-party INFO logs from appearing in the file
|
|
174
164
|
logging.getLogger('httpx').setLevel(logging.WARNING)
|
|
175
165
|
logging.getLogger('httpcore').setLevel(logging.WARNING)
|
|
176
166
|
|
|
177
|
-
|
|
178
|
-
|
|
167
|
+
|
|
168
|
+
def bind_log_identity(username: str, log_name: Optional[str] = None):
|
|
169
|
+
"""
|
|
170
|
+
Bind the bot's identity to the logging system.
|
|
171
|
+
|
|
172
|
+
Updates the console handler formatter to prefix every line with [log_name] and opens
|
|
173
|
+
the per-instance log file named {log_name}_{timestamp}.log.
|
|
174
|
+
|
|
175
|
+
Must be called after the bot's Telegram username is resolved by _tele_info().
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
username: The bot's Telegram username (without @); used as the identity label when
|
|
179
|
+
log_name is not set.
|
|
180
|
+
log_name: Optional override from config.yaml. When set, used for both the console
|
|
181
|
+
prefix and log file name instead of the Telegram username -- useful for
|
|
182
|
+
multi-platform deployments where the same bot runs on Telegram and Discord.
|
|
183
|
+
"""
|
|
184
|
+
raw_label = log_name or username
|
|
185
|
+
# Sanitize: strip path separators so a misconfigured log_name cannot escape TELLMGRAMBOT_LOGS_PATH
|
|
186
|
+
label = os.path.basename(raw_label).strip()
|
|
187
|
+
if not label:
|
|
188
|
+
label = username
|
|
189
|
+
|
|
190
|
+
root_logger = logging.getLogger()
|
|
191
|
+
|
|
192
|
+
# Idempotency: skip if a FileHandler is already attached (e.g. multiple TelegramBot instances)
|
|
193
|
+
if any(isinstance(h, logging.FileHandler) for h in root_logger.handlers):
|
|
194
|
+
return
|
|
195
|
+
|
|
196
|
+
for handler in root_logger.handlers:
|
|
197
|
+
if isinstance(handler, logging.StreamHandler) and not isinstance(handler, logging.FileHandler):
|
|
198
|
+
handler.setFormatter(_ConsoleFormatter(f'[{label}] %(levelname)s: %(message)s'))
|
|
199
|
+
|
|
200
|
+
verbose = '-v' in sys.argv or '--verbose' in sys.argv
|
|
201
|
+
logs_dir = os.environ.get('TELLMGRAMBOT_LOGS_PATH') or gettempdir()
|
|
202
|
+
os.makedirs(logs_dir, exist_ok=True)
|
|
203
|
+
log_path = os.path.join(logs_dir, generate_filename(label))
|
|
204
|
+
file_handler = logging.FileHandler(log_path, encoding='utf-8')
|
|
205
|
+
file_handler.setLevel(logging.DEBUG if verbose else logging.INFO)
|
|
206
|
+
file_handler.setFormatter(_RedactedFileFormatter('%(asctime)s %(levelname)s %(name)s: %(message)s'))
|
|
207
|
+
root_logger.addHandler(file_handler)
|
|
208
|
+
|
|
209
|
+
# Prune old log files for this bot - keep the 10 most recent
|
|
210
|
+
instance_logs = sorted(glob(os.path.join(logs_dir, f'{label}_*.log')))
|
|
179
211
|
for old_log in instance_logs[:-10]:
|
|
180
212
|
try:
|
|
181
213
|
os.remove(old_log)
|
|
@@ -495,12 +527,11 @@ def init_url_prompt(file: str = 'url_analysis.prmpt') -> str:
|
|
|
495
527
|
def init_structure(
|
|
496
528
|
config_file: str = 'config.yaml',
|
|
497
529
|
prompt_file: str = 'test_personality.prmpt',
|
|
498
|
-
log_name: str = 'tellmgrambot',
|
|
499
530
|
) -> tuple[ApiKeyStatus, dict, str]:
|
|
500
531
|
"""
|
|
501
532
|
Performs the whole TeLLMgramBot first-run setup including:
|
|
502
533
|
- Directories for configurations, prompts, and conversation/error logs.
|
|
503
|
-
- Logging configuration (console
|
|
534
|
+
- Logging configuration (console handler; file handler bound later by bind_log_identity()).
|
|
504
535
|
- Database naming and schema initialization from config (conversations.db or custom db_name).
|
|
505
536
|
- Provider-conditional API keys (OpenAI/Anthropic determined by config.yaml model prefixes).
|
|
506
537
|
- Configuration files (config.yaml, models.yaml) with inline parameter descriptions.
|
|
@@ -519,15 +550,13 @@ def init_structure(
|
|
|
519
550
|
Resolved relative to TELLMGRAMBOT_CONFIGS_PATH.
|
|
520
551
|
prompt_file: Name of the bot persona prompt file (default: 'test_personality.prmpt').
|
|
521
552
|
Resolved relative to TELLMGRAMBOT_PROMPTS_PATH.
|
|
522
|
-
log_name: Base name for the per-instance log file (default: 'tellmgrambot').
|
|
523
|
-
Passed through to init_logging().
|
|
524
553
|
|
|
525
554
|
Returns:
|
|
526
555
|
Tuple of (ApiKeyStatus, parsed config dict, persona prompt string with framework-owned
|
|
527
556
|
system appendix automatically appended).
|
|
528
557
|
"""
|
|
529
558
|
init_directories()
|
|
530
|
-
init_logging(
|
|
559
|
+
init_logging()
|
|
531
560
|
|
|
532
561
|
# Configurations for bot and LLM models
|
|
533
562
|
config = init_bot_config(config_file)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: TeLLMgramBot
|
|
3
|
-
Version: 3.13.
|
|
3
|
+
Version: 3.13.2
|
|
4
4
|
Summary: LLM-powered Telegram bot (OpenAI + Anthropic)
|
|
5
5
|
Home-page: https://github.com/Digital-Heresy/TeLLMgramBot
|
|
6
6
|
Author: Digital Heresy
|
|
@@ -82,9 +82,9 @@ TeLLMgramBot creates the following directories:
|
|
|
82
82
|
- `test_personality.prmpt` - Sample bot personality (multi-provider, can be renamed)
|
|
83
83
|
- `url_analysis.prmpt` - URL summarization prompt template
|
|
84
84
|
- A system appendix is automatically appended to every persona at runtime, teaching the LLM about cross-chat memory and search behavior. User messages include speaker annotations with chat context and timestamps so the LLM always knows who is speaking, in which chat, and when.
|
|
85
|
-
- **`logs`** - Bot instance logs (one per startup, e.g. `
|
|
86
|
-
- Logs include anonymized Telegram IDs for privacy. Console shows INFO-level TeLLMgramBot messages only.
|
|
87
|
-
- Bot keeps the 10 most recent logs, automatically pruning older ones.
|
|
85
|
+
- **`logs`** - Bot instance logs (one per startup, named after the bot's Telegram username or `log_name` config, e.g. `my_bot_2026-03-29_10-30-45.log`)
|
|
86
|
+
- Logs include anonymized Telegram IDs for privacy. Console shows INFO-level TeLLMgramBot messages only, prefixed with an `[identity label]` (the bot's Telegram username by default, or `log_name` when configured).
|
|
87
|
+
- Bot keeps the 10 most recent logs per bot instance, automatically pruning older ones.
|
|
88
88
|
- Pass `-v` or `--verbose` on startup for DEBUG-level logging.
|
|
89
89
|
- **`data`** - SQLite database (default `conversations.db`, customizable via `db_name` config) storing all messages, users, and chats
|
|
90
90
|
- Users manage their data via `/forget` and `/private` commands.
|
|
@@ -153,9 +153,11 @@ When the bot is triggered in a group and about to respond (not deferring to anot
|
|
|
153
153
|
- `url_model`: LLM model for URL analysis (e.g. `gpt-4o` or `claude-haiku-4-5`)
|
|
154
154
|
- `bot_nickname` / `bot_initials`: Names the bot responds to in groups
|
|
155
155
|
- `db_name`: Optional custom database filename without extension (e.g. `MyBot` creates `MyBot.db`); omit for default `conversations.db`. Use distinct names when running multiple bot instances in the same directory.
|
|
156
|
+
- `log_name`: Optional label used for the console prefix and log filename (e.g. `MyBot` produces `[MyBot] INFO: ...` on the console and `MyBot_{timestamp}.log`); omit to use the bot's Telegram username. Useful for multi-platform deployments sharing the same config.
|
|
156
157
|
- `token_limit`: Max tokens (optional; defaults to model's maximum)
|
|
157
158
|
- `search_limit`: Max search results (optional; defaults to 30)
|
|
158
159
|
- `archive_days`: Days before messages are eligible for archival (optional; default 60, minimum 1). Older messages are distilled into daily summaries, then progressively compressed into monthly digests. Once archived their respective raw messages do not return to the LLM context any more, only when searching messages.
|
|
160
|
+
- `allow_local_webhooks`: Set to `true` to permit webhook/MCP URLs targeting loopback or link-local addresses (optional; default `false`). Useful when tools like Home Assistant run on the same host.
|
|
159
161
|
- `tools`: Optional list of webhook and MCP tool definitions (admin-only, private chat only). See [docs/tools.md](docs/tools.md) for schema and examples.
|
|
160
162
|
4. **Disable group privacy mode in BotFather:**
|
|
161
163
|
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|