Git Product home page Git Product logo

telegram-moderator-bot's Introduction

This repo is archived as of July 10, 2020 but made available for historical record.

Telegram-Moderator-Bot

Overview

Telegram Moderator Bot written in Go as an AWS Lambda function (and a stand-alone web service).

Please refer to the User's Guide for additional information on how to use the bot.

Setup

Prerequisites

  1. Set up Go and the GOPATH veriable.
  2. Familiarize yourself with @BotFather on Telegram.
  3. Set up Terraform and AWS credentials, if you want to deploy using Terraform.
  4. Run the below to download and prepare the code:
cd $GOPATH
mkdir -p src/github.com/freshautomations
cd src/github.com/freshautomations
git clone https://github.com/freshautomations/telegram-moderator-bot
cd telegram-moderator-bot

make get_vendor_deps

Build

BUILD_NUMBER=10 make build

This creates the tmb binary in the build folder. It can be run locally, with the -webserver option or deployed as a Lambda function in AWS.

Run local webserver

Copy the tmb.conf.template file over to tmb.conf. Edit the file and fill in the details. Then run:

make localnet-start

Deploy infrastructure

The resources/terraform folder contains Terraform scripts to deploy the compiled binary to AWS and set it up with Telegram. It is a working example, however it is worth checking exactly what it does when deploying the bot to production.

To make life easier, let's export some variables that the build process and the deployment process will use:

export ENVIRONMENT=prod
export LAMBDA_SECRET=mylonglambdasecret
export TELEGRAM_TOKEN=abcdef 

Descriptions for these variables can be found in the Environment variables section.

You also need to have access to AWS Lambda, Gateway, AWF and IAM. The easiest way is to request an AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY token and export them as environment variables. You could also run the deployment from an AWS EC2 instance with proper IAM roles set up. Setting up AWS access is beyond the scope of this documentation.

Run the below to build a Linux binary, deploy it to Lambda using Terraform and deploy the associated API Gateway:

BUILD_NUMBER=11 make build-linux package deploy

Run the below command to tell Telegram where to find the bot: (only if you used Terraform to deploy)

make webhook

And the below will tell you the details of the webhook from Telegram:

make webhook-info

How to use it

Please refer to the User's Guide for additional information on how to use the bot.

Environment variables

BUILD_NUMBER = 0

Required for build.

The release or patch version of the compiled code (semantic versioning). For example: BUILD_NUMBER=23 - code version will be: 0.1.23.

LAMBDA_SECRET = <unset_by_default>

Required for deploy.

The URL path prefix that the Lambda function will be listening on. Even if someone finds the Lambda function on the Internet, they will need this secret to be able to issue commands.

TELEGRAM_TOKEN = <unset_by_default>

Required for deploy and webhook.

The token received from @BotFather on Telegram.

ENVIRONMENT = staging

Optional for deploy.

Tag the deployed environment with a name. Default value: staging.

LAMBDA_TIMEOUT = 15

Optional for build and deploy.

Timeout in seconds for the Lambda function. Default value: 15 seconds.

telegram-moderator-bot's People

Contributors

greg-szabo avatar okwme avatar

Watchers

 avatar  avatar

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.