| 1 | # relay-message-to-telegram |
| 2 | CLI Telegram Message Sender |
| 3 | # Usage |
| 4 | |
| 5 | ```./TelegramNotifier.exe <command> <parameters>``` |
| 6 | |
| 7 | where ```<command>``` is one of: |
| 8 | |
| 9 | send-message-to-chat |
| 10 | description: send a message to chat (optional topicId for forum groups) |
| 11 | parameters: chatId, message [, topicId] |
| 12 | example: .\TelegramNotifier.exe send-message-to-chat 840666093 "Hello" |
| 13 | create-chat |
| 14 | description: create a group with name <chatName> and invite <username> to this group |
| 15 | parameters: chatName, username |
| 16 | output: id of created chat |
| 17 | example of use: .\TelegramNotifier.exe create-chat testChat krawler |
| 18 | delete-chat: |
| 19 | description: delete chat with <chatId> |
| 20 | parameters: chatId |
| 21 | example of use: .\TelegramNotifier.exe delete-chat 840666093 |
| 22 | get-messages |
| 23 | description: get messages from chat (output: JSON). Optional topicId for forum groups. |
| 24 | parameters: chatId [, topicId] |
| 25 | example: .\TelegramNotifier.exe get-messages 840666093 |
| 26 | example with topic: .\TelegramNotifier.exe get-messages -1001234567890 42 |
| 27 | create-topic |
| 28 | description: create a forum topic in a supergroup (forum enabled; manage_topics required). |
| 29 | parameters: chatId, title |
| 30 | example: .\TelegramNotifier.exe create-topic -1001234567890 "New topic" |
| 31 | delete-user-from-chat |
| 32 | description: delete a user with <username> from chat with <chatId> |
| 33 | parameters: chatId username |
| 34 | example of use: .\TelegramNotifier.exe delete-user-from-chat 979115881 krawler |
| 35 | invite-user |
| 36 | description: invites a user with <username> to chat with <chatId> |
| 37 | parameters: chatId username |
| 38 | example of use: .\TelegramNotifier.exe invite-user 979115881 answeroom |
| 39 | send-message-to-user |
| 40 | description: send a <message> to user with <username> |
| 41 | parameters: username, message |
| 42 | example of use: \TelegramNotifier.exe send-message-to-user krawler "This is programmatically sended message" |
| 43 | |
| 44 | if user privacy settings ban invites or messages you'll be noticed on console |
| 45 | |
| 46 | username provided without @ character |
| 47 | |
| 48 | first launch of app request user login, next - uses .session file |
| 49 | if u want to use another user you should remove *.session |
| 50 | |
| 51 | **Topics (forum groups):** For supergroups with topics, use optional `topicId` (the topic's top message id) in `get-messages` and `send-message-to-chat`. `get-messages` outputs a JSON array (Id, Date, FromUserId, Text, ReplyToMsgId, TopicId) for MCP/scripting. |
| 52 | |
| 53 | **Tab completion (PowerShell):** In the folder with `TelegramNotifier.exe`, run once per session: `. .\TelegramNotifier-completion.ps1` (script is in repo `TelegramNotifier\TelegramNotifier-completion.ps1`). Then `.\TelegramNotifier.exe <TAB>` will list commands. To enable permanently, add that line to your PowerShell profile (`$PROFILE`). |
| 54 | |
| 55 | ## Config |
| 56 | |
| 57 | Конфиг: **appsettings.toml** (скопируй `appsettings.toml.example` → `appsettings.toml` и заполни API_ID, API_HASH, AccountPhone) или по‑старому **appsettings.json**. Оба файла в `.gitignore`. |
| 58 | |
| 59 | ## MCP server (TelegramRelay.Mcp) |
| 60 | |
| 61 | Model Context Protocol server that exposes CLI as tools for AI agents: |
| 62 | |
| 63 | - **telegram_get_messages** — `chat_id` (required), `topic_id` (optional). Returns JSON array of messages. |
| 64 | - **telegram_send_message** — `chat_id`, `message` (required), `topic_id` (optional). |
| 65 | |
| 66 | Build: from repo root run `dotnet build TelegramNotifier\TelegramNotifier.sln`. Publish MCP: `dotnet publish TelegramRelay.Mcp\TelegramRelay.Mcp.csproj -c Release`. The server expects **TelegramNotifier.exe** either next to the MCP executable or its path in **TELEGRAM_RELAY_EXE**. When publishing, copy `TelegramNotifier.exe` (and its config/session) next to `TelegramRelay.Mcp.exe`, or set `TELEGRAM_RELAY_EXE` in the environment. |
| 67 | |