mirror of
https://github.com/appleboy/telegram-action.git
synced 2026-12-02 15:45:30 +09:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
68ac04bda0 | ||
|
|
d8eb9b4997 | ||
|
|
390cf73457 | ||
|
|
a2d0caf64a | ||
|
|
978281de94 | ||
|
|
dd9f2d9fa7 | ||
|
|
4023d256c8 | ||
|
|
214f06cfa3 | ||
|
|
2608c6db39 | ||
|
|
c078210187 | ||
|
|
7f612b977e | ||
|
|
c18c95644a | ||
|
|
6753faf1d2 | ||
|
|
53d62f6c74 | ||
|
|
e9e9d8fda7 | ||
|
|
16657635b3 | ||
|
|
fd541f19b0 | ||
|
|
f8121d9e5a | ||
|
|
b8da483c2e | ||
|
|
724a55ccf8 | ||
|
|
8223320a4c | ||
|
|
ea12760348 | ||
|
|
d678193671 | ||
|
|
d600df785a | ||
|
|
78e5f2ccac | ||
|
|
78c9ef35ff | ||
|
|
4cd2253b24 | ||
|
|
37056891d4 | ||
|
|
847a2d3240 | ||
|
|
1b2bf60368 | ||
|
|
95f03551fd | ||
|
|
85afa0fd9a | ||
|
|
84183da9cf | ||
|
|
5010c012e9 | ||
|
|
94584eda62 | ||
|
|
221e6b6849 | ||
|
|
9177cafddc | ||
|
|
65a1d3c2f9 | ||
|
|
a77dd3e42f | ||
|
|
2e9996f96e | ||
|
|
2efd23283a | ||
|
|
a5d86cddbc | ||
|
|
f384cb685b | ||
|
|
ed144893ba | ||
|
|
beaf02496b | ||
|
|
6ecbcc43b0 | ||
|
|
dc870f34e9 | ||
|
|
6cdf58fd81 | ||
|
|
1ecd8d50e4 | ||
|
|
9e5e0be372 | ||
|
|
0e7bbc5ef7 | ||
|
|
3295af7b78 | ||
|
|
12a87fd2ec | ||
|
|
ec18563cbb | ||
|
|
d23549b68a | ||
|
|
18c4142dfa | ||
|
|
c05923bdec | ||
|
|
50dd6d184f | ||
|
|
68616a84f7 | ||
|
|
f501e27814 | ||
|
|
867844f8a4 | ||
|
|
abd0142ad9 | ||
|
|
363157132e | ||
|
|
d0bf9f621b | ||
|
|
1ac4b1171b | ||
|
|
845086369b | ||
|
|
268d7f7856 | ||
|
|
7ba2054f08 | ||
|
|
d04c916137 | ||
|
|
df78a5d925 | ||
|
|
94223af513 | ||
|
|
deae8157b2 | ||
|
|
74d1289afd | ||
|
|
65a4c9fc42 | ||
|
|
ee6f548104 | ||
|
|
62444e6582 | ||
|
|
406cbeb82a | ||
|
|
a5e94a4245 | ||
|
|
40cbdc99a4 | ||
|
|
ac4245365c | ||
|
|
06cc7371ce | ||
|
|
b535a89bc8 | ||
|
|
696643cdf6 | ||
|
|
bd65e6f3ea |
No files matched your search
@@ -0,0 +1,15 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
commit-message:
|
||||||
|
prefix: "chore(ci)"
|
||||||
|
|
||||||
|
- package-ecosystem: "docker"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
commit-message:
|
||||||
|
prefix: "chore(docker)"
|
||||||
+128
-36
@@ -1,59 +1,151 @@
|
|||||||
name: telegram message
|
name: telegram message
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- "**"
|
||||||
jobs:
|
jobs:
|
||||||
|
# Tests the working-tree Dockerfile and entrypoint.sh; the build job below
|
||||||
|
# runs against the published image referenced by action.yml instead.
|
||||||
|
local-image:
|
||||||
|
name: Test local image build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
|
||||||
|
- name: build image from working tree
|
||||||
|
run: docker build -t telegram-action:local .
|
||||||
|
|
||||||
|
- name: send message via local image
|
||||||
|
env:
|
||||||
|
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
run: |
|
||||||
|
docker run --rm \
|
||||||
|
-e INPUT_TO="$TELEGRAM_TO" \
|
||||||
|
-e INPUT_TOKEN="$TELEGRAM_TOKEN" \
|
||||||
|
-e INPUT_MESSAGE_THREAD_ID= \
|
||||||
|
-e INPUT_MESSAGE="ci: local image smoke test for ${{ github.sha }}" \
|
||||||
|
telegram-action:local
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- uses: actions/checkout@v7
|
||||||
- name: send custom message with args
|
- name: send message using with
|
||||||
uses: appleboy/telegram-action@master
|
uses: ./
|
||||||
env:
|
|
||||||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
|
||||||
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
|
|
||||||
with:
|
with:
|
||||||
args: The ${{ github.event_name }} event triggered first step.
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
- name: send message useing with
|
message: |
|
||||||
uses: appleboy/telegram-action@master
|
The ${{ github.event_name }} event triggered second step.
|
||||||
env:
|
show the github variable ref: ${{ github.ref }}
|
||||||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
show the github variable commit: ${{ github.sha }}
|
||||||
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
|
show the github variable ref: {{ commit.ref }}
|
||||||
with:
|
show the github variable commit: {{ commit.sha }}
|
||||||
message: The ${{ github.event_name }} event triggered second step.
|
Commit Message: ${{ github.event.head_commit.message }}
|
||||||
|
|
||||||
- name: send default message
|
- name: send default message
|
||||||
uses: appleboy/telegram-action@master
|
uses: ./
|
||||||
env:
|
with:
|
||||||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
|
||||||
- name: send photo message
|
- name: send photo message
|
||||||
uses: appleboy/telegram-action@master
|
uses: ./
|
||||||
with:
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
message: send photo message
|
message: send photo message
|
||||||
photo: './tests/github.png'
|
photo: "./tests/github.png"
|
||||||
document: './tests/gophercolor.png'
|
document: "./tests/gophercolor.png"
|
||||||
env:
|
|
||||||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
|
||||||
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
|
|
||||||
|
|
||||||
- name: send location message
|
- name: send location message
|
||||||
uses: appleboy/telegram-action@master
|
uses: ./
|
||||||
with:
|
with:
|
||||||
location: '24.9163213 121.1424972'
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
venue: '35.661777 139.704051 竹北體育館 新竹縣竹北市'
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
env:
|
location: "24.9163213 121.1424972"
|
||||||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
venue: "35.661777 139.704051 竹北體育館 新竹縣竹北市"
|
||||||
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
|
|
||||||
|
|
||||||
- name: send custom message
|
- name: send custom message
|
||||||
uses: appleboy/telegram-action@master
|
uses: ./
|
||||||
env:
|
|
||||||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
|
||||||
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
|
|
||||||
with:
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
message: |
|
message: |
|
||||||
The ${{ github.event_name }} event triggered final step.
|
The ${{ github.event_name }} event triggered final step.
|
||||||
echo This event is a pull request that had an assignee removed.
|
echo This event is a pull request that had an assignee removed.
|
||||||
|
|
||||||
|
- name: send message file
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message_file: tests/message.txt
|
||||||
|
|
||||||
|
# Regression test for issue #68: step outputs written to $GITHUB_OUTPUT
|
||||||
|
# must be usable inside the message input. The step producing the
|
||||||
|
# output needs an `id` so it can be referenced via steps.<id>.outputs.
|
||||||
|
- name: set step output
|
||||||
|
id: repo-discussion
|
||||||
|
run: |
|
||||||
|
COUNT=42
|
||||||
|
echo "discussionCount=$COUNT" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: verify step output is interpolated
|
||||||
|
run: |
|
||||||
|
test "${{ steps.repo-discussion.outputs.discussionCount }}" = "42"
|
||||||
|
|
||||||
|
- name: send message with step output (issue #68)
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: |
|
||||||
|
There are currently ${{ steps.repo-discussion.outputs.discussionCount }} discussions, come on!
|
||||||
|
format: markdown
|
||||||
|
|
||||||
|
# - name: send message using socks5 proxy URL
|
||||||
|
# uses: appleboy/telegram-action@master
|
||||||
|
# with:
|
||||||
|
# to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
# token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
# socks5: "http://222.124.154.19:23500"
|
||||||
|
# message: Send message from socks5 proxy URL.
|
||||||
|
|
||||||
|
# - name: try multiple message
|
||||||
|
# uses: appleboy/telegram-action@master
|
||||||
|
# with:
|
||||||
|
# to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
# token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
# format: html
|
||||||
|
# message: |
|
||||||
|
# ⚡️ <a href="https://github.com/aszenz/repo/commit/${{ github.event.push.after }}">Commits</a> pushed to master by <em>${{ github.event.push.pusher.name }}</em> ⚡️
|
||||||
|
# ${{ github.actor }}:${{ github.event.head_commit.message }}
|
||||||
|
|
||||||
|
- name: link preview
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: |
|
||||||
|
show link preview https://google.com.tw
|
||||||
|
|
||||||
|
- name: disable link preview
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
disable_web_page_preview: true
|
||||||
|
message: |
|
||||||
|
disable link preview https://google.com.tw
|
||||||
|
|
||||||
|
- name: sending a message without notification
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
disable_notification: true
|
||||||
|
message: |
|
||||||
|
disable link preview https://google.com.tw
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
name: Docker Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
tags:
|
||||||
|
# full semver only; the floating major tag (v1) must not trigger builds
|
||||||
|
- "v[0-9]*.[0-9]*.[0-9]*"
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v4
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v4
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Docker meta
|
||||||
|
id: docker-meta
|
||||||
|
uses: docker/metadata-action@v6
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
ghcr.io/${{ github.repository }}
|
||||||
|
tags: |
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=semver,pattern={{major}}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v7
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ steps.docker-meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.docker-meta.outputs.labels }}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
name: Goreleaser
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
# full semver only; the floating major tag (v1) must not cut a release
|
||||||
|
- "v[0-9]*.[0-9]*.[0-9]*"
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
goreleaser:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v7
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Run GoReleaser
|
||||||
|
uses: goreleaser/goreleaser-action@v7
|
||||||
|
with:
|
||||||
|
# either 'goreleaser' (default) or 'goreleaser-pro'
|
||||||
|
distribution: goreleaser
|
||||||
|
version: latest
|
||||||
|
args: release --clean
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
name: Trivy Security Scan
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
# Run at 00:00 on day 1 of every 3rd month (January, April, July, October)
|
||||||
|
- cron: "0 0 1 */3 *"
|
||||||
|
workflow_dispatch: # Allow manual trigger
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
security-events: write # For uploading results to GitHub Security tab
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
trivy-scan:
|
||||||
|
name: Trivy Security Scan
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
|
- name: Run Trivy vulnerability scanner in repo mode
|
||||||
|
uses: aquasecurity/trivy-action@v0.36.0
|
||||||
|
with:
|
||||||
|
scan-type: "fs"
|
||||||
|
scan-ref: "."
|
||||||
|
format: "sarif"
|
||||||
|
output: "trivy-results.sarif"
|
||||||
|
severity: "CRITICAL,HIGH"
|
||||||
|
|
||||||
|
- name: Upload Trivy results to GitHub Security tab
|
||||||
|
uses: github/codeql-action/upload-sarif@v4
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
sarif_file: "trivy-results.sarif"
|
||||||
|
|
||||||
|
- name: Run Trivy vulnerability scanner (table output)
|
||||||
|
uses: aquasecurity/trivy-action@v0.36.0
|
||||||
|
with:
|
||||||
|
scan-type: "fs"
|
||||||
|
scan-ref: "."
|
||||||
|
format: "table"
|
||||||
|
severity: "CRITICAL,HIGH"
|
||||||
|
exit-code: "1"
|
||||||
|
|
||||||
|
trivy-docker:
|
||||||
|
name: Trivy Docker Image Scan
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
|
- name: Build Docker image
|
||||||
|
run: docker build -t telegram-action:latest .
|
||||||
|
|
||||||
|
- name: Run Trivy vulnerability scanner on Docker image
|
||||||
|
uses: aquasecurity/trivy-action@v0.36.0
|
||||||
|
with:
|
||||||
|
scan-type: "image"
|
||||||
|
image-ref: "telegram-action:latest"
|
||||||
|
format: "sarif"
|
||||||
|
output: "trivy-docker-results.sarif"
|
||||||
|
severity: "CRITICAL,HIGH"
|
||||||
|
|
||||||
|
- name: Upload Trivy Docker results to GitHub Security tab
|
||||||
|
uses: github/codeql-action/upload-sarif@v4
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
sarif_file: "trivy-docker-results.sarif"
|
||||||
|
|
||||||
|
# Gated at CRITICAL only: base images may carry upstream HIGHs that can
|
||||||
|
# only be cleared by an upstream rebuild. They remain visible in the
|
||||||
|
# Security tab via the SARIF upload above.
|
||||||
|
- name: Run Trivy vulnerability scanner on Docker image (table output)
|
||||||
|
uses: aquasecurity/trivy-action@v0.36.0
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
scan-type: "image"
|
||||||
|
image-ref: "telegram-action:latest"
|
||||||
|
format: "table"
|
||||||
|
severity: "CRITICAL"
|
||||||
|
exit-code: "1"
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
.DS_Store
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
builds:
|
||||||
|
- # If true, skip the build.
|
||||||
|
# Useful for library projects.
|
||||||
|
# Default is false
|
||||||
|
skip: true
|
||||||
|
|
||||||
|
changelog:
|
||||||
|
use: github
|
||||||
|
groups:
|
||||||
|
- title: Features
|
||||||
|
regexp: "^.*feat[(\\w)]*:+.*$"
|
||||||
|
order: 0
|
||||||
|
- title: "Bug fixes"
|
||||||
|
regexp: "^.*fix[(\\w)]*:+.*$"
|
||||||
|
order: 1
|
||||||
|
- title: "Enhancements"
|
||||||
|
regexp: "^.*chore[(\\w)]*:+.*$"
|
||||||
|
order: 2
|
||||||
|
- title: "Refactor"
|
||||||
|
regexp: "^.*refactor[(\\w)]*:+.*$"
|
||||||
|
order: 3
|
||||||
|
- title: "Build process updates"
|
||||||
|
regexp: ^.*?(build|ci)(\(.+\))??!?:.+$
|
||||||
|
order: 4
|
||||||
|
- title: "Documentation updates"
|
||||||
|
regexp: ^.*?docs?(\(.+\))??!?:.+$
|
||||||
|
order: 4
|
||||||
|
- title: Others
|
||||||
+2
-3
@@ -1,7 +1,6 @@
|
|||||||
FROM appleboy/drone-telegram:1.3.1-linux-amd64
|
FROM ghcr.io/appleboy/drone-telegram:1.5.3
|
||||||
|
|
||||||
ADD entrypoint.sh /entrypoint.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
RUN chmod +x /entrypoint.sh
|
|
||||||
|
|
||||||
WORKDIR /github/workspace
|
WORKDIR /github/workspace
|
||||||
|
|
||||||
|
|||||||
@@ -1,107 +1,87 @@
|
|||||||
# 🚀 Telegram for GitHub Actions
|
# 🚀 Telegram for GitHub Actions
|
||||||
|
|
||||||
[GitHub Action](https://developer.github.com/actions/) for sending a Telegram notification message.
|
[繁體中文](./README.zh-tw.md) | [简体中文](./README.zh-cn.md)
|
||||||
|
|
||||||
|
[GitHub Action](https://github.com/features/actions) for sending Telegram notification messages.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
[](https://github.com/appleboy/facebook-action/actions)
|
[](https://github.com/appleboy/telegram-action/actions)
|
||||||
|
[](https://github.com/appleboy/telegram-action/releases)
|
||||||
|
[](./LICENSE)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Send custom message and see the custom variable as blow.
|
Send a custom message on every push:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
- name: send custom message
|
name: telegram message
|
||||||
uses: appleboy/telegram-action@master
|
on: [push]
|
||||||
env:
|
jobs:
|
||||||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
|
||||||
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: send telegram message on push
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
with:
|
with:
|
||||||
args: The ${{ github.event_name }} event triggered first step.
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: |
|
||||||
|
${{ github.actor }} created commit:
|
||||||
|
Commit message: ${{ github.event.commits[0].message }}
|
||||||
|
|
||||||
|
Repository: ${{ github.repository }}
|
||||||
|
|
||||||
|
See changes: https://github.com/${{ github.repository }}/commit/${{github.sha}}
|
||||||
```
|
```
|
||||||
|
|
||||||
Remove `args` to send the default message.
|
Remove the `message` input to send the default message, which looks like:
|
||||||
|
|
||||||
```yml
|
```text
|
||||||
- name: send default message
|
appleboy/telegram-action/telegram message triggered by appleboy (push)
|
||||||
uses: appleboy/telegram-action@master
|
|
||||||
env:
|
|
||||||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
|
||||||
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
|
|
||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Input variables
|
> `@v1` follows the latest `v1.x` release. Pin an exact version such as
|
||||||
|
> `appleboy/telegram-action@v1.1.2` if you want fully reproducible builds.
|
||||||
|
|
||||||
* photo - optional. photo message
|
## Setup
|
||||||
* document - optional. document message
|
|
||||||
* sticker - optional. sticker message
|
|
||||||
* audio - optional. audio message
|
|
||||||
* voice - optional. voice message
|
|
||||||
* location - optional. location message
|
|
||||||
* venue - optional. venue message
|
|
||||||
* video - optional. video message
|
|
||||||
* debug - optional. enable debug mode
|
|
||||||
* format - optional. `markdown` or `html`
|
|
||||||
|
|
||||||
### Example
|
### 1. Create a Telegram bot
|
||||||
|
|
||||||
send photo message:
|
Talk to [@BotFather](https://t.me/BotFather) in Telegram, send `/newbot`, and
|
||||||
|
follow the prompts. BotFather replies with the bot token — this is your
|
||||||
|
`TELEGRAM_TOKEN` secret. See the [Telegram Bot API](https://core.telegram.org/bots/api)
|
||||||
|
for details.
|
||||||
|
|
||||||
```yml
|
### 2. Get the chat ID
|
||||||
- name: send photo message
|
|
||||||
uses: appleboy/telegram-action@master
|
|
||||||
with:
|
|
||||||
message: send photo message
|
|
||||||
photo: tests/github.png
|
|
||||||
document: tests/gophercolor.png
|
|
||||||
env:
|
|
||||||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
|
||||||
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
|
|
||||||
```
|
|
||||||
|
|
||||||
send location message:
|
First send any message to your bot (for a group or channel, add the bot as a
|
||||||
|
member and post a message there), then call:
|
||||||
```yml
|
|
||||||
- name: send location message
|
|
||||||
uses: appleboy/telegram-action@master
|
|
||||||
with:
|
|
||||||
location: '24.9163213 121.1424972'
|
|
||||||
venue: '35.661777 139.704051 竹北體育館 新竹縣竹北市'
|
|
||||||
env:
|
|
||||||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
|
||||||
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
|
|
||||||
```
|
|
||||||
|
|
||||||
send custom message:
|
|
||||||
|
|
||||||
```yml
|
|
||||||
- name: send custom message
|
|
||||||
uses: appleboy/telegram-action@master
|
|
||||||
env:
|
|
||||||
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
|
|
||||||
TELEGRAM_TO: ${{ secrets.TELEGRAM_TO }}
|
|
||||||
with:
|
|
||||||
message: |
|
|
||||||
The ${{ github.event_name }} event triggered final step.
|
|
||||||
echo This event is a pull request that had an assignee removed.
|
|
||||||
```
|
|
||||||
|
|
||||||
## Secrets
|
|
||||||
|
|
||||||
Getting started with [Telegram Bot API](https://core.telegram.org/bots/api).
|
|
||||||
|
|
||||||
* `TELEGRAM_TOKEN`: Telegram authorization token.
|
|
||||||
* `TELEGRAM_TO`: Unique identifier for this chat.
|
|
||||||
|
|
||||||
How to get unique identifier from telegram api:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl https://api.telegram.org/bot<token>/getUpdates
|
curl https://api.telegram.org/bot<token>/getUpdates
|
||||||
```
|
```
|
||||||
|
|
||||||
See the result: (get chat id like `65382999`)
|
Read the chat ID from `result[].message.chat.id` — this is your `TELEGRAM_TO`
|
||||||
|
secret.
|
||||||
|
|
||||||
|
- A **private chat** ID is a positive number, e.g. `65382999`.
|
||||||
|
- A **group / supergroup / channel** ID is negative and usually starts with
|
||||||
|
`-100`, e.g. `-1001234567890`. Use the numeric ID; usernames like
|
||||||
|
`@channelname` are not supported.
|
||||||
|
- If `getUpdates` returns an empty result, send a fresh message in the chat
|
||||||
|
and call it again.
|
||||||
|
|
||||||
|
**Note**: the "Error: Chat not found" error means the chat ID is wrong or the
|
||||||
|
bot has never been added to that chat. See also this
|
||||||
|
[StackOverflow answer](https://stackoverflow.com/a/41291666).
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Example <code>getUpdates</code> response</summary>
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@@ -134,10 +114,140 @@ See the result: (get chat id like `65382999`)
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Template variable
|
</details>
|
||||||
|
|
||||||
| Github Variable | Telegram Template Variable |
|
### 3. Add the secrets to your repository
|
||||||
|-------------------|----------------------------|
|
|
||||||
|
In your repository go to **Settings → Secrets and variables → Actions** and
|
||||||
|
add `TELEGRAM_TOKEN` and `TELEGRAM_TO`.
|
||||||
|
|
||||||
|
## Input variables
|
||||||
|
|
||||||
|
| Variable | Description |
|
||||||
|
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| to | **required**. Chat ID of the target chat. Send to several chats with a comma-separated list, e.g. `65382999,-1001234567890`. |
|
||||||
|
| token | **required**. Telegram bot authorization token. |
|
||||||
|
| message | optional. Custom message. Falls back to the default message when empty. |
|
||||||
|
| message_file | optional. Overwrite the default message template with the contents of the specified file. Requires `actions/checkout`. |
|
||||||
|
| message_thread_id | optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only. |
|
||||||
|
| format | optional. `markdown` or `html`. Plain text when empty. See [message formatting](#message-formatting) below. |
|
||||||
|
| photo | optional. Photo file path(s). Comma-separated list, glob patterns supported. Requires `actions/checkout`. |
|
||||||
|
| document | optional. Document file path(s). Comma-separated list, glob patterns supported. Requires `actions/checkout`. |
|
||||||
|
| sticker | optional. Sticker file path(s). Comma-separated list, glob patterns supported. Requires `actions/checkout`. |
|
||||||
|
| audio | optional. Audio file path(s). Comma-separated list, glob patterns supported. Requires `actions/checkout`. |
|
||||||
|
| voice | optional. Voice file path(s). Comma-separated list, glob patterns supported. Requires `actions/checkout`. |
|
||||||
|
| video | optional. Video file path(s). Comma-separated list, glob patterns supported. Requires `actions/checkout`. |
|
||||||
|
| location | optional. Location as `latitude longitude`, e.g. `24.9163213 121.1424972`. |
|
||||||
|
| venue | optional. Venue as `latitude longitude title address`. |
|
||||||
|
| disable_web_page_preview | optional. Disables link previews for links in this message. Default is `false`. |
|
||||||
|
| disable_notification | optional. Sends the message silently, without a notification sound. Default is `false`. |
|
||||||
|
| socks5 | optional. Custom proxy URL (`http`, `https`, or `socks5`). |
|
||||||
|
| debug | optional. Enable debug mode. Default is `false`. |
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
Send a photo and a document (file inputs need `actions/checkout` so the files
|
||||||
|
exist in the workspace):
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
- name: send photo message
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: send photo message
|
||||||
|
photo: tests/github.png
|
||||||
|
document: tests/gophercolor.png
|
||||||
|
```
|
||||||
|
|
||||||
|
Send a message from a file:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
- name: send message file
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message_file: tests/message.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
Send the same message to several chats:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: notify several chats
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: "65382999,-1001234567890"
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: deploy finished
|
||||||
|
```
|
||||||
|
|
||||||
|
Send a location message:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: send location message
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
location: '24.9163213 121.1424972'
|
||||||
|
venue: '35.661777 139.704051 竹北體育館 新竹縣竹北市'
|
||||||
|
```
|
||||||
|
|
||||||
|
Send a message to a specific forum topic (thread):
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: send message to forum topic
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message_thread_id: 42
|
||||||
|
message: Hello from GitHub Actions!
|
||||||
|
```
|
||||||
|
|
||||||
|
Send message using a custom proxy (supports `http`, `https`, and `socks5`),
|
||||||
|
like `socks5://127.0.0.1:1080` or `http://222.124.154.19:23500`:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: send message using socks5 proxy URL
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
socks5: "http://222.124.154.19:23500"
|
||||||
|
message: Send message from socks5 proxy URL.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Message formatting
|
||||||
|
|
||||||
|
With `format: markdown` the message is sent using Telegram's legacy
|
||||||
|
[Markdown style](https://core.telegram.org/bots/api#markdown-style).
|
||||||
|
Underscores are escaped automatically, but unbalanced `*`, `` ` ``, or `[`
|
||||||
|
characters (for example in a commit message) make the Telegram API reject the
|
||||||
|
whole message with a "can't parse entities" error. For messages with
|
||||||
|
unpredictable content, prefer `format: html` or plain text (no `format`).
|
||||||
|
|
||||||
|
## Template variables
|
||||||
|
|
||||||
|
The `message` and `message_file` inputs are rendered as templates: `{{ ... }}`
|
||||||
|
placeholders are replaced with values taken from the environment.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: send message with template variables
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: |
|
||||||
|
Commit {{ commit.sha }} on {{ commit.ref }}
|
||||||
|
triggered by {{ repo.namespace }}
|
||||||
|
```
|
||||||
|
|
||||||
|
| GitHub Variable | Telegram Template Variable |
|
||||||
|
| ----------------- | -------------------------- |
|
||||||
| GITHUB_REPOSITORY | repo |
|
| GITHUB_REPOSITORY | repo |
|
||||||
| GITHUB_ACTOR | repo.namespace |
|
| GITHUB_ACTOR | repo.namespace |
|
||||||
| GITHUB_SHA | commit.sha |
|
| GITHUB_SHA | commit.sha |
|
||||||
|
|||||||
+253
@@ -0,0 +1,253 @@
|
|||||||
|
# 🚀 GitHub Actions 的 Telegram
|
||||||
|
|
||||||
|
[English](./README.md) | [繁體中文](./README.zh-tw.md)
|
||||||
|
|
||||||
|
[GitHub Action](https://github.com/features/actions) 用于发送 Telegram 通知消息。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
[](https://github.com/appleboy/telegram-action/actions)
|
||||||
|
[](https://github.com/appleboy/telegram-action/releases)
|
||||||
|
[](./LICENSE)
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
在每次 push 时发送自定义消息:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
name: telegram message
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: send telegram message on push
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: |
|
||||||
|
${{ github.actor }} created commit:
|
||||||
|
Commit message: ${{ github.event.commits[0].message }}
|
||||||
|
|
||||||
|
Repository: ${{ github.repository }}
|
||||||
|
|
||||||
|
See changes: https://github.com/${{ github.repository }}/commit/${{github.sha}}
|
||||||
|
```
|
||||||
|
|
||||||
|
移除 `message` 参数则发送默认消息,格式如下:
|
||||||
|
|
||||||
|
```text
|
||||||
|
appleboy/telegram-action/telegram message triggered by appleboy (push)
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
> `@v1` 会跟踪 `v1.x` 的最新版本。如需完全可复现的构建,请锁定确切版本,
|
||||||
|
> 例如 `appleboy/telegram-action@v1.1.2`。
|
||||||
|
|
||||||
|
## 设置步骤
|
||||||
|
|
||||||
|
### 1. 创建 Telegram bot
|
||||||
|
|
||||||
|
在 Telegram 中与 [@BotFather](https://t.me/BotFather) 对话,输入 `/newbot`
|
||||||
|
并按提示操作。BotFather 会回复 bot token — 这就是 `TELEGRAM_TOKEN` secret。
|
||||||
|
详见 [Telegram Bot API](https://core.telegram.org/bots/api)。
|
||||||
|
|
||||||
|
### 2. 获取 chat ID
|
||||||
|
|
||||||
|
先给你的 bot 发送任意消息(群组或频道则需把 bot 添加为成员并在其中发一条
|
||||||
|
消息),然后调用:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl https://api.telegram.org/bot<token>/getUpdates
|
||||||
|
```
|
||||||
|
|
||||||
|
从 `result[].message.chat.id` 读取 chat ID — 这就是 `TELEGRAM_TO` secret。
|
||||||
|
|
||||||
|
- **私聊**的 ID 是正数,例如 `65382999`。
|
||||||
|
- **群组 / 超级群组 / 频道**的 ID 是负数,通常以 `-100` 开头,例如
|
||||||
|
`-1001234567890`。请使用数字 ID,不支持 `@channelname` 这类用户名。
|
||||||
|
- 如果 `getUpdates` 返回空结果,请在聊天中重新发一条消息后再调用一次。
|
||||||
|
|
||||||
|
**注意**:出现 "Error: Chat not found" 错误说明 chat ID 有误,或 bot 从未被
|
||||||
|
添加到该聊天。也可参考这个 [StackOverflow 回答](https://stackoverflow.com/a/41291666)。
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><code>getUpdates</code> 响应示例</summary>
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"ok": true,
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"update_id": 664568113,
|
||||||
|
"message": {
|
||||||
|
"message_id": 8423,
|
||||||
|
"from": {
|
||||||
|
"id": 65382999,
|
||||||
|
"is_bot": false,
|
||||||
|
"first_name": "Bo-Yi",
|
||||||
|
"last_name": "Wu (appleboy)",
|
||||||
|
"username": "appleboy46",
|
||||||
|
"language_code": "en"
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"id": 65382999,
|
||||||
|
"first_name": "Bo-Yi",
|
||||||
|
"last_name": "Wu (appleboy)",
|
||||||
|
"username": "appleboy46",
|
||||||
|
"type": "private"
|
||||||
|
},
|
||||||
|
"date": 1550333434,
|
||||||
|
"text": "?"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
### 3. 将 secrets 添加到仓库
|
||||||
|
|
||||||
|
进入仓库的 **Settings → Secrets and variables → Actions**,添加
|
||||||
|
`TELEGRAM_TOKEN` 和 `TELEGRAM_TO`。
|
||||||
|
|
||||||
|
## 输入变量
|
||||||
|
|
||||||
|
| 变量 | 描述 |
|
||||||
|
| ------------------------ | ------------------------------------------------------------------------------------------------------- |
|
||||||
|
| to | **必填**。目标聊天的 chat ID。用逗号分隔可发送到多个聊天,例如 `65382999,-1001234567890` |
|
||||||
|
| token | **必填**。Telegram bot 授权 token |
|
||||||
|
| message | 可选。自定义消息,留空则发送默认消息 |
|
||||||
|
| message_file | 可选。用指定文件的内容覆盖默认消息模板,需搭配 `actions/checkout` |
|
||||||
|
| message_thread_id | 可选。论坛目标消息串(主题)的唯一标识符,仅适用于论坛超级群组 |
|
||||||
|
| format | 可选。`markdown` 或 `html`,留空为纯文本。参见下方[消息格式](#消息格式) |
|
||||||
|
| photo | 可选。图片文件路径,可逗号分隔多个并支持 glob 模式,需搭配 `actions/checkout` |
|
||||||
|
| document | 可选。文档文件路径,可逗号分隔多个并支持 glob 模式,需搭配 `actions/checkout` |
|
||||||
|
| sticker | 可选。贴纸文件路径,可逗号分隔多个并支持 glob 模式,需搭配 `actions/checkout` |
|
||||||
|
| audio | 可选。音频文件路径,可逗号分隔多个并支持 glob 模式,需搭配 `actions/checkout` |
|
||||||
|
| voice | 可选。语音文件路径,可逗号分隔多个并支持 glob 模式,需搭配 `actions/checkout` |
|
||||||
|
| video | 可选。视频文件路径,可逗号分隔多个并支持 glob 模式,需搭配 `actions/checkout` |
|
||||||
|
| location | 可选。位置,格式为 `纬度 经度`,例如 `24.9163213 121.1424972` |
|
||||||
|
| venue | 可选。地点,格式为 `纬度 经度 名称 地址` |
|
||||||
|
| disable_web_page_preview | 可选。禁用此消息中链接的预览。默认值为 `false` |
|
||||||
|
| disable_notification | 可选。静默发送消息(无通知提示音)。默认值为 `false` |
|
||||||
|
| socks5 | 可选。自定义代理 URL(`http`、`https` 或 `socks5`) |
|
||||||
|
| debug | 可选。启用调试模式。默认值为 `false` |
|
||||||
|
|
||||||
|
## 示例
|
||||||
|
|
||||||
|
发送图片和文档(文件类参数需搭配 `actions/checkout`,文件才会存在于
|
||||||
|
workspace 中):
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
- name: send photo message
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: send photo message
|
||||||
|
photo: tests/github.png
|
||||||
|
document: tests/gophercolor.png
|
||||||
|
```
|
||||||
|
|
||||||
|
从文件发送消息:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
- name: send message file
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message_file: tests/message.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
将同一消息发送到多个聊天:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: notify several chats
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: "65382999,-1001234567890"
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: deploy finished
|
||||||
|
```
|
||||||
|
|
||||||
|
发送位置消息:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: send location message
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
location: '24.9163213 121.1424972'
|
||||||
|
venue: '35.661777 139.704051 竹北體育館 新竹縣竹北市'
|
||||||
|
```
|
||||||
|
|
||||||
|
发送消息到特定论坛主题(消息串):
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: send message to forum topic
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message_thread_id: 42
|
||||||
|
message: Hello from GitHub Actions!
|
||||||
|
```
|
||||||
|
|
||||||
|
使用自定义代理发送消息(支持 `http`、`https` 和 `socks5`),如
|
||||||
|
`socks5://127.0.0.1:1080` 或 `http://222.124.154.19:23500`:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: send message using socks5 proxy URL
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
socks5: "http://222.124.154.19:23500"
|
||||||
|
message: Send message from socks5 proxy URL.
|
||||||
|
```
|
||||||
|
|
||||||
|
## 消息格式
|
||||||
|
|
||||||
|
使用 `format: markdown` 时,消息会以 Telegram 的传统
|
||||||
|
[Markdown 样式](https://core.telegram.org/bots/api#markdown-style)发送。
|
||||||
|
下划线会自动转义,但未成对的 `*`、`` ` `` 或 `[` 字符(例如出现在 commit
|
||||||
|
消息中)会让 Telegram API 以 "can't parse entities" 错误拒绝整条消息。
|
||||||
|
如果消息内容不可预期,建议改用 `format: html` 或纯文本(不设置 `format`)。
|
||||||
|
|
||||||
|
## 模板变量
|
||||||
|
|
||||||
|
`message` 和 `message_file` 参数会以模板方式渲染:`{{ ... }}` 占位符会被
|
||||||
|
替换为环境中的对应值。
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: send message with template variables
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: |
|
||||||
|
Commit {{ commit.sha }} on {{ commit.ref }}
|
||||||
|
triggered by {{ repo.namespace }}
|
||||||
|
```
|
||||||
|
|
||||||
|
| GitHub 变量 | Telegram 模板变量 |
|
||||||
|
| ----------------- | ----------------- |
|
||||||
|
| GITHUB_REPOSITORY | repo |
|
||||||
|
| GITHUB_ACTOR | repo.namespace |
|
||||||
|
| GITHUB_SHA | commit.sha |
|
||||||
|
| GITHUB_REF | commit.ref |
|
||||||
|
| GITHUB_WORKFLOW | github.workflow |
|
||||||
|
| GITHUB_ACTION | github.action |
|
||||||
|
| GITHUB_EVENT_NAME | github.event.name |
|
||||||
|
| GITHUB_EVENT_PATH | github.event.path |
|
||||||
|
| GITHUB_WORKSPACE | github.workspace |
|
||||||
+253
@@ -0,0 +1,253 @@
|
|||||||
|
# 🚀 Telegram 的 GitHub Actions
|
||||||
|
|
||||||
|
[English](./README.md) | [简体中文](./README.zh-cn.md)
|
||||||
|
|
||||||
|
透過 [GitHub Action](https://github.com/features/actions) 發送 Telegram 通知訊息。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
[](https://github.com/appleboy/telegram-action/actions)
|
||||||
|
[](https://github.com/appleboy/telegram-action/releases)
|
||||||
|
[](./LICENSE)
|
||||||
|
|
||||||
|
## 使用方式
|
||||||
|
|
||||||
|
在每次 push 時發送自訂訊息:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
name: telegram message
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: send telegram message on push
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: |
|
||||||
|
${{ github.actor }} created commit:
|
||||||
|
Commit message: ${{ github.event.commits[0].message }}
|
||||||
|
|
||||||
|
Repository: ${{ github.repository }}
|
||||||
|
|
||||||
|
See changes: https://github.com/${{ github.repository }}/commit/${{github.sha}}
|
||||||
|
```
|
||||||
|
|
||||||
|
移除 `message` 參數則發送預設訊息,格式如下:
|
||||||
|
|
||||||
|
```text
|
||||||
|
appleboy/telegram-action/telegram message triggered by appleboy (push)
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
> `@v1` 會追蹤 `v1.x` 的最新版本。如需完全可重現的建置,請鎖定確切版本,
|
||||||
|
> 例如 `appleboy/telegram-action@v1.1.2`。
|
||||||
|
|
||||||
|
## 設定步驟
|
||||||
|
|
||||||
|
### 1. 建立 Telegram bot
|
||||||
|
|
||||||
|
在 Telegram 中與 [@BotFather](https://t.me/BotFather) 對話,輸入 `/newbot`
|
||||||
|
並依提示操作。BotFather 會回覆 bot token — 這就是 `TELEGRAM_TOKEN` secret。
|
||||||
|
詳見 [Telegram Bot API](https://core.telegram.org/bots/api)。
|
||||||
|
|
||||||
|
### 2. 取得 chat ID
|
||||||
|
|
||||||
|
先傳任意訊息給你的 bot(群組或頻道則需把 bot 加入成員並在其中發一則訊息),
|
||||||
|
然後呼叫:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl https://api.telegram.org/bot<token>/getUpdates
|
||||||
|
```
|
||||||
|
|
||||||
|
從 `result[].message.chat.id` 讀取 chat ID — 這就是 `TELEGRAM_TO` secret。
|
||||||
|
|
||||||
|
- **私人對話**的 ID 是正數,例如 `65382999`。
|
||||||
|
- **群組 / 超級群組 / 頻道**的 ID 是負數,通常以 `-100` 開頭,例如
|
||||||
|
`-1001234567890`。請使用數字 ID,不支援 `@channelname` 這類使用者名稱。
|
||||||
|
- 若 `getUpdates` 回傳空結果,請在聊天中重新發一則訊息後再呼叫一次。
|
||||||
|
|
||||||
|
**注意**:出現 "Error: Chat not found" 錯誤代表 chat ID 錯誤,或 bot 從未被
|
||||||
|
加入該聊天。亦可參考此 [StackOverflow 回答](https://stackoverflow.com/a/41291666)。
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><code>getUpdates</code> 回應範例</summary>
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"ok": true,
|
||||||
|
"result": [
|
||||||
|
{
|
||||||
|
"update_id": 664568113,
|
||||||
|
"message": {
|
||||||
|
"message_id": 8423,
|
||||||
|
"from": {
|
||||||
|
"id": 65382999,
|
||||||
|
"is_bot": false,
|
||||||
|
"first_name": "Bo-Yi",
|
||||||
|
"last_name": "Wu (appleboy)",
|
||||||
|
"username": "appleboy46",
|
||||||
|
"language_code": "en"
|
||||||
|
},
|
||||||
|
"chat": {
|
||||||
|
"id": 65382999,
|
||||||
|
"first_name": "Bo-Yi",
|
||||||
|
"last_name": "Wu (appleboy)",
|
||||||
|
"username": "appleboy46",
|
||||||
|
"type": "private"
|
||||||
|
},
|
||||||
|
"date": 1550333434,
|
||||||
|
"text": "?"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
### 3. 將 secrets 加入 repository
|
||||||
|
|
||||||
|
前往 repository 的 **Settings → Secrets and variables → Actions**,新增
|
||||||
|
`TELEGRAM_TOKEN` 與 `TELEGRAM_TO`。
|
||||||
|
|
||||||
|
## 輸入變數
|
||||||
|
|
||||||
|
| 變數 | 說明 |
|
||||||
|
| ------------------------ | ------------------------------------------------------------------------------------------------------- |
|
||||||
|
| to | **必填**。目標聊天的 chat ID。以逗號分隔可發送到多個聊天,例如 `65382999,-1001234567890` |
|
||||||
|
| token | **必填**。Telegram bot 授權 token |
|
||||||
|
| message | 選填。自訂訊息,留空則發送預設訊息 |
|
||||||
|
| message_file | 選填。使用指定檔案的內容覆蓋預設訊息模板,需搭配 `actions/checkout` |
|
||||||
|
| message_thread_id | 選填。論壇目標訊息串(主題)的唯一標識符,僅適用於論壇超級群組 |
|
||||||
|
| format | 選填。`markdown` 或 `html`,留空為純文字。參見下方[訊息格式](#訊息格式) |
|
||||||
|
| photo | 選填。圖片檔案路徑,可逗號分隔多個並支援 glob 樣式,需搭配 `actions/checkout` |
|
||||||
|
| document | 選填。文件檔案路徑,可逗號分隔多個並支援 glob 樣式,需搭配 `actions/checkout` |
|
||||||
|
| sticker | 選填。貼圖檔案路徑,可逗號分隔多個並支援 glob 樣式,需搭配 `actions/checkout` |
|
||||||
|
| audio | 選填。音訊檔案路徑,可逗號分隔多個並支援 glob 樣式,需搭配 `actions/checkout` |
|
||||||
|
| voice | 選填。語音檔案路徑,可逗號分隔多個並支援 glob 樣式,需搭配 `actions/checkout` |
|
||||||
|
| video | 選填。影片檔案路徑,可逗號分隔多個並支援 glob 樣式,需搭配 `actions/checkout` |
|
||||||
|
| location | 選填。位置,格式為 `緯度 經度`,例如 `24.9163213 121.1424972` |
|
||||||
|
| venue | 選填。地點,格式為 `緯度 經度 名稱 地址` |
|
||||||
|
| disable_web_page_preview | 選填。停用此訊息中連結的預覽。預設為 `false` |
|
||||||
|
| disable_notification | 選填。靜音發送訊息(無通知音效)。預設為 `false` |
|
||||||
|
| socks5 | 選填。自訂代理 URL(`http`、`https` 或 `socks5`) |
|
||||||
|
| debug | 選填。啟用除錯模式。預設為 `false` |
|
||||||
|
|
||||||
|
## 範例
|
||||||
|
|
||||||
|
發送圖片與文件(檔案類參數需搭配 `actions/checkout`,檔案才會存在於
|
||||||
|
workspace 中):
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
- name: send photo message
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: send photo message
|
||||||
|
photo: tests/github.png
|
||||||
|
document: tests/gophercolor.png
|
||||||
|
```
|
||||||
|
|
||||||
|
從檔案發送訊息:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
- name: send message file
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message_file: tests/message.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
發送相同訊息到多個聊天:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: notify several chats
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: "65382999,-1001234567890"
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: deploy finished
|
||||||
|
```
|
||||||
|
|
||||||
|
發送位置訊息:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: send location message
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
location: '24.9163213 121.1424972'
|
||||||
|
venue: '35.661777 139.704051 竹北體育館 新竹縣竹北市'
|
||||||
|
```
|
||||||
|
|
||||||
|
發送訊息到特定論壇主題(訊息串):
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: send message to forum topic
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message_thread_id: 42
|
||||||
|
message: Hello from GitHub Actions!
|
||||||
|
```
|
||||||
|
|
||||||
|
使用自訂代理發送訊息(支援 `http`、`https` 和 `socks5`),如
|
||||||
|
`socks5://127.0.0.1:1080` 或 `http://222.124.154.19:23500`:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: send message using socks5 proxy URL
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
socks5: "http://222.124.154.19:23500"
|
||||||
|
message: Send message from socks5 proxy URL.
|
||||||
|
```
|
||||||
|
|
||||||
|
## 訊息格式
|
||||||
|
|
||||||
|
使用 `format: markdown` 時,訊息會以 Telegram 的傳統
|
||||||
|
[Markdown 樣式](https://core.telegram.org/bots/api#markdown-style)發送。
|
||||||
|
底線會自動 escape,但未成對的 `*`、`` ` `` 或 `[` 字元(例如出現在 commit
|
||||||
|
訊息中)會讓 Telegram API 以 "can't parse entities" 錯誤拒絕整則訊息。
|
||||||
|
若訊息內容無法預期,建議改用 `format: html` 或純文字(不設定 `format`)。
|
||||||
|
|
||||||
|
## 模板變數
|
||||||
|
|
||||||
|
`message` 與 `message_file` 參數會以模板方式渲染:`{{ ... }}` 佔位符會被
|
||||||
|
替換為環境中的對應值。
|
||||||
|
|
||||||
|
```yml
|
||||||
|
- name: send message with template variables
|
||||||
|
uses: appleboy/telegram-action@v1
|
||||||
|
with:
|
||||||
|
to: ${{ secrets.TELEGRAM_TO }}
|
||||||
|
token: ${{ secrets.TELEGRAM_TOKEN }}
|
||||||
|
message: |
|
||||||
|
Commit {{ commit.sha }} on {{ commit.ref }}
|
||||||
|
triggered by {{ repo.namespace }}
|
||||||
|
```
|
||||||
|
|
||||||
|
| GitHub 變數 | Telegram 模板變數 |
|
||||||
|
| ----------------- | ----------------- |
|
||||||
|
| GITHUB_REPOSITORY | repo |
|
||||||
|
| GITHUB_ACTOR | repo.namespace |
|
||||||
|
| GITHUB_SHA | commit.sha |
|
||||||
|
| GITHUB_REF | commit.ref |
|
||||||
|
| GITHUB_WORKFLOW | github.workflow |
|
||||||
|
| GITHUB_ACTION | github.action |
|
||||||
|
| GITHUB_EVENT_NAME | github.event.name |
|
||||||
|
| GITHUB_EVENT_PATH | github.event.path |
|
||||||
|
| GITHUB_WORKSPACE | github.workspace |
|
||||||
+19
-1
@@ -2,6 +2,18 @@ name: 'Telegram Message Notify'
|
|||||||
description: 'Sending a Telegram message'
|
description: 'Sending a Telegram message'
|
||||||
author: 'Bo-Yi Wu'
|
author: 'Bo-Yi Wu'
|
||||||
inputs:
|
inputs:
|
||||||
|
to:
|
||||||
|
description: 'telegram user'
|
||||||
|
required: true
|
||||||
|
token:
|
||||||
|
description: 'telegram token'
|
||||||
|
required: true
|
||||||
|
message:
|
||||||
|
description: 'telegram message'
|
||||||
|
message_file:
|
||||||
|
description: 'overwrite the default message template with the contents of the specified file'
|
||||||
|
socks5:
|
||||||
|
description: 'support socks5 proxy URL'
|
||||||
photo:
|
photo:
|
||||||
description: 'send the photo message.'
|
description: 'send the photo message.'
|
||||||
document:
|
document:
|
||||||
@@ -22,9 +34,15 @@ inputs:
|
|||||||
description: 'enable debug mode.'
|
description: 'enable debug mode.'
|
||||||
format:
|
format:
|
||||||
description: 'message format: markdown or html'
|
description: 'message format: markdown or html'
|
||||||
|
disable_web_page_preview:
|
||||||
|
description: 'disables link previews for links in this message'
|
||||||
|
disable_notification:
|
||||||
|
description: 'disables notifications for this message, supports sending a message without notification,'
|
||||||
|
message_thread_id:
|
||||||
|
description: 'unique identifier for the target message thread (topic) of the forum; for forum supergroups only'
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'Dockerfile'
|
image: 'docker://ghcr.io/appleboy/telegram-action:1.1.2'
|
||||||
|
|
||||||
branding:
|
branding:
|
||||||
icon: 'message-square'
|
icon: 'message-square'
|
||||||
|
|||||||
@@ -4,6 +4,4 @@ set -eu
|
|||||||
|
|
||||||
export GITHUB="true"
|
export GITHUB="true"
|
||||||
|
|
||||||
[ -n "$*" ] && export TELEGRAM_MESSAGE="$*"
|
|
||||||
|
|
||||||
/bin/drone-telegram
|
/bin/drone-telegram
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
Sample message loaded from file.
|
||||||
|
|
||||||
|
Commit msg: {{commit.message}}
|
||||||
Reference in new issue
Block a user