berserktech / telebot

Telegram bot for our community
MIT License
6 stars 1 forks source link

# 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! :+1: 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. https://github.com/Codertocat/Hello-World/issues/2#issuecomment-393304133
pull_request_review_comment Codertocat commented one pull request with: Maybe you should use more emojji on this line. https://github.com/Codertocat/Hello-World/pull/1#discussion_r191908831
pull_request_review Codertocat submitted the pull request review: Update the README with new information https://github.com/Codertocat/Hello-World/pull/1
pull_request Codertocat closed the pull request: Update the README with new information https://github.com/Codertocat/Hello-World/pull/1 Details: ditions: 1 Deletions: 1
issues Codertocat edited the issue: Spelling error in the README file https://github.com/Codertocat/Hello-World/issues/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:

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 git@github.com: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

License

MIT, check the LICENSE file.

References