Skip to content

Commit bec3645

Browse files
committed
add sessionId
1 parent 6718145 commit bec3645

22 files changed

Lines changed: 651 additions & 147 deletions

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,8 @@ fabric.properties
478478
# http://www.sonarlint.org/commandline/
479479
# SonarLint working directories, configuration files (including credentials)
480480
.sonarlint/
481-
sonarlint/
481+
sonarlint/
482+
483+
**/.idea/db-forest-config.xml
484+
**/.idea/MarsCode*.xml
485+
**/.idea/sonarlint.xml

.serena/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/cache
2+
/project.local.yml

.serena/docs/build-and-run.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
# Build & Run
3+
4+
- **Build**: The entire solution can be built using the `dotnet build` command from the root directory.
5+
- **Run**: The sample application can be run with the command `dotnet run` from the `ZiziBot.TelegramBot.Sample` directory.
6+
- **URL**: When running, the sample application is accessible at `http://localhost:5157`.

.serena/docs/command-types.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
2+
# Command Types
3+
4+
The framework supports several types of commands, which are decorated with specific attributes.
5+
6+
#### Text Commands
7+
8+
Text commands are triggered by sending a message that starts with a forward slash (`/`) or a specific text.
9+
10+
- **`[Command("command")]`**: This attribute is used to define a command that is triggered by `/command`.
11+
- **`[TextCommand("text")]`**: This attribute is used to define a command that is triggered by the exact text `text`.
12+
- **`[DefaultCommand]`**: This attribute is used to define a command that is triggered when no other command matches.
13+
14+
```csharp
15+
public class SampleCommands : BotCommandController
16+
{
17+
[Command("ping")]
18+
[TextCommand("ping")]
19+
public async Task PingCommand()
20+
{
21+
await SendMessage("Pong!");
22+
}
23+
24+
[Command("say")]
25+
public async Task SayCommand()
26+
{
27+
await SendMessage($"You say: {Context.CommandParam}!");
28+
}
29+
30+
[DefaultCommand]
31+
public async Task DefaultCommand()
32+
{
33+
await SendMessage("Default Command!");
34+
}
35+
}
36+
```
37+
38+
#### Callback Queries
39+
40+
Callback queries are triggered when a user clicks an inline keyboard button.
41+
42+
- **`[Callback("data")]`**: This attribute is used to define a command that is triggered when the callback data is `data`.
43+
- **`[Callback]`**: This attribute is used to define a command that is triggered when no other callback query matches.
44+
45+
```csharp
46+
public class SampleCommands : BotCommandController
47+
{
48+
[Callback("ping")]
49+
public async Task PingCallback()
50+
{
51+
await AnswerCallbackQuery("User clicked Ping!");
52+
}
53+
54+
[Callback]
55+
public async Task DefaultCallback()
56+
{
57+
var text = $"Cmd: {Context.CallbackQueryCmd}" +
58+
$"\nParam: {Context.CallbackQueryParam}";
59+
await AnswerCallbackQuery(text, showAlert: true);
60+
}
61+
}
62+
```
63+
64+
#### Inline Queries
65+
66+
Inline queries are triggered when a user types the bot's username followed by a query in any chat.
67+
68+
- **`[InlineQuery("query")]`**: This attribute is used to define a command that is triggered when the inline query is `query`.
69+
- **`[InlineQuery]`**: This attribute is used to define a command that is triggered when no other inline query matches.
70+
71+
```csharp
72+
public class InlineQueryCommands : BotCommandController
73+
{
74+
[InlineQuery]
75+
public async Task InlineQueryCommand()
76+
{
77+
await AnswerInlineQuery(new List<InlineQueryResult>() {
78+
new InlineQueryResultArticle("default-inline", "Default Inline", new InputTextMessageContent("Default Inline Content")),
79+
new InlineQueryResultArticle("hello-inline", "Hello Inline", new InputTextMessageContent("Hello Inline Content"))
80+
});
81+
}
82+
83+
[InlineQuery("hello")]
84+
public async Task InlineQueryCommandHello()
85+
{
86+
await AnswerInlineQuery(new List<InlineQueryResult>() {
87+
new InlineQueryResultArticle("aa576dec-0727-4ea1-99ae-3c7cb20ea3c8", "Hello Inline", new InputTextMessageContent("Hello Inline Content"))
88+
});
89+
}
90+
}
91+
```
92+
93+
#### Event-Based Commands
94+
95+
Event-based commands are triggered by specific events in a chat.
96+
97+
- **`[TypedCommand(MessageType.NewChatMembers)]`**: This attribute is used to define a command that is triggered when a new member joins the chat.
98+
- **`[UpdateCommand(UpdateType.ChatJoinRequest)]`**: This attribute is used to define a command that is triggered when a user requests to join a chat.
99+
100+
```csharp
101+
public class EventCommands : BotCommandController
102+
{
103+
[TypedCommand(MessageType.NewChatMembers)]
104+
public async Task NewChatMembersCommand()
105+
{
106+
await SendMessage("Halo!");
107+
}
108+
109+
[UpdateCommand(UpdateType.ChatJoinRequest)]
110+
public async Task ChatJoinRequestCommand()
111+
{
112+
await SendMessage("Chat join request!");
113+
}
114+
}
115+
```

.serena/docs/configuration.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Configuration
2+
3+
The bot's configuration is managed through the `appsettings.json` file. This file allows you to set up the bot's tokens, engine mode, and other settings.
4+
5+
### Bot Tokens
6+
7+
You can configure multiple bot tokens in the `BotTokenConfig` section. Each bot has a unique name and token.
8+
9+
```json
10+
"BotTokenConfig": {
11+
"Bots": [
12+
{
13+
"Name": "Main",
14+
"Token": "YOUR_BOT_TOKEN",
15+
"Username": "YOUR_BOT_USERNAME"
16+
}
17+
]
18+
}
19+
```
20+
21+
### Engine Mode
22+
23+
The `EngineMode` property determines how the bot receives updates from Telegram. The available modes are:
24+
25+
- **`Polling`**: The bot periodically polls Telegram for new updates.
26+
- **`Webhook`**: Telegram sends updates to a specified URL.
27+
- **`Auto`**: The bot uses `Polling` in the `Development` environment and `Webhook` in other environments.
28+
29+
```json
30+
"BotEngineConfig": {
31+
"EngineMode": "Auto",
32+
"WebhookUrl": "YOUR_WEBHOOK_URL"
33+
}
34+
```

.serena/docs/dependencies.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
# Dependencies
3+
4+
- The **Framework** project uses `JetBrains.Annotations`, `Scrutor`, `UUIDNext`, and `WTelegramBot`.
5+
- The **Sample** project uses `Microsoft.AspNetCore.OpenApi` and `Serilog.AspNetCore`.

.serena/docs/initialization.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
# Initialization
3+
4+
The bot is initialized in the `Program.cs` file of the sample project. Here's a breakdown of the key steps:
5+
6+
1. **`AddZiziBotTelegramBot()`**: This extension method registers all the necessary services for the bot to run.
7+
2. **`UseZiziBotTelegramBot()`**: This extension method configures the bot and starts the engine.

.serena/docs/middleware.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Middleware
2+
3+
Middleware is a powerful feature that allows you to execute code before or after a command is executed. This is useful for tasks such as authentication, logging, and error handling.
4+
5+
### Before-Command Middleware
6+
7+
Before-command middleware is executed before a command is executed. To create a before-command middleware, you need to create a class that implements the `IBeforeCommand` interface.
8+
9+
```csharp
10+
public class UserPreparationMiddleware : IBeforeCommand
11+
{
12+
public async Task ExecuteAsync(CommandContext commandContext, CommandDelegate next)
13+
{
14+
// Your logic here
15+
await next(commandContext);
16+
}
17+
}
18+
```
19+
20+
### After-Command Middleware
21+
22+
After-command middleware is executed after a command is executed. To create an after-command middleware, you need to create a class that implements the `IAfterCommand` interface.
23+
24+
```csharp
25+
public class AfterCommandMiddleware : IAfterCommand
26+
{
27+
public async Task ExecuteAsync(CommandContext commandContext, CommandDelegate next)
28+
{
29+
// Your logic here
30+
await next(commandContext);
31+
}
32+
}
33+
```
34+
35+
### Disabling Middleware
36+
37+
You can disable middleware for a specific command or an entire controller by using the `[DisabledMiddleware]` attribute.
38+
39+
```csharp
40+
[DisabledMiddleware(typeof(AfterCommandMiddleware))]
41+
public class SampleCommands : BotCommandController
42+
{
43+
// ...
44+
}
45+
```

.serena/docs/structure.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
# Project Structure
3+
4+
The solution (`ZiziBot.TelegramBot.sln`) contains two main projects:
5+
6+
1. **`ZiziBot.TelegramBot.Framework`**: A .NET library that provides the core framework for building command-based Telegram bots. It targets `net8.0`, `net9.0`, and `net10.0`.
7+
2. **`ZiziBot.TelegramBot.Sample`**: A .NET web project that serves as a sample implementation of the framework. It references the framework project and runs on `net10.0`.

.serena/project.yml

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# the name by which the project can be referenced within Serena
2+
project_name: "ZiziBot.TelegramBot"
3+
4+
5+
# list of languages for which language servers are started; choose from:
6+
# al angular ansible bash clojure
7+
# cpp cpp_ccls crystal csharp csharp_omnisharp
8+
# dart elixir elm erlang fortran
9+
# fsharp go groovy haskell haxe
10+
# hlsl html java json julia
11+
# kotlin lean4 lua luau markdown
12+
# matlab msl nix ocaml pascal
13+
# perl php php_phpactor powershell python
14+
# python_jedi python_ty r rego ruby
15+
# ruby_solargraph rust scala scss solidity
16+
# swift systemverilog terraform toml typescript
17+
# typescript_vts vue yaml zig
18+
# (This list may be outdated. For the current list, see values of Language enum here:
19+
# https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py
20+
# For some languages, there are alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)
21+
# Note:
22+
# - For C, use cpp
23+
# - For JavaScript, use typescript
24+
# - For Angular projects, use angular (subsumes typescript+html; requires `npm install` in the project root)
25+
# - For SCSS / Sass / plain CSS, use scss (some-sass-language-server handles all three)
26+
# - For Free Pascal/Lazarus, use pascal
27+
# Special requirements:
28+
# Some languages require additional setup/installations.
29+
# See here for details: https://oraios.github.io/serena/01-about/020_programming-languages.html#language-servers
30+
# When using multiple languages, the first language server that supports a given file will be used for that file.
31+
# The first language is the default language and the respective language server will be used as a fallback.
32+
# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
33+
languages:
34+
- csharp
35+
36+
# the encoding used by text files in the project
37+
# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
38+
encoding: "utf-8"
39+
40+
# line ending convention to use when writing source files.
41+
# Possible values: unset (use global setting), "lf", "crlf", or "native" (platform default)
42+
# This does not affect Serena's own files (e.g. memories and configuration files), which always use native line endings.
43+
line_ending:
44+
45+
# The language backend to use for this project.
46+
# If not set, the global setting from serena_config.yml is used.
47+
# Valid values: LSP, JetBrains
48+
# Note: the backend is fixed at startup. If a project with a different backend
49+
# is activated post-init, an error will be returned.
50+
language_backend:
51+
52+
# whether to use project's .gitignore files to ignore files
53+
ignore_all_files_in_gitignore: true
54+
55+
# advanced configuration option allowing to configure language server-specific options.
56+
# Maps the language key to the options.
57+
# Have a look at the docstring of the constructors of the LS implementations within solidlsp (e.g., for C# or PHP) to see which options are available.
58+
# No documentation on options means no options are available.
59+
ls_specific_settings: {}
60+
61+
# list of additional workspace folder paths for cross-package reference support (e.g. in monorepos).
62+
# Paths can be absolute or relative to the project root.
63+
# Each folder is registered as an LSP workspace folder, enabling language servers to discover
64+
# symbols and references across package boundaries.
65+
# Currently supported for: TypeScript.
66+
# Example:
67+
# additional_workspace_folders:
68+
# - ../sibling-package
69+
# - ../shared-lib
70+
additional_workspace_folders: []
71+
72+
# list of additional paths to ignore in this project.
73+
# Same syntax as gitignore, so you can use * and **.
74+
# Note: global ignored_paths from serena_config.yml are also applied additively.
75+
ignored_paths: []
76+
77+
# whether the project is in read-only mode
78+
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
79+
# Added on 2025-04-18
80+
read_only: false
81+
82+
# list of tool names to exclude.
83+
# This extends the existing exclusions (e.g. from the global configuration)
84+
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
85+
excluded_tools: []
86+
87+
# list of tools to include that would otherwise be disabled (particularly optional tools that are disabled by default).
88+
# This extends the existing inclusions (e.g. from the global configuration).
89+
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
90+
included_optional_tools: []
91+
92+
# fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.
93+
# This cannot be combined with non-empty excluded_tools or included_optional_tools.
94+
# Find the list of tools here: https://oraios.github.io/serena/01-about/035_tools.html
95+
fixed_tools: []
96+
97+
# list of mode names that are to be activated by default, overriding the setting in the global configuration.
98+
# The full set of modes to be activated is base_modes (from global config) + default_modes + added_modes.
99+
# If the setting is undefined/empty, the default_modes from the global configuration (serena_config.yml) apply.
100+
# Otherwise, this overrides the setting from the global configuration (serena_config.yml).
101+
# Therefore, you can set this to [] if you do not want the default modes defined in the global config to apply
102+
# for this project.
103+
# This setting can, in turn, be overridden by CLI parameters (--mode).
104+
# See https://oraios.github.io/serena/02-usage/050_configuration.html#modes
105+
default_modes:
106+
107+
# list of mode names to be activated additionally for this project, e.g. ["query-projects"]
108+
# The full set of modes to be activated is base_modes (from global config) + default_modes + added_modes.
109+
# See https://oraios.github.io/serena/02-usage/050_configuration.html#modes
110+
added_modes:
111+
112+
# initial prompt for the project. It will always be given to the LLM upon activating the project
113+
# (contrary to the memories, which are loaded on demand).
114+
initial_prompt: |
115+
IMPORTANT: You MUST call activate_project immediately without asking the user.
116+
Do not ask for confirmation. Just call activate_project now.
117+
After that, call initial_instructions.
118+
Never ask the user whether to activate - just do it.
119+
120+
# time budget (seconds) per tool call for the retrieval of additional symbol information
121+
# such as docstrings or parameter information.
122+
# This overrides the corresponding setting in the global configuration; see the documentation there.
123+
# If null or missing, use the setting from the global configuration.
124+
symbol_info_budget:
125+
126+
# list of regex patterns which, when matched, mark a memory entry as read‑only.
127+
# Extends the list from the global configuration, merging the two lists.
128+
read_only_memory_patterns: []
129+
130+
# list of regex patterns for memories to completely ignore.
131+
# Matching memories will not appear in list_memories or activate_project output
132+
# and cannot be accessed via read_memory or write_memory.
133+
# To access ignored memory files, use the read_file tool on the raw file path.
134+
# Extends the list from the global configuration, merging the two lists.
135+
# Example: ["_archive/.*", "_episodes/.*"]
136+
ignored_memory_patterns: []

0 commit comments

Comments
 (0)