├── .gitignore ├── go.mod ├── go.sum ├── Dockerfile ├── action.yml ├── .github └── workflows │ └── go.yml ├── README.md ├── LICENSE └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | notify-telegram 2 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/yanzay/notify-telegram 2 | 3 | go 1.13 4 | 5 | require github.com/yanzay/tbot/v2 v2.0.2 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/yanzay/tbot/v2 v2.0.2 h1:GQ7U0HYn/b9CM2L1rWM/HRDRRsVbt4/pKZj5ucJrRxY= 2 | github.com/yanzay/tbot/v2 v2.0.2/go.mod h1:q0+8JblBq9tLAnKHdBIZsHwDvMS9TfO6mNfaAk1VrHg= 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.13 as builder 2 | 3 | WORKDIR /app 4 | 5 | COPY . /app 6 | 7 | RUN CGO_ENABLED=0 go build -v -o notify-telegram . 8 | 9 | FROM alpine:latest 10 | 11 | COPY --from=builder /app/notify-telegram /notify-telegram 12 | 13 | ENTRYPOINT ["/notify-telegram"] 14 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Notify Telegram' 2 | description: 'Get build notification to Telegram messenger' 3 | author: 'yanzay' 4 | inputs: 5 | chat: 6 | description: 'Chat to send: chat id or @channel_name' 7 | required: true 8 | token: 9 | description: 'Telegram Bot token' 10 | required: true 11 | status: 12 | description: 'Job status' 13 | required: true 14 | runs: 15 | using: 'docker' 16 | image: 'Dockerfile' 17 | branding: 18 | icon: 'send' 19 | color: 'blue' 20 | -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: [push] 3 | jobs: 4 | 5 | build: 6 | name: Build 7 | runs-on: ubuntu-latest 8 | steps: 9 | 10 | - name: Set up Go 1.13 11 | uses: actions/setup-go@v1 12 | with: 13 | go-version: 1.13 14 | id: go 15 | 16 | - name: Check out code into the Go module directory 17 | uses: actions/checkout@v1 18 | 19 | - name: Build 20 | run: go build -v . 21 | 22 | - uses: yanzay/notify-telegram@master 23 | if: always() 24 | with: 25 | chat: ${{ secrets.chat }} 26 | token: ${{ secrets.token }} 27 | status: ${{ job.status }} 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Notify Telegram 2 | 3 | Get workflow status notifications to Telegram chat or channel. 4 | 5 | ## Usage 6 | 7 | First of all, you need to create a Telegram bot by talking to [@BotFather](https://t.me/botfather) bot. See official guide here: https://core.telegram.org/bots#6-botfather 8 | 9 | If you want to get notifications to personal chat with bot, find your user id, for example by talking to [@jsondumpbot](https://t.me/jsondumpbot). 10 | 11 | Also you can use channel for notifications, in this case just get your channel name in format `@channelname`. 12 | 13 | Then add your bot token and user id (or channel name) to repository Secrets. 14 | 15 | Add following step to the end of your workflow: 16 | 17 | ```yaml 18 | - uses: yanzay/notify-telegram@v0.1.0 19 | if: always() 20 | with: 21 | chat: ${{ secrets.chat }} # user id or channel name secret 22 | token: ${{ secrets.token }} # token secret 23 | status: ${{ job.status }} # do not modify this line 24 | ``` 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2019 Alexey Grachov 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net/http" 7 | "os" 8 | "strings" 9 | 10 | "github.com/yanzay/tbot/v2" 11 | ) 12 | 13 | func main() { 14 | icons := map[string]string{ 15 | "failure": "❗", 16 | "cancelled": "❕", 17 | "success": "✅", 18 | } 19 | 20 | var ( 21 | // inputs 22 | token = os.Getenv("INPUT_TOKEN") 23 | chat = os.Getenv("INPUT_CHAT") 24 | status = os.Getenv("INPUT_STATUS") 25 | 26 | // github env 27 | workflow = os.Getenv("GITHUB_WORKFLOW") 28 | repo = os.Getenv("GITHUB_REPOSITORY") 29 | commit = os.Getenv("GITHUB_SHA") 30 | ) 31 | 32 | if token == "" { 33 | log.Fatal("token input is required") 34 | } 35 | if chat == "" { 36 | log.Fatal("chat input is required") 37 | } 38 | if status == "" { 39 | log.Fatal("status input is required") 40 | } 41 | 42 | c := tbot.NewClient(token, http.DefaultClient, "https://api.telegram.org") 43 | 44 | icon := icons[strings.ToLower(status)] 45 | link := fmt.Sprintf("https://github.com/%s/commit/%s/checks", repo, commit) 46 | msg := fmt.Sprintf(`%s*%s*: %s ([%s](%s))`, icon, status, repo, workflow, link) 47 | 48 | _, err := c.SendMessage(chat, msg, tbot.OptParseModeMarkdown) 49 | if err != nil { 50 | log.Fatalf("unable to send message: %v", err) 51 | } 52 | } 53 | --------------------------------------------------------------------------------