创建 Bot
使用 @BotFather 创建一个新的 Bot,按照提示操作,获取 Bot 的 API Token 并妥善保存。
获取 Chat ID
注意
该 ID 对于每个账户来说是唯一的。
进入 Bot 聊天界面,发送一条消息,例如 “Hello”。
访问 Telegram API 获取更新:
https://api.telegram.org/bot<Bot-Token>/getUpdates返回结果中的
chat.id即为 Chat ID。JSON{ "ok": true, "result": [ { "update_id": 123456789, "message": { "message_id": 1, "from": { "id": 123456789, "is_bot": false, "first_name": "EwigLicht", "username": "EwigLicht", "language_code": "zh-hans" }, "chat": { "id": 123456789, "first_name": "EwigLicht", "username": "EwigLicht", "type": "private" }, "date": 123456789, "text": "Hello" } } ] }
发送消息
appleboy/telegram-action
YAML
steps:
- name: Notify
if: ${{ always() && env.TELEGRAM_BOT_TOKEN && env.TELEGRAM_CHAT_ID }}
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
format: markdown
message: |
*标题*
${{ steps.checkin.outputs.result }}
[任务详情](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})curl
BASH
curl -sS -X POST "https://api.telegram.org/bot<Bot-Token>/sendMessage" \
-H "Content-Type: application/json" \
-d '{
"chat_id": "<Chat-ID>",
"text": "Hello, World!"
}'