tgcli について
tgcliは、AIエージェント向けのTelegramコマンドラインスキルで、メッセージの閲覧、検索、アーカイブ、メッセージやメディアの送信に対応します。JSON出力、ローカルアーカイブ、アカウントプロファイル、同期ジョブを備え、エージェントのワークフローに使えます。
主な機能
- 01アーカイブまたはライブのメッセージを閲覧・検索
- 02テキスト、写真、ファイルを送信
- 03トピック、チャンネル、連絡先を管理
- 04メッセージのメディアをダウンロード
- 05分離された名前付きアカウントプロファイル
- 06アーカイブ同期ジョブを実行
活用シーン
- 01ローカルのTelegramメッセージアーカイブを検索
- 02書式付きメッセージやメディアファイルを送信
- 03指定したチャットを監視・同期
- 04JSON出力でTelegram操作を自動化
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ dapi/ tgcli --skill tgcliインストール後、Claude Code で/tgcliを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
.mise.tomlDockerfile.npmignoreLICENSECLAUDE.md.gitignoreLIBRARY.mdAGENTS.mdMakefileclient.jscli.jsMIGRATION.mdREADME.md.github/workflows/release.ymlci.ymlcore/config.jsarchive-queries.jsarchive-reader.jsaccounts.jsowner-coordinator.jsowner-operations.jsservice-identity.jssend-utils.jsowner-ipc.jsservices.jsrequest-context.jsshutdown.jsretry.jsstore.jsdocs/plans/2026-02-27-folders-commands.md詳細
tgcli
AI エージェント向けの Telegram CLI スキルです。
インストール
このスキルを GitHub からインストールします:
npx skills add dapi/tgcli --skill tgcli --agent '*' -g -y
CLI をインストールします:
npm install -g @dapi/tgcli
一度認証します:
tgcli auth
ツールの使い分け:tgcli と telegram-mcp
| tgcli を使用する用途 | telegram-mcp を使用する用途 |
|---|---|
| メッセージの閲覧/検索/アーカイブ | 編集/削除/転送 |
| コールバックボタンの確認/クリック | リアクション |
| テキスト/写真/ファイルやトピック投稿の送信 | 高度なインタラクティブ操作 |
| フォーラムトピックの一覧表示/検索 | |
| メッセージからメディアをダウンロード | |
| グループ管理(参加リクエスト、名前変更、メンバー、招待、参加/退出) | 詳細な権限を指定した禁止/キック/昇格 |
| チャンネル/連絡先のタグとメタデータ | |
| 同期ジョブとアーカイブの監視 | |
| 自動化用の JSON 出力 |
実行ルール
tgcliが見つからない場合は、npm install -g @dapi/tgcliでインストールし、初回ログイン時にtgcli authを実行します。tgcli authは Telegram セッションの認証のみを行います。ダイアログを初期登録/アーカイブするには、tgcli sync --onceまたはtgcli sync --followを使用します。- エージェントのワークフローでは、必ず
--jsonを追加します。 - デフォルトで
--timeout 30sを追加し、負荷の高いライブ読み取りには--timeout 90sを使用します。 - デフォルトに頼らず、明示的に
--source archive|live|bothを指定します。 --source archiveは、結果が見つからない場合も含め、ローカルアーカイブのみを読み取ります。Telegram に問い合わせるには--source liveを、両方を組み合わせるには--source bothを使用します。tgcli serverまたはtgcli sync --followの実行中は、アーカイブのメッセージ読み取り、キャッシュ済みタグ、およびsync jobs listは読み取り専用の SQLite を使用します。ライブ読み取りやストアを変更するコマンドは、MCP が無効でも所有者のプライベートなローカルソケットを使用します。所有者がいない場合、CLI はそれらのコマンドのためにストアを自ら確保します。ライブ所有者のソケットが利用できない場合は、所有者に依存するコマンドを再試行する前に修復するか停止する必要があります。CLI は2つ目のセッションを開きません。- Telegram によるレート制限でサーバー起動時のダイアログ更新が制限された場合も、サーバーは引き続き利用できますが、保留中の同期作業は一時停止します。
tgcli sync status --jsonにはdialogRefreshDeferred: trueと表示されます。同じ所有者を通じて、後からtgcli sync --onceで更新を再試行してください。FLOOD_WAIT中に何度も再試行しないでください。 - ライブコマンドが
UNKNOWN_RESULTを報告した場合、送信などの非冪等な変更をむやみに再試行しないでください。同じ所有者の実行中に、返されたrequestIdを使ってtgcli owner request <requestId> --jsonを実行します。リクエストが実行中、または結果が不明な場合は、再試行する前にチャットまたはアーカイブを確認してください。 --timeoutは所有者上のリクエストの Telegram RPC とアップロードをキャンセルし、ライブスロットを解放します。ただし、すでに Telegram に送信された変更を取り消すことはできません。その結果はコードUNKNOWN_RESULTとともにunknownのままになる場合があります。大きなファイルには、明示的に長いタイムアウトを指定してください。バックグラウンド同期ジョブは、それをキューに追加したリクエストとは独立して続行されます。--sinceは使用しないでください。tgcli では ISO タイムスタンプを指定する--afterと--beforeを使用します。tgcli sync --chat ...は使用しないでください。トップレベルのsyncは、--once/--followを通じてのみワーカーを実行します。- 特定のチャットを同期するには、
tgcli channels sync --chat <id|@username> --enableやtgcli sync jobs add --chat <id|@username>を実行し、その後tgcli sync --onceまたはtgcli sync --followを実行します。 - コマンドの形式が不確かな場合は、フラグを推測せず、まず
tgcli <command> --helpで確認してください。 - 名前付きアカウントは、コマンドの前にグローバルオプション
--account <id|alias|phone>を指定するか、TGCLI_ACCOUNTで選択します。選択の優先順位は--account→TGCLI_ACCOUNT→defaultです。 defaultプロファイルは、従来のストアと既存の認証を保持します。名前付きプロファイルが表示されないという理由だけで、auth logoutを実行したり、セッションを移動したり、セッションファイルをコピーしたりしないでください。- 名前付きプロファイルでは、設定、セッション、メッセージデータベース、ロック、ダウンロード、同期ジョブ、およびサービス状態が物理的に分離されています。そのプロファイルに属する認証、読み取り、書き込み、同期、およびサービスの各コマンドでは、必ず同じアカウントセレクターを使用してください。
- アカウントコマンドで突然プロファイルが表示されなくなったり、設定が見つからないと報告されたりした場合は、
TGCLI_STOREを確認してください。継承された一時/テスト用ストアによって、本番のプロファイルレジストリが隠れている可能性があります。認証を変更する前に、使用するベースストアを特定してください。 - グローバルなプロキシフォールバックは
~/.tgclircにproxy=<url>として設定され、すべてのアカウントプロファイルに適用されます。有効な設定の優先順位はTELEGRAM_PROXY→ 選択したプロファイルのconfig.json→~/.tgclircです。 - 送信時の書式を制御するには、次のオプションを使用します。
--parse-mode markdown|html|none(大文字と小文字を区別しません)send photoとsend fileでは、--parse-modeに--captionが必要です--reply-to <messageId>は特定のメッセージに返信します。--reply-toと--topicの両方が指定された場合は、--reply-toが優先されます--silentは通知音なしで送信します--no-forwardsはメッセージの転送/保存を防ぎます--schedule <iso>はメッセージを将来の配信に予約します(ISO 8601 形式。未来の日時で、365日以内である必要があります)--caption-aboveはキャプションをメディアの上に表示します(send photo/send fileで使用。--captionが必要です)--spoilerはタップするまでメディアをぼかします(send photo/send file)--retries <n>はsend photoの一時的なネットワーク/トランスポート障害時の再試行回数を指定します--retry-backoff <ms|constant|linear|exponential>はsend photoの再試行間隔を制御します--force-documentは写真/動画を非圧縮のドキュメントとして送信します(send fileでのみ使用)--retries <n>は指数バックオフで失敗時に再試行します(デフォルトは 0)。再試行が発生した場合、JSON 出力にはretry_logとattemptsが含まれます
- Telegram の Markdown 書式(
--parse-mode markdownの場合):- 太字:
**text** - 斜体:
__text__(アンダースコア2つ。1つの_ではありません) - 太字+斜体:
**__text__**(太字で斜体を囲みます) _text_のようにアンダースコアを1つだけ使っても斜体にはなりません。アンダースコアがそのまま表示されます*text*のようにアスタリスクを1つだけ使っても太字にはなりません。アスタリスクがそのまま表示されます- インラインの等幅テキスト:
`text` - コードブロック:バッククォート3つ
- Telegram の Markdown は標準の Markdown とは異なるため、必ずマーカーを2つ使用します
- 太字:
- ロックファイル(
LOCK、database is locked)は削除しないでください。待ってから再試行してください。 - 複数行のテキストや任意のユーザー作成テキストには、
scripts/send_text.pyを使用し、 本文を標準入力から渡してください。これはシェルを介さずにtgcliを呼び出すため、 実際の改行と句読点がそのまま保持されます。 JSON.stringify(message)を使ってシェルコマンドを組み立てたり、--messageにリテラルの\\nシーケンスを入れたりしないでください。Telegram には改行ではなく、 バックスラッシュと文字nが表示されます。- 複数行のテキストを送信した後は、メッセージを読み戻し、
textにリテラルの\\nシーケンスではなく、 実際の改行文字が含まれていることを確認してください。
主なコマンドパターン
アカウント
# Existing commands without a selector continue to use the default profile.
tgcli auth status --json --timeout 30s
# Register an isolated profile without contacting Telegram.
tgcli accounts add work --phone "+7 707 111 22 33" --alias office
tgcli accounts list --json
# Authenticate and use exactly one named profile.
tgcli --account work auth
tgcli --account office auth status --json --timeout 30s
tgcli --account +770****2233 messages search "invoice" --source live --json --timeout 30s
# Environment selection is useful for a dedicated service/process.
TGCLI_ACCOUNT=work tgcli sync --follow
アカウントセレクターは、安定したプロフィール ID、正規化された電話番号、またはエイリアスでアカウントを特定します。選択が曖昧な場合や、保存されている Telegram ユーザー ID がセッションと一致しない場合は、処理を中止してプロフィールを確認してください。別のアカウントにフォールバックしてはいけません。
アプリ内で配信されたログインコードを確認するには、同じ認証済みの対象プロフィールから Telegram 公式サービスチャット 777000 を読み取ります。コードは、たとえば Код для входа в Telegram: や Login code: のように、ローカライズされている場合があります。認証リクエストのタイムスタンプで絞り込み、コマンド引数やログにコードを含めず、stdin 経由で渡してください。
読み取り
tgcli messages list --chat <id|@username> --limit 50 --source archive --json --timeout 30s
tgcli messages list --chat <id|@username> --chat <id2> --limit 50 --source archive --json --timeout 30s
tgcli messages list --chat <id|@username> --topic <topicId> --after 2025-01-01T00:00:00Z --limit 100 --source archive --json --timeout 30s
tgcli messages show --chat <id|@username> --id <msgId> --source archive --json --timeout 30s
tgcli messages context --chat <id|@username> --id <msgId> --before 5 --after 5 --source archive --json --timeout 30s
tgcli messages list --chat <id|@username> --limit 50 --source live --json --timeout 90s
tgcli messages list --chat <id|@username> --limit 50 --source both --json --timeout 90s
tgcli messages buttons list --chat <id|@username> --id <msgId> --json --timeout 30s
tgcli messages buttons click --chat <id|@username> --id <msgId> --row 1 --column 1 --json --timeout 30s
messages buttons list は常に最新のメッセージを読み取り、1 始まりの座標と安全なボタンメタデータを返します。コールバックのペイロードバイトは出力しません。messages buttons click では、それらの正確な座標を使用してください。このクリックコマンドはコールバックボタンのみをサポートし、URL/Web App ボタンやパスワードで保護されたボタンの場合は、安全側に倒して処理を失敗させます。
ここでは --since を使わないでください。正しいフラグは --after です。
検索
tgcli messages search "Claude Code" --chat <id|@username> --source archive --json --timeout 30s
tgcli messages search --query "Claude Code" --chat <id|@username> --source archive --json --timeout 30s
tgcli messages search --regex "claude\\s+(code|agent)" --chat <id|@username> --source archive --json --timeout 30s
tgcli messages search --tag ai --chat <id|@username> --source archive --json --timeout 30s
tgcli messages search --tags "ai,dev" --chat <id|@username> --source archive --json --timeout 30s
tgcli messages search "release" --chat <id|@username> --after 2025-06-01T00:00:00Z --before 2025-06-30T00:00:00Z --source archive --json --timeout 30s
tgcli messages search "Release" --case-sensitive --chat <id|@username> --source archive --json --timeout 30s
位置引数のクエリと --query フラグのどちらも使用できます。--chat には複数の値を指定できます。パターンマッチングには --regex、チャンネルタグによる絞り込みには --tag/--tags、日付範囲の指定には --after/--before を使用します。大文字と小文字を区別しない検索を無効にするには、--case-sensitive を使用します。
テキスト/写真/ファイルの送信
⚠ send では、送信先に --to(別名 --chat)、テキスト本文に --message(別名 --text)、写真のアップロードに --photo、一般的なファイルには --file を使用します。
複数行のテキストには、区切り文字をシングルクォートで囲んだ heredoc を使う stdin ヘルパーを使用してください。
python3 ~/.agents/skills/tgcli/scripts/send_text.py --to <id|@username> <<'TGCLI_MESSAGE'
Первая строка.
1. Первый пункт.
2. Второй пункт.
TGCLI_MESSAGE
区切り文字を引用符で囲むとシェルによる展開を防げます。また、stdin を使うことで実際の改行が保持されます。tgcli send text --message "..." は、短く静的な単一行メッセージに適しています。
tgcli send text --to <id|@username> --message "Hello" --json --timeout 30s
tgcli send text --to <id|@username> --topic <topicId> --message "**Hello**" --parse-mode markdown --json --timeout 30s
tgcli send text --to <id|@username> --message "Done" --reply-to <messageId> --json --timeout 30s
tgcli send text --to <id|@username> --message "https://example.com check this" --no-preview --json --timeout 30s
tgcli send text --to <id|@username> --message "Nightly report" --silent --json --timeout 30s
tgcli send text --to <id|@username> --message "Confidential" --no-forwards --json --timeout 30s
tgcli send text --to <id|@username> --message "Good morning!" --schedule "2025-01-15T09:00:00+03:00" --json --timeout 30s
tgcli send text --to <id|@username> --message "Hello" --retries 3 --json --timeout 30s
tgcli send photo --to <id|@username> --photo /path/to/image.png --caption "Report" --json --timeout 30s
tgcli send photo --to <id|@username> --photo /path/to/image.png --caption "**Report**" --parse-mode markdown --json --timeout 30s
tgcli send photo --to <id|@username> --photo /path/to/image.png --reply-to <messageId> --json --timeout 30s
tgcli send photo --to <id|@username> --photo /path/to/image.png --caption "Breaking news" --caption-above --json --timeout 30s
tgcli send photo --to <id|@username> --photo /path/to/image.png --spoiler --json --timeout 30s
tgcli send photo --to <id|@username> --photo /path/to/image.png --retries 3 --retry-backoff exponential --json --timeout 30s
tgcli send file --to <id|@username> --file /path/to/file --caption "Report" --json --timeout 30s
tgcli send file --to <id|@username> --file /path/to/file --caption "<b>Report</b>" --parse-mode html --json --timeout 30s
tgcli send file --to <id|@username> --file /path/to/file --filename custom-name.pdf --json --timeout 30s
tgcli send file --to <id|@username> --file /path/to/file --reply-to <messageId> --json --timeout 30s
tgcli send file --to <id|@username> --file /path/to/file --caption "Breaking news" --caption-above --json --timeout 30s
tgcli send file --to <id|@username> --file /path/to/photo.jpg --spoiler --json --timeout 30s
tgcli send file --to <id|@username> --file /path/to/photo.jpg --force-document --json --timeout 30s
写真のプレビューとドキュメントのアップロード
- Telegram で写真のプレビューとして表示させる場合は、ローカルの PNG/JPG に
tgcli send photoを使用します。 - 一般的なアップロードや、ドキュメント形式の添付ファイルを明示的に送信する場合は、
tgcli send fileを使用します。 - 下書き/承認のフローでは、まず「保存済みメッセージ」に送信し、Telegram で確認してから対象のチャットに再送信します。
メディアのダウンロード
tgcli media download --chat <id|@username> --id <msgId> --json --timeout 30s
tgcli media download --chat <id|@username> --id <msgId> --output /path/to/save --json --timeout 30s
チャンネル
tgcli channels list --query "ai" --limit 20 --json --timeout 30s
tgcli channels show --chat <id|@username> --json --timeout 30s
tgcli channels sync --chat <id|@username> --enable --json --timeout 30s
tgcli channels sync --chat <id|@username> --disable --json --timeout 30s
トピック
tgcli topics list --chat <id|@username> --limit 50 --json --timeout 30s
tgcli topics search --chat <id|@username> --query "release" --limit 20 --json --timeout 30s
連絡先
tgcli contacts search "alex" --limit 20 --json --timeout 30s
tgcli contacts show --user <id> --json --timeout 30s
tgcli contacts alias set --user <id> --alias "Alex" --json --timeout 30s
tgcli contacts alias rm --user <id> --json --timeout 30s
tgcli contacts tags add --user <id> --tag coworker --tag ai --json --timeout 30s
tgcli contacts tags rm --user <id> --tag ai --json --timeout 30s
tgcli contacts notes set --user <id> --notes "Met at meetup" --json --timeout 30s
グループ
tgcli groups list --query "dev" --limit 20 --json --timeout 30s
tgcli groups info --chat <id|@username> --json --timeout 30s
tgcli groups requests list --chat <id|@username> --limit 100 --json --timeout 30s
tgcli groups requests list --chat <id|@username> --query "alex" --json --timeout 30s
tgcli groups requests list --chat <id|@username> --link <invite-url> --json --timeout 30s
tgcli groups requests approve --chat <id|@username> --user <userId> --json --timeout 30s
tgcli groups requests decline --chat <id|@username> --user <userId> --json --timeout 30s
tgcli groups rename --chat <id|@username> --name "New Name" --json --timeout 30s
tgcli groups members add --chat <id|@username> --user <userId> --user <userId2> --json --timeout 30s
tgcli groups members remove --chat <id|@username> --user <userId> --json --timeout 30s
tgcli groups invite get --chat <id|@username> --json --timeout 30s
tgcli groups invite edit --chat <id|@username> --link <invite-url> --request-needed true --json --timeout 30s
tgcli groups invite edit --chat <id|@username> --link <invite-url> --request-needed false --json --timeout 30s
tgcli groups invite revoke --chat <id|@username> --json --timeout 30s
tgcli groups join --code <invite-code> --json --timeout 30s
tgcli groups leave --chat <id|@username> --json --timeout 30s
参加リクエスト関連のコマンドには、グループ管理者権限が必要です。--query と --link を同時に指定してはいけません。最新の groups requests list の結果で返された正確な userId に対してのみ、承認または拒否を行ってください。別の管理者がすでにリクエストを処理している場合があります。groups invite edit は、指定した既存のリンクをそのまま変更し、リンクを取り消すことはありません。正確なリンクを渡し、JSON レスポンスに同じ link と要求した requestNeeded の値が含まれていることを確認してください。groups invite get --json は、読み戻し確認用に、プライマリリンクと有効な requestNeeded および isPrimary の値を返します。
タグ(チャンネル分類)
tgcli tags list --chat <id|@username> --json --timeout 30s
tgcli tags set --chat <id|@username> --tag ai --tag dev --json --timeout 30s
tgcli tags search --tag ai --limit 20 --json --timeout 30s
tgcli tags auto --limit 50 --json --timeout 90s # AI-powered: generates tags from channel metadata/content
tgcli tags auto --chat <id|@username> --source manual --json --timeout 90s
tgcli tags auto --limit 50 --no-refresh-metadata --json --timeout 90s
メタデータ(チャンネルキャッシュ)
tgcli metadata get --chat <id|@username> --json --timeout 30s
tgcli metadata refresh --chat <id|@username> --force --json --timeout 30s
tgcli metadata refresh --only-missing --limit 50 --json --timeout 90s
フォルダー
tgcli folders list --json --timeout 30s
tgcli folders show <name|id> --json --timeout 30s
tgcli folders show <name|id> --resolve --json --timeout 30s
tgcli folders create --title "Name" --emoji "🤖" --json --timeout 30s
tgcli folders edit <name|id> --title "New Name" --json --timeout 30s
tgcli folders delete <name|id> --json --timeout 30s
tgcli folders order <id1> <id2> <id3> --json --timeout 30s
tgcli folders add-chat <folder> --chat <id> --json --timeout 30s
tgcli folders remove-chat <folder> --chat <id> --json --timeout 30s
tgcli folders join --link "https://t.me/addlist/slug" --json --timeout 30s
folders show で --resolve を使用すると、ピア ID を読みやすいチャンネル名/ユーザー名に解決できます(処理が遅くなり、ピアごとに API 呼び出しが必要です)。--resolve を指定しない場合、ピアは型付き ID(例:channel:123)で表示されます。
同期ジョブ
tgcli sync status --json --timeout 30s
tgcli sync jobs list --json --timeout 30s
tgcli sync jobs list --status error --json --timeout 30s
tgcli sync jobs list --channel <id|@username> --json --timeout 30s
tgcli sync jobs add --chat <id|@username> --depth 500 --json --timeout 30s
tgcli sync jobs add --chat <id|@username> --min-date 2025-01-01T00:00:00Z --json --timeout 30s
tgcli sync jobs retry --all-errors --json --timeout 30s
tgcli sync jobs retry --job-id <id> --json --timeout 30s
tgcli sync jobs retry --channel <id|@username> --json --timeout 30s
tgcli sync jobs cancel --job-id <id> --json --timeout 30s
tgcli sync jobs cancel --channel <id|@username> --json --timeout 30s
tgcli sync --chat ... と指定してはいけません。sync jobs add --chat ... でジョブをキューに追加し、tgcli sync --once または tgcli sync --follow で処理してください。
オーナーリクエストの結果
tgcli owner request <requestId> --json --timeout 30s
アクティブなオーナーは、直近のリクエスト結果をメモリに保持します。completed はハンドラーが正常に完了したことを意味し、failed にはエラーコードが含まれます。running はまだ完了していないことを意味します。コード UNKNOWN_RESULT を伴う unknown は、キャンセルによって結果が不確定になったことを意味します。コードを伴わない unknown は、アクティブなオーナーに記録がないことを意味します(たとえば、再起動後など)。どちらの場合も、送信が行われなかったことの証明にはなりません。
サービス(バックグラウンド同期デーモン)
シャットダウン時には、受け付け済みの所有者リクエストをキャンセルし、クリーンアップが完了するまで待機します。クリーンアップが10秒経っても停止したままの場合、所有プロセスはエラーで終了し、OSがストアガードを解放します。実行中のMCPツールには30秒の期限があり、呼び出し元によるキャンセルを尊重します。
tgcli service status --json --timeout 30s
tgcli service install --json --timeout 30s
tgcli service start --json --timeout 30s
tgcli service stop --json --timeout 30s
tgcli service logs --json --timeout 30s
設定と認証
tgcli auth --json --timeout 30s
tgcli auth --qr --json --timeout 30s
tgcli auth status --json --timeout 30s
tgcli auth logout --json --timeout 30s
tgcli config list --json --timeout 30s
tgcli config get <key> --json --timeout 30s
tgcli config set <key> <value> --json --timeout 30s
tgcli config unset <key> --json --timeout 30s
# Global fallback shared by all profiles
# ~/.tgclirc: proxy=socks5://127.0.0.1:1080
# Route via SOCKS5 for only the selected profile (stored in config.json)
tgcli config set proxy socks5://127.0.0.1:1080 --json --timeout 30s
# Route via MTProxy (Telegram t.me link format also accepted)
tgcli config set proxy "https://t.me/proxy?server=HOST&port=PORT&secret=SECRET" --json --timeout 30s
# Or via env variable (overrides profile config and ~/.tgclirc):
# export TELEGRAM_PROXY="https://t.me/proxy?server=HOST&port=PORT&secret=SECRET"
# Remove the configured proxy
tgcli config unset proxy --json --timeout 30s
tgcli doctor --json --timeout 30s
tgcli doctor --connect --json --timeout 30s
アーカイブと分析のワークフロー
「チャット履歴を分析して」「今週何があった?」「ダイジェスト/ニュース」のようなタスクの場合:
- チャットを特定します:
tgcli channels list --query "<name>" --json --timeout 30s- 必要に応じて
tgcli groups list --query "<name>" --json --timeout 30s
- アーカイブフローを確認します:
tgcli channels sync --chat <id> --enabletgcli sync jobs add --chat <id> --depth 500tgcli service status --json --timeout 30s— 実行中かどうかを確認しますtgcli service install --json --timeout 30s— まだインストールされていない場合に実行しますtgcli service start --json --timeout 30s— デーモンを起動します
- まずアーカイブを読み取ります:
tgcli messages list --chat <id> --source archive --limit 500 --json --timeout 30s
- アーカイブがまだ空の場合は、ライブデータに切り替えます:
tgcli messages list --chat <id> --source live --limit 500 --json --timeout 90s
- JSONペイロードからダイジェスト/要約を作成します。
継続同期のワークフロー
「これらのチャンネルを監視して」「登録したチャンネルの同期を続けて」のようなタスクの場合:
アーキテクチャ:channels sync --enable でチャンネルを監視対象に設定 → sync jobs add でバックフィルタスクを作成 → service start で、ジョブを処理してリアルタイム更新を取得する永続デーモンを起動します。
- 各チャンネルの同期を有効にします:
tgcli channels sync --chat <id|@username> --enable --json --timeout 30s- 監視するチャンネルごとに繰り返します
- バックフィルジョブを追加します(任意。履歴を取得します):
tgcli sync jobs add --chat <id|@username> --depth 1000 --json --timeout 30s
- バックグラウンドデーモンを起動します:
tgcli service install --json --timeout 30s— 初回のみtgcli service start --json --timeout 30s
- 実行中であることを確認します:
tgcli service status --json --timeout 30stgcli sync status --json --timeout 30s— チャンネルごとの同期状況を表示します
- エラーを確認します:
tgcli sync jobs list --status error --json --timeout 30stgcli sync jobs retry --all-errors --json --timeout 30s
- チャンネルの監視を停止します:
tgcli channels sync --chat <id|@username> --disable --json --timeout 30s
systemdサービスを使わない場合の代替手段(一回実行またはフォアグラウンド):
tgcli sync --once— 同期を1回実行して終了しますtgcli sync --follow— フォアグラウンドで同期を続けます(停止するにはctrl-cを押します)tgcli sync --follow --idle-exit 5m— 5分間アイドル状態が続くと自動終了します
同期の意味
- 「自分のチャンネル/登録チャンネル」→
tgcli channels list ... - 「監視中/同期済みのチャンネル」→
tgcli sync status --json --timeout 30s
トリガー例
トリガーすべきリクエスト
- 「のメッセージを読んで」
- 「についてTelegramを検索して」
- 「このテキスト/ファイルをTelegramに送って」
- 「Telegramのメッセージからファイルをダウンロードして」
- 「今週話し合ったことを要約して」
- 「の最新情報は?」
- 「で自分宛てのメンションを表示して」
- 「トピック別にチャンネルにタグを付けて」
- 「Telegramグループにユーザーを追加して」
- 「グループの招待リンクを取得して」
- 「特定のTelegramメッセージに返信して」
- 「Telegramのメッセージにあるボタンを一覧表示して」
- 「インラインのコールバックボタンをクリックして」
- 「このチャンネルの同期を開始して」
- 「自分のTelegramチャンネルを監視して」
- 「チャンネルのメッセージを読んで」
- 「Telegramでリリースについて検索して」
- 「チャンネルにメッセージを送って」
- 「チャットの概要を教えて」
- 「メッセージからファイルをダウンロードして」
- 「画像付きの投稿を公開して」
- 「キャプション付きの写真をチャンネルに送って」
- 「カバー画像付きで投稿して」
トリガーすべきでないリクエスト
- 「Telegramのメッセージを編集/削除/転送して」
- 「メッセージに絵文字でリアクションして」
- 「詳細な権限を指定してユーザーをBAN/キック/昇格して」
これらの操作には telegram-mcp を使用してください。