Telegram Bot for our GitHub community 🤗
- What is telebot
- Why?
- Supported Events
- How to build
- How to contribute
- How to deploy
- License
- References
telebot is a bot that sends each one of the GitHub Webhooks we care about to our private Telegram group.
Besides that, it's an example of a Go project that uses GitHub Webhooks and the Telegram API.
This started as a go practice by @sadasant, but now it is the official Telegram bot for BerserkTech.
My study notes can be found: here.
This bot is currently listening to the following webhook events (keep in mind that some line breaks won't appear in this table):
Event Name | Output |
---|---|
commit_comment | Codertocat commented one commit with: This is a really good change! 👍 https://github.com/Codertocat/Hello-World/commit/a10867b14bb761a232cd80139fbd4c0d33264240#commitcomment-29186860 |
issue_comment | Codertocat commented one issue with: You are totally right! I'll get this fixed right away. Codertocat/Hello-World#2 (comment) |
pull_request_review_comment | Codertocat commented one pull request with: Maybe you should use more emojji on this line. Codertocat/Hello-World#1 (comment) |
pull_request_review | Codertocat submitted the pull request review: Update the README with new information Codertocat/Hello-World#1 |
pull_request | Codertocat closed the pull request: Update the README with new information Codertocat/Hello-World#1 Details: ditions: 1 Deletions: 1 |
issues | Codertocat edited the issue: Spelling error in the README file Codertocat/Hello-World#2 |
status | success : Initial commit by Codertocat |
ping | ping |
We should definitely add more and improve what we're currently doing with each one of these events (check out the open issues!).
Some of the events are filtered. In detail:
status
if they have state equal topending
.- Any other event if they have an action property assigned to
labeled
,unlabeled
,assigned
,unassigned
,review_requested
,review_request_removed
,edited
orsynchronize
Make sure you have Go installed: https://golang.org/doc/install. You can also use @stefanmaric's Simple go version manager, gluten-free 🙌
Make an issue or a pull request! :) Remember to fmt
your .go
s 😆
Execute the following command: go test ./...
We have a simple bash script called fmt-check.bash
. It runs go fmt -l .
at the root and in all the submodules of this repo. If it finds files
that don't have the proper formatting, it will exit with status code 1.
We use this script mainly for CI purposes.
Go to https://telegram.me/botfather and follow the steps :)
Make sure to store the HTTP API token in a safe place!
Make sure you have git installed. Follow the GitHub guides: https://help.github.com/en#dotcom, they're way better than anything I can come up with.
Once you have git
, you can clone this repo with:
git clone https://github.com/berserktech/telebot
or:
git clone [email protected]:berserktech/telebot.git
Install Zeit's now
by going to: https://zeit.co/download#now-cli,
or running npm install -g now
.
After you have now
, you'll need to add the following secrets:
- github-secret: Your Webhook secret (more below).
- telegram-chat-id: The ID of your Telegram chat.
telebot
doesn't listen to telegram incoming messages, so you will need to follow the steps described here: https://stackoverflow.com/questions/32423837/telegram-bot-how-to-get-a-group-chat-id - telegram-token: The HTTP API token obtained from the creation of the Telegram bot.
At the end, if you run now secret ls
, it should look like this:
now secret ls
> 4 secrets found under sadasant [345ms]
name created
github-secret 9h ago
telegram-chat-id 8h ago
telegram-token 8h ago
As long as you have this project locally, you can run now
at the
root of telebot
to deploy it in with Zeit 👍 If you run it, you
should eventually get this output:
now
> Deploying ~/code/github.com/berserktech/telebot under sadasant
> Using project telebot
> Synced 2 files (6.91KB) [1s]
> https://telebot-[something random].now.sh [v2] [3s]
┌ index.go Ready [42s]
└── λ index.go (4.68MB) [iad1]
> Success! Deployment ready [45s]
At this point, you should be able to make network requests against it,
or to see the logs: now logs https://telebot-[something random].now.sh
.
- Go to: https://github.com/settings/apps
- Click on
New GitHub App
. - Fill at least the following fields in the form:
- GitHub App name: Your app name. It can be anything.
- User authorization callback URL: This is required, but we won't be using it, so put any valid URL here.
- Webhook URL: Paste the URL generated by Zeit's Now. It should
look like:
https://telebot-[something random].now.sh
. - Webhook secret: Set the same value you created in the
github-secret
secret. - Add as many permissions as you want. Keep in mind that you should probably allow this application to have read access to: commits, issues and pull requests.
- Subscribe to all the events that you want. Keep in mind that telebot only answers to the events listed in: Supported events.
- Save.
- At this point there should be a button list at the left, with a specific option: Install App. Go there and install your freshly created application to your account or organization 🙌 You're done!
MIT, check the LICENSE file.