Skip to content

berserktech/telebot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

telebot 🤖✨

Telegram Bot for our GitHub community 🤗

Index

What is telebot

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.

Why?

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.

Supported events

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 to pending.
  • Any other event if they have an action property assigned to labeled, unlabeled, assigned, unassigned, review_requested, review_request_removed, edited or synchronize

How to build

Install Go

Make sure you have Go installed: https://golang.org/doc/install. You can also use @stefanmaric's Simple go version manager, gluten-free 🙌

How to contribute

Make an issue or a pull request! :) Remember to fmt your .gos 😆

To run our tests

Execute the following command: go test ./...

To check wether your code is formatted

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.

How to deploy

Creating a Telegram Bot

Go to https://telegram.me/botfather and follow the steps :)

Make sure to store the HTTP API token in a safe place!

Cloning this repository

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

Install Zeit's now by going to: https://zeit.co/download#now-cli, or running npm install -g now.

Setting up the secrets

After you have now, you'll need to add the following secrets:

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

Deploy this project

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.

Make a new GitHub Webhook Application

  • 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!

License

MIT, check the LICENSE file.

References

About

Telegram bot for our community

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published