Code Monkey home page Code Monkey logo

drone-telegram's Introduction

drone-telegram

logo

GoDoc Build Status Build status codecov Go Report Card Docker Pulls

Drone plugin for sending telegram notifications. For the usage information and a listing of the available options please take a look at the docs.

Feature

  • Send with Text Message. (markdown or html format)
  • Send with New Photo.
  • Send with New Document.
  • Send with New Audio.
  • Send with New Voice.
  • Send with New Location.
  • Send with New Venue.
  • Send with New Video.
  • Send with New Sticker.

Build or Download a binary

The pre-compiled binaries can be downloaded from release page. Support the following OS type.

  • Windows amd64/386
  • Linux arm/amd64/386
  • Darwin amd64/386

With Go installed

go get -u -v github.com/appleboy/drone-telegram

or build the binary with the following command:

export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on

go test -cover ./...

go build -v -a -tags netgo -o release/linux/amd64/drone-telegram .

Testing

Test the package with the following command:

make test

Usage

Execute from the working directory:

docker run --rm \
  -e PLUGIN_TOKEN=xxxxxxx \
  -e PLUGIN_TO=xxxxxxx \
  -e PLUGIN_MESSAGE=test \
  -e PLUGIN_MESSAGE_FILE=testmessage.md \  
  -e PLUGIN_PHOTO=tests/github.png \
  -e PLUGIN_DOCUMENT=tests/gophercolor.png \
  -e PLUGIN_STICKER=tests/github-logo.png \
  -e PLUGIN_AUDIO=tests/audio.mp3 \
  -e PLUGIN_VOICE=tests/voice.ogg \
  -e PLUGIN_LOCATION="24.9163213 121.1424972" \
  -e PLUGIN_VENUE="24.9163213 121.1424972 title address" \
  -e PLUGIN_VIDEO=tests/video.mp4 \
  -e PLUGIN_DEBUG=true \
  -e PLUGIN_ONLY_MATCH_EMAIL=false \
  -e PLUGIN_FORMAT=markdown \
  -e DRONE_REPO_OWNER=appleboy \
  -e DRONE_REPO_NAME=go-hello \
  -e DRONE_COMMIT_SHA=e5e82b5eb3737205c25955dcc3dcacc839b7be52 \
  -e DRONE_COMMIT_BRANCH=master \
  -e DRONE_COMMIT_LINK=https://github.com/appleboy/go-hello/compare/master... \
  -e DRONE_COMMIT_AUTHOR=appleboy \
  -e [email protected] \
  -e DRONE_BUILD_NUMBER=1 \
  -e DRONE_BUILD_STATUS=success \
  -e DRONE_BUILD_LINK=http://github.com/appleboy/go-hello \
  -e DRONE_TAG=1.0.0 \
  -e DRONE_JOB_STARTED=1477550550 \
  -e DRONE_JOB_FINISHED=1477550750 \
  -v $(pwd):$(pwd) \
  -w $(pwd) \
  appleboy/drone-telegram

Load all environments from file.

docker run --rm \
  -e PLUGIN_ENV_FILE=your_env_file_path \
  -v $(pwd):$(pwd) \
  -w $(pwd) \
  appleboy/drone-telegram

drone-telegram's People

Contributors

alber70g avatar appleboy avatar dbolotin avatar dmlambea avatar icecream78 avatar kolaente avatar koluchiy avatar rafi avatar sanasol avatar vaaski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

drone-telegram's Issues

invalid character '<' looking for beginning of value

Hey there
Thanks for this plugin! it is awsome for private projects with a not so big infrastructure to back things up :D
I wanted to build a arch package on my server with drone and send it to me via telegram, but the documents are not send, there is just the error

2018/02/23 22:19:15 invalid character '<' looking for beginning of value

my drone.yml is like this

pipeline:
  build:
    image: lerentis/build:arch
    commands:
      - "pacman -S --needed base-devel git wget yajl glibc glib2 icu libbsd libedit libutil-linux libxml2 ncurses python2 sqlite cmake ninja perl python2-requests python2-six python2-sphinx rsync swig clang --noconfirm"
      - "git clone https://aur.archlinux.org/libblocksruntime.git"
      - "chown -R nobody: libblocksruntime"
      - "chmod -R g+ws libblocksruntime"
      - "cd libblocksruntime" 
      - "sudo -u nobody makepkg"
      - "pacman -U libblocksruntime-0.4.1-1-x86_64.pkg.tar.xz --noconfirm && cd .."
      - "git clone https://aur.archlinux.org/swift-language.git"
      - "chown -R nobody: swift-language"
      - "chmod -R g+ws swift-language"
      - "cd swift-language && sudo -u nobody makepkg"
      - "ls -alh"
      - "pwd"
      - "mv swift-4.0.3-2-x86_64.pkg.tar.xz ../"
      - "mv swift-lldb-4.0.3-2-x86_64.pkg.tar.xz ../"
    cpu_quota: 0.80
    when:
      event: [ push, pull_request ]

  telegram:
    image: appleboy/drone-telegram
    token: masked
    to: masked
    document:
      - swift-4.0.3-2-x86_64.pkg.tar.xz
      - swift-lldb-4.0.3-2-x86_64.pkg.tar.xz

is there any issue with adding archives with this plugin? I have tested to just send empty files with the same name like this echo test > swift-4.0.3-2-x86_64.pkg.tar.xz which sends the file, so i think it is not the name of the file.

Any help or hint in the right direction would be greatly appreciated

Error using _ and markdown format

If you have _ symbol in your username and use default message with format markdown, got error of telegram API: Bad Request: can't parse entities in message text: Can't find end of the entity starting at byte offset

This pull request fix issue:
#40

Temporary you can use image koluchiy/drone-telegram

Message as auxiliary file

Hi @appleboy

the plugin is awesome, I really like it!

The only thing that bothers me (a little) is that I cannot configure the message in a side file.

It would be incredible if one is able to do the following:

Let's say: in .drone-telegram-message.md

{{#success build.status}}
... here goes md content
{{else}}
... here goes md content
{{/success}}

Pros:

  • file is supported by IDE by simply following its extension / file type
  • no need to encode special yaml characters such as #, : etc.
  • more readable .drone.yml

And then the config would look as

    name: telegram
    depends_on: [dockerize]
    image: appleboy/drone-telegram
    when:
      status: [success, failure]
    settings:
      token:
        from_secret: telegram_token
      to:
        from_secret: telegram_to
      format: markdown
      messageFile: .drone-telegram-message.md

What do you think?

To parameter with 'username'

Thank you so much for this plugin.
I've got one issue: Should the to parameter be the username of the user that needs to receive a notification? Or if not, where can I find my UserId?

ARM version doesn't work

This image doesn't work on OrangePI armv7 arch:
standard_init_linux.go:207: exec user process caused "exec format error"

Wildcard attachment upload

Looking for a way to upload (photos specifically) defined by wildcard, such as:

photo:
    - tests/Browser/screenshots/*.png

Are you planning on adding it? Unfortunately I am not very fit in Go.

Possible null pointer error

tgbotapi.NewBotAPI(p.Config.Token) can return error and then assigning Debug field of bot will cause NP error

drone-telegram/plugin.go

Lines 235 to 246 in 197bad6

bot, err := tgbotapi.NewBotAPI(p.Config.Token)
// enable bot debug mode
if p.Config.Debug {
bot.Debug = true
}
if err != nil {
return err
}

strip commit message

I'm using the current version (image id e526ca0ec7f0) with the default template and I get all messages in Telegram with a newline between the commit and the closing ใ€ character.

I'm not a Go guy but as far as I can understand the plugin is getting the Commit.Message string with a trailing newline. I propose to strip that string of all leading and trailing blanks (spaces, tabs, newlines) before passing it to the template rendering.

This is a sample message in Telegram:
Schermata 2019-03-19 alle 17 54 16

This is the config I am using:

- name: notify_telegram
  image: appleboy/drone-telegram
  settings:
    token: <MY_TELEGRAM_TOKEN>
    to: <MY_TELEGRAM_ID>
  when:
    status: [ success, failure ]

I'm not too sure but this could be similar or related to issue #61 - actually if it was me I'd strip all incoming strings (commit message, author name, etc...)

Function {{datetime build.started}} not working

When using the {{datetime build.started}} function, an error is displayed:
Evaluation error: Helper 'datetime' called with wrong number of arguments, needed 3 but got 1
How can I fix this?

{{build.branch}} and {{build.commit}} not working

I tried to get these Information in my Message but the only thing I got was an empty message. The other variables I use work.

I have one more question. Does something like this work?

file:
      - /drone/src/github.com/{{repo.owner}}/{{repo.name}}/commit/{{build.commit}}/README.md

support loading token from secrets

Right now, I cannot load telegram token from secrets, unlike with kubernetes plugin where I can do things like:

  deploy:
    image: quay.io/honestbee/drone-kubernetes
    deployment: abc
    container: abc
    repo: gcr.io/xyz/abc
    tag: [ "${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:8}" ]
    secrets: [ kubernetes_server, kubernetes_cert, kubernetes_token ]

doing it with this plugin

  notify:
    image: appleboy/drone-telegram
    to: xxxxx
    format: markdown
    secrets: 
      - source: telegram_token
        target: token

results in

missing telegram token or user list

Doesn't notify on failure

My .drone.yml part where this plugin is configured:

pipeline:
  telegram:
    image: appleboy/drone-telegram
    pull: true
    secrets: [telegram_token, telegram_to]
    when:
      status: [success, failure]

send pdf to telegram group

Hello,
I want to use the telegram plugin to send a pdf document to a telegram group.

I defined this configuration into my .drone.yml file

pipeline:
  telegram:
    image: appleboy/drone-telegram
    token: [ telegram_token ]
    to: [ telegram_user_id ]
    document:
      - index.pdf
    when:
      event: tag
    message: >
     {{#success build.status}}
       Build {{build.number}} succeeded for tag {{build.tag}}. Good job :)
     {{else}}
       Build {{build.number}} failed for tag {{build.tag}}. Fix me please :(
     {{/success}}

The telegram_token and telegram_user_id is defined over the drone web interface for the project.
But I get every time the error

2018/12/04 14:38:26 Not Found

I can not find out what the plugin not find. The PDF-Document, the user-group or the telegram token.

The readme should also be completed by the plugin. Finally, I'm not sure if the token is meant inclusive prefix (bot) or exclusive. In addition, the documentation only speaks of a user_id. Is it even possible to send files to a group? If so, this should be documented. If not, how can I specify multiple user_ids to send the document to?

standard_init_linux.go:211: exec user process caused "exec format error"

I'm using the last version of the image with this format on my pipeline.

- name: notify
   image: appleboy/drone-telegram:1.3.1
   settings:
     format: markdown
     message: "{{#success build.status}} โœ…  Build #{{build.number}} of `{{repo.name}}` succeeded.\n\n๐Ÿ“ Commit by {{commit.author}} on `{{commit.branch}}`:\n``` {{commit.     message}} ```\n\n๐ŸŒ {{ build.link }} {{else}} โŒ  Build #{{build.number}} of `{{repo.name}}` failed.\n\n๐Ÿ“ Commit by {{commit.author}} on `{{commit.branch}}`:\n``` {{commit.  message}} ```\n\n๐ŸŒ {{ build.link }} {{/success}}\n"
     to:
       from_secret: TELEGRAM_TO
     token:
       from_secret: TELEGRAM_TOKEN
   when:
     status:
     - success
     - changed
     - failure

But im getting this error in all my pipelines. I see there is an update two hours ago on DockerHub. Maybe it's something broken or I have to change someting.

image

{{#success ..}} {{else}} does not work

I can't make a custom message with {{#success ..}} {{else}}. Without {{else}} works well.
this is my config

pipeline:
  telegram:
    image: appleboy/drone-telegram
    token: $PLUGIN_TOKEN
    to: $PLUGIN_TO
    secrets: [ plugin_token, plugin_to ]
    message: |
      {{repo.owner}}/{{repo.name}}
      Branch: {{build.branch}}
      Commit: {{truncate build.commit 8}}
      Autor: {{build.author}}
      {{#success build.status}}
      Compila correctamente.
      {{else}}
      No compila.
      {{/success}}

this is the error message

Parse error on line 8:
Expecting OpenEndBlock, got: 'EOF'

Add clarification notes on configuration parameter usage

In relation to #47, I just wanted to contribute a few bits of documentation which might help users figure out whay are they not getting Telegram notifications. The way to determine a chat group id comes from this StackOverflow answer.

Hope this helps. Thanks.

PLUGIN_TOKEN and PLUGIN_TO parameter configuration.

  • PLUGIN_TOKEN is the token issued by @BotFather when configuring a new bot, as described in Telegram's Bot API.

  • PLUGIN_TO consist of a numerical id, which specifies the Telegram chat group where the Telegram plugin will send build notifications. To obtain the chat group id:

  • Call the telegram API using your bot's token:

    https://api.telegram.org/bot<THE_BOT_TOKEN>/getUpdates

And extract the id value from the chat object in the JSON response.

{
  "ok": true,
  "result": [{
    "update_id": 549000058,
    "message": {
      "message_id": 3,
      "from": {
        "id": 000000000,
        "is_bot": false,
        "first_name": "AHumansFirstName",
        "last_name": "AHumansLastName",
        "username": "humanUsername",
        "language_code": "en"
      },
      "chat": {
        "id": 123456789,
        "first_name": "AHumansFirstName",
        "last_name": "AHumansLastName",
        "username": "humanUsername",
        "type": "private"
      },
      "date": 1513466390,
      "text": "LOLZ"
    }
  }]
}

step in drone 1.0 gives yaml parse error

I've been trying to adjust to the 1.0 syntax, here's the snippet:

steps:
  - name: send notification to telegram
    image: appleboy/drone-telegram
    settings:
      token:
        from_secret: telegram_token
      to: 123456970
      message: >
        {{#success build.status}}
          build {{build.link}}, triggerd by {{commit.link}} from {{commit.author}} succeeded. Good job.
        {{else}}
          build {{build.link}}, triggerd by {{commit.link}} from {{commit.author}} failed. Fix me please.
        {{/success}}
    when:
      status:
        - success
        - failure

the secret is saved on the drone server in the format:
123456789:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

upon running a build i receive the following error:

Parse error on line 2:
Expecting OpenEndBlock, got: 'EOF'

I cannot identify the meaning of OpenEndBlock in this context, could anybody point me to the possible syntax error in the config?

The #success in message doesn't work?

I feel like the #success in the message doesn't work. It should be a kind of 'if-statement' but it doesn't seem to work. I've tried the example given in the docs, but I think something is wrong.

This is my config right now:

  telegram:
    image: appleboy/drone-telegram
    token: ${DRONE_BUILD_BOT_TOKEN}
    to: ddddddd
    message: |
      {{ #success build.status }}
        build {{ build.number }} succeeded. Good job.
      {{ else }}
        build {{ build.number }} failed. Fix me please.
      {{ /success }}
    when: 
      status: [ success, failure ]

The error I get:

Parse error on line 1:
Lexer error
Token: Error{"Unexpected character in expression: '#'"}

Examples not working in 0.6

As of drone 0.6 example in DOCS.md not working.
Spent some time to figure this out, works:

  telegram:
    image: appleboy/drone-telegram
    secrets: 
      - source: telegram_token
        target: plugin_token
    to: 12345679
    message: |
      Hello world

on error bot token displayed in drone logs

2018/10/18 00:43:56 Post https://api.telegram.org/bot667338145:HFHDFHDHFHD-lViTaORT3piWK5slHj59dfM/getMe: read tcp 172.19.0.2:44146->149.154.167.220:443: read: connection reset by peer

i think that bot token needs to be hidden

getting connection refused

I installed the drone plugin as mentioned. Created a bot, got a token and tried to send a message but getting:

2018/03/07 12:44:34 Post https://api.telegram.org/bot4xxxxxxxxx9:AAxxxxxxxxxxxxxxxDc1-mlxxxxxxxxxcYglhQ/getMe: dial tcp 149.154.167.220:443: getsockopt: connection refused

About secrets.

Hi, how can I specify a token and parameters from secrets.
The example below does not work.

token: "$TELEGRAM_TOKEN" 
to: "$TELEGRAM_TO" 
secrets: [telegram_to, telegram_token]

FR: Proxy for connection

Hi there!
Thanks for the project!
Would be great be able to set socks proxy for folks who get Telegram blocked.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.