configure-telegram
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseConfigure Telegram Notifications
配置Telegram通知
Set up Telegram notifications so OMX can message you when sessions end, need input, or complete background tasks.
设置Telegram通知,以便在会话结束、需要输入或完成后台任务时,OMX向您发送消息。
How This Skill Works
本Skill的工作方式
This is an interactive, natural-language configuration skill. Walk the user through setup by asking questions with AskUserQuestion. Write the result to .
~/.codex/.omx-config.json这是一个交互式的自然语言配置Skill。通过AskUserQuestion提问引导用户完成设置,并将结果写入。
~/.codex/.omx-config.jsonStep 1: Detect Existing Configuration
步骤1:检测现有配置
bash
CONFIG_FILE="$HOME/.codex/.omx-config.json"
if [ -f "$CONFIG_FILE" ]; then
HAS_TELEGRAM=$(jq -r '.notifications.telegram.enabled // false' "$CONFIG_FILE" 2>/dev/null)
CHAT_ID=$(jq -r '.notifications.telegram.chatId // empty' "$CONFIG_FILE" 2>/dev/null)
PARSE_MODE=$(jq -r '.notifications.telegram.parseMode // "Markdown"' "$CONFIG_FILE" 2>/dev/null)
if [ "$HAS_TELEGRAM" = "true" ]; then
echo "EXISTING_CONFIG=true"
echo "CHAT_ID=$CHAT_ID"
echo "PARSE_MODE=$PARSE_MODE"
else
echo "EXISTING_CONFIG=false"
fi
else
echo "NO_CONFIG_FILE"
fiIf existing config is found, show the user what's currently configured and ask if they want to update or reconfigure.
bash
CONFIG_FILE="$HOME/.codex/.omx-config.json"
if [ -f "$CONFIG_FILE" ]; then
HAS_TELEGRAM=$(jq -r '.notifications.telegram.enabled // false' "$CONFIG_FILE" 2>/dev/null)
CHAT_ID=$(jq -r '.notifications.telegram.chatId // empty' "$CONFIG_FILE" 2>/dev/null)
PARSE_MODE=$(jq -r '.notifications.telegram.parseMode // "Markdown"' "$CONFIG_FILE" 2>/dev/null)
if [ "$HAS_TELEGRAM" = "true" ]; then
echo "EXISTING_CONFIG=true"
echo "CHAT_ID=$CHAT_ID"
echo "PARSE_MODE=$PARSE_MODE"
else
echo "EXISTING_CONFIG=false"
fi
else
echo "NO_CONFIG_FILE"
fi如果检测到现有配置,向用户展示当前配置内容,并询问他们是否想要更新或重新配置。
Step 2: Create a Telegram Bot
步骤2:创建Telegram机器人
Guide the user through creating a bot if they don't have one:
To set up Telegram notifications, you need a Telegram bot token and your chat ID.
CREATE A BOT (if you don't have one):
1. Open Telegram and search for @BotFather
2. Send /newbot
3. Choose a name (e.g., "My OMX Notifier")
4. Choose a username (e.g., "my_omc_bot")
5. BotFather will give you a token like: 123456789:ABCdefGHIjklMNOpqrsTUVwxyz
GET YOUR CHAT ID:
1. Start a chat with your new bot (send /start)
2. Visit: https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates
3. Look for "chat":{"id":YOUR_CHAT_ID}
- Personal chat IDs are positive numbers (e.g., 123456789)
- Group chat IDs are negative numbers (e.g., -1001234567890)如果用户尚未拥有机器人,引导他们创建:
要设置Telegram通知,您需要一个Telegram机器人令牌(bot token)和您的聊天ID(chat ID)。
创建机器人(如果您还没有):
1. 打开Telegram,搜索@BotFather
2. 发送/newbot
3. 选择一个名称(例如:"My OMX Notifier")
4. 选择一个用户名(例如:"my_omc_bot")
5. BotFather会为您提供一个类似这样的令牌:123456789:ABCdefGHIjklMNOpqrsTUVwxyz
获取您的聊天ID:
1. 与您的新机器人开始对话(发送/start)
2. 访问:https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates
3. 查找"chat":{"id":YOUR_CHAT_ID}
- 个人聊天ID为正数(例如:123456789)
- 群组聊天ID为负数(例如:-1001234567890)Step 3: Collect Bot Token
步骤3:收集机器人令牌
Use AskUserQuestion:
Question: "Paste your Telegram bot token (from @BotFather)"
The user will type their token in the "Other" field.
Validate the token:
- Must match pattern: (e.g.,
digits:alphanumeric)123456789:ABCdefGHI... - If invalid, explain the format and ask again
使用AskUserQuestion:
问题: "粘贴您的Telegram机器人令牌(来自@BotFather)"
用户将在“其他”字段中输入他们的令牌。
验证令牌:
- 必须匹配格式:(例如:
数字:字母数字组合)123456789:ABCdefGHI... - 如果无效,说明格式要求并重新询问
Step 4: Collect Chat ID
步骤4:收集聊天ID
Use AskUserQuestion:
Question: "Paste your Telegram chat ID (the number from getUpdates API)"
The user will type their chat ID in the "Other" field.
Validate the chat ID:
- Must be a number (positive for personal, negative for groups)
- If invalid, offer to help them find it:
bash
undefined使用AskUserQuestion:
问题: "粘贴您的Telegram聊天ID(来自getUpdates API的数字)"
用户将在“其他”字段中输入他们的聊天ID。
验证聊天ID:
- 必须是数字(个人聊天为正数,群组为负数)
- 如果无效,提供帮助查找的方法:
bash
undefinedHelp user find their chat ID
帮助用户查找聊天ID
BOT_TOKEN="USER_PROVIDED_TOKEN"
echo "Fetching recent messages to find your chat ID..."
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/getUpdates" | jq '.result[-1].message.chat.id // .result[-1].message.from.id // "No messages found - send /start to your bot first"'
undefinedBOT_TOKEN="USER_PROVIDED_TOKEN"
echo "Fetching recent messages to find your chat ID..."
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/getUpdates" | jq '.result[-1].message.chat.id // .result[-1].message.from.id // "No messages found - send /start to your bot first"'
undefinedStep 5: Choose Parse Mode
步骤5:选择解析模式
Use AskUserQuestion:
Question: "Which message format do you prefer?"
Options:
- Markdown (Recommended) - Bold, italic, code blocks with Markdown syntax
- HTML - Bold, italic, code with HTML tags
使用AskUserQuestion:
问题: "您偏好哪种消息格式?"
选项:
- Markdown(推荐) - 使用Markdown语法实现加粗、斜体、代码块
- HTML - 使用HTML标签实现加粗、斜体、代码
Step 6: Configure Events
步骤6:配置触发事件
Use AskUserQuestion with multiSelect:
Question: "Which events should trigger Telegram notifications?"
Options (multiSelect: true):
- Session end (Recommended) - When a Codex session finishes
- Input needed - When Codex is waiting for your response (great for long-running tasks)
- Session start - When a new session begins
- Session continuing - When a persistent mode keeps the session alive
Default selection: session-end + ask-user-question.
使用支持多选的AskUserQuestion:
问题: "哪些事件应触发Telegram通知?"
选项(支持多选):
- 会话结束(推荐) - 当Codex会话完成时
- 需要输入 - 当Codex等待您的响应时(非常适合长时间运行的任务)
- 会话开始 - 当新会话启动时
- 会话持续 - 当持久化模式保持会话活跃时
默认选择:会话结束 + 需要用户输入。
Step 7: Write Configuration
步骤7:写入配置
Read the existing config, merge the new Telegram settings, and write back:
bash
CONFIG_FILE="$HOME/.codex/.omx-config.json"
mkdir -p "$(dirname "$CONFIG_FILE")"
if [ -f "$CONFIG_FILE" ]; then
EXISTING=$(cat "$CONFIG_FILE")
else
EXISTING='{}'
fi读取现有配置,合并新的Telegram设置,然后写回文件:
bash
CONFIG_FILE="$HOME/.codex/.omx-config.json"
mkdir -p "$(dirname "$CONFIG_FILE")"
if [ -f "$CONFIG_FILE" ]; then
EXISTING=$(cat "$CONFIG_FILE")
else
EXISTING='{}'
fiBOT_TOKEN, CHAT_ID, PARSE_MODE are collected from user
BOT_TOKEN, CHAT_ID, PARSE_MODE 来自用户输入
echo "$EXISTING" | jq
--arg token "$BOT_TOKEN"
--arg chatId "$CHAT_ID"
--arg parseMode "$PARSE_MODE"
'.notifications = (.notifications // {enabled: true}) | .notifications.enabled = true | .notifications.telegram = { enabled: true, botToken: $token, chatId: $chatId, parseMode: $parseMode }' > "$CONFIG_FILE"
--arg token "$BOT_TOKEN"
--arg chatId "$CHAT_ID"
--arg parseMode "$PARSE_MODE"
'.notifications = (.notifications // {enabled: true}) | .notifications.enabled = true | .notifications.telegram = { enabled: true, botToken: $token, chatId: $chatId, parseMode: $parseMode }' > "$CONFIG_FILE"
undefinedecho "$EXISTING" | jq
--arg token "$BOT_TOKEN"
--arg chatId "$CHAT_ID"
--arg parseMode "$PARSE_MODE"
'.notifications = (.notifications // {enabled: true}) | .notifications.enabled = true | .notifications.telegram = { enabled: true, botToken: $token, chatId: $chatId, parseMode: $parseMode }' > "$CONFIG_FILE"
--arg token "$BOT_TOKEN"
--arg chatId "$CHAT_ID"
--arg parseMode "$PARSE_MODE"
'.notifications = (.notifications // {enabled: true}) | .notifications.enabled = true | .notifications.telegram = { enabled: true, botToken: $token, chatId: $chatId, parseMode: $parseMode }' > "$CONFIG_FILE"
undefinedAdd event-specific config if user didn't select all events:
如果用户未选择所有事件,添加特定事件配置:
For each event NOT selected, disable it:
bash
undefined对于每个未被选中的事件,将其禁用:
bash
undefinedExample: disable session-start if not selected
示例:如果未选择会话开始,则禁用该事件
echo "$(cat "$CONFIG_FILE")" | jq
'.notifications.events = (.notifications.events // {}) | .notifications.events["session-start"] = {enabled: false}' > "$CONFIG_FILE"
'.notifications.events = (.notifications.events // {}) | .notifications.events["session-start"] = {enabled: false}' > "$CONFIG_FILE"
undefinedecho "$(cat "$CONFIG_FILE")" | jq
'.notifications.events = (.notifications.events // {}) | .notifications.events["session-start"] = {enabled: false}' > "$CONFIG_FILE"
'.notifications.events = (.notifications.events // {}) | .notifications.events["session-start"] = {enabled: false}' > "$CONFIG_FILE"
undefinedStep 8: Test the Configuration
步骤8:测试配置
After writing config, offer to send a test notification:
Use AskUserQuestion:
Question: "Send a test notification to verify the setup?"
Options:
- Yes, test now (Recommended) - Send a test message to your Telegram chat
- No, I'll test later - Skip testing
写入配置后,提供发送测试通知的选项:
使用AskUserQuestion:
问题: "是否发送测试通知以验证设置?"
选项:
- 是,立即测试(推荐) - 向您的Telegram聊天发送测试消息
- 否,我稍后再测试 - 跳过测试
If testing:
如果选择测试:
bash
BOT_TOKEN="USER_PROVIDED_TOKEN"
CHAT_ID="USER_PROVIDED_CHAT_ID"
PARSE_MODE="Markdown"
RESPONSE=$(curl -s -w "\n%{http_code}" \
"https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-d "chat_id=${CHAT_ID}" \
-d "parse_mode=${PARSE_MODE}" \
-d "text=OMX test notification - Telegram is configured!")
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
BODY=$(echo "$RESPONSE" | head -1)
if [ "$HTTP_CODE" = "200" ]; then
echo "Test notification sent successfully!"
else
echo "Failed (HTTP $HTTP_CODE):"
echo "$BODY" | jq -r '.description // "Unknown error"' 2>/dev/null || echo "$BODY"
fiReport success or failure. Common issues:
- 401 Unauthorized: Bot token is invalid
- 400 Bad Request: chat not found: Chat ID is wrong, or user hasn't sent to the bot
/start - Network error: Check connectivity to api.telegram.org
bash
BOT_TOKEN="USER_PROVIDED_TOKEN"
CHAT_ID="USER_PROVIDED_CHAT_ID"
PARSE_MODE="Markdown"
RESPONSE=$(curl -s -w "\n%{http_code}" \
"https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-d "chat_id=${CHAT_ID}" \
-d "parse_mode=${PARSE_MODE}" \
-d "text=OMX test notification - Telegram is configured!")
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
BODY=$(echo "$RESPONSE" | head -1)
if [ "$HTTP_CODE" = "200" ]; then
echo "Test notification sent successfully!"
else
echo "Failed (HTTP $HTTP_CODE):"
echo "$BODY" | jq -r '.description // "Unknown error"' 2>/dev/null || echo "$BODY"
fi报告测试成功或失败。常见问题:
- 401 Unauthorized:机器人令牌无效
- 400 Bad Request: chat not found:聊天ID错误,或用户尚未向机器人发送/start
- 网络错误:检查与api.telegram.org的连接
Step 9: Confirm
步骤9:确认配置
Display the final configuration summary:
Telegram Notifications Configured!
Bot: @your_bot_username
Chat ID: 123456789
Format: Markdown
Events: session-end, ask-user-question
Config saved to: ~/.codex/.omx-config.json
You can also set these via environment variables:
OMX_TELEGRAM_BOT_TOKEN=123456789:ABCdefGHI...
OMX_TELEGRAM_CHAT_ID=123456789
To reconfigure: /configure-telegram
To configure Discord: /configure-discord显示最终配置摘要:
Telegram通知已配置完成!
机器人: @your_bot_username
聊天ID: 123456789
格式: Markdown
触发事件: session-end, ask-user-question
配置已保存至:~/.codex/.omx-config.json
您也可以通过环境变量进行设置:
OMX_TELEGRAM_BOT_TOKEN=123456789:ABCdefGHI...
OMX_TELEGRAM_CHAT_ID=123456789
如需重新配置:/configure-telegram
如需配置Discord:/configure-discordEnvironment Variable Alternative
环境变量替代方案
Users can skip this wizard entirely by setting env vars in their shell profile:
bash
export OMX_TELEGRAM_BOT_TOKEN="123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
export OMX_TELEGRAM_CHAT_ID="123456789"Env vars are auto-detected by the notification system without needing .
.omx-config.json用户可以完全跳过此向导,通过在shell配置文件中设置环境变量来完成配置:
bash
export OMX_TELEGRAM_BOT_TOKEN="123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
export OMX_TELEGRAM_CHAT_ID="123456789"通知系统会自动检测环境变量,无需依赖文件。
.omx-config.json