Template for advanced Telegram bots using telebot.v3

Telebot Template

$ git clone https://github.com/massbots/template .
$ chmod +x init.sh; ./init.sh
NOTE The script will delete itself after the configuration.

Project name: ssvideo
Module path: go.massbots.xyz/ssvideo

Dialect (sqlite3|mysql|postgres): postgres
Driver (github.com/lib/pq):

Overview

A basic telebot.v3 template is used for most of our bots. There are two ways of organizing the root, and this one sticks with this project structure. We prefer to use a simpler layout for simpler apps, without separating on pkg and internal directories, keeping every package in the root. But, in the huge projects, where we may have lots of packages as has to be hidden, as exposed, the separation becomes really useful and much more convenient.

So, this is a good example of structuring your advanced bot, when there is too much code for an ordinary main.go file.

Directories

/

The root package, with the name of the module, usually should contain highly generic information. We store the Bootstrap structure here, which defines the basic dependencies required for a successful application performing. It's later used in /internal subpackages for proper initializing.

/locales

This directory consists of bot locales in *.yml files respectively to the telebot/layout format. If you don't need localization in your project, leave a single file and specify its locale code in lt.DefaultLocale("..") call.

/sql

Optional, if you don't use a relational database. It's a directory of *.sql files, formatted in a way to use with goose migration tool.

/cmd

Main binaries for the project. The directory name for each application should match the name of the executable you want to have. We use /cmd/bot for the bot's primary executable. It's common to have a small main function that imports and invokes the code from the /internal and /pkg directories and nothing else.

/pkg

Library code that's ok to use by external applications. It's ok not to use it if your app project is really small and where an extra level of nesting doesn't add much value.

/internal

Private application and library code. This is the code you don't want others importing into their applications or libraries. Note that this layout pattern is enforced by the Go compiler itself.

/internal/bot

Obviously, the core of the bot. Imports root's Bootstrap to initialize itself. It has all the handlers and bot behavior, logically grouped by the files. We also store custom middlewares here in bot/middle subpackage.

For example, imagine your bot has some settings that open as an inline menu on settings command. There are several parameters to be configured, let's say the user's name and delivery address. Where you should put this logic? The best place is settings.go file in the bot package with three functions inside, which are responsible for sending settings menu, asking for a new value to update, and actual updating operation of the specific setting. That way we have three ascending actions relying on each other, and it makes them intuitive by gathering in one place.

/internal/database

A wrapper to simplify the communication with your database. If you're ok with using ORM in your projects, then most likely there is no need for you in this package.

/internal/thread

This becomes useful when you have some background routine to do. One file for each thread logic accordingly. Of course, it's not about OS threads, just a short representative name for the package that holds background logic.

boot := Bootstrap{...}

go thread.ProcessPayments(boot)
go thread.CollectStatistics(boot)

b.Start()
Similar Resources

A simple template using Fiber for me to bootstrap API services quickly.

Fiber Template A simple template using Fiber for me to bootstrap API services quickly. Features Fiber GORM air for hot reloading ... and possibly more

Dec 16, 2021

HTML template engine for Go

Ace - HTML template engine for Go Overview Ace is an HTML template engine for Go. This is inspired by Slim and Jade. This is a refinement of Gold. Exa

Jan 4, 2023

Package damsel provides html outlining via css-selectors and common template functionality.

Damsel Markup language featuring html outlining via css-selectors, extensible via pkg html/template and others. Library This package expects to exist

Oct 23, 2022

Simple and fast template engine for Go

fasttemplate Simple and fast template engine for Go. Fasttemplate performs only a single task - it substitutes template placeholders with user-defined

Dec 30, 2022

A handy, fast and powerful go template engine.

A handy, fast and powerful go template engine.

Hero Hero is a handy, fast and powerful go template engine, which pre-compiles the html templates to go code. It has been used in production environme

Dec 27, 2022

Jet template engine

Jet Template Engine for Go Jet is a template engine developed to be easy to use, powerful, dynamic, yet secure and very fast. simple and familiar synt

Jan 4, 2023

A complete Liquid template engine in Go

A complete Liquid template engine in Go

Liquid Template Parser liquid is a pure Go implementation of Shopify Liquid templates. It was developed for use in the Gojekyll port of the Jekyll sta

Dec 15, 2022

The mustache template language in Go

Overview mustache.go is an implementation of the mustache template language in Go. It is better suited for website templates than Go's native pkg/temp

Dec 22, 2022

Useful template functions for Go templates.

Sprig: Template functions for Go templates The Go language comes with a built-in template language, but not very many template functions. Sprig is a l

Jan 4, 2023
A template to build dynamic web apps quickly using Go, html/template and javascript
A template to build dynamic web apps quickly using Go, html/template and javascript

gomodest-template A modest template to build dynamic web apps in Go, HTML and sprinkles and spots of javascript. Why ? Build dynamic websites using th

Dec 29, 2022
Wrapper package for Go's template/html to allow for easy file-based template inheritance.

Extemplate Extemplate is a small wrapper package around html/template to allow for easy file-based template inheritance. File: templates/parent.tmpl <

Dec 6, 2022
Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application.

goview Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application. Contents Inst

Dec 25, 2022
Fast, powerful, yet easy to use template engine for Go. Optimized for speed, zero memory allocations in hot paths. Up to 20x faster than html/template

quicktemplate A fast, powerful, yet easy to use template engine for Go. Inspired by the Mako templates philosophy. Features Extremely fast. Templates

Dec 26, 2022
Simple system for writing HTML/XML as Go code. Better-performing replacement for html/template and text/template

Simple system for writing HTML as Go code. Use normal Go conditionals, loops and functions. Benefit from typing and code analysis. Better performance than templating. Tiny and dependency-free.

Dec 5, 2022
Made from template temporalio/money-transfer-project-template-go
Made from template temporalio/money-transfer-project-template-go

Temporal Go Project Template This is a simple project for demonstrating Temporal with the Go SDK. The full 20 minute guide is here: https://docs.tempo

Jan 6, 2022
Go-project-template - Template for a golang project

This is a template repository for golang project Usage Go to github: https://git

Oct 25, 2022
Go-api-template - A rough template to give you a starting point for your API

Golang API Template This is only a rough template to give you a starting point f

Jan 14, 2022
Api-go-template - A simple Go API template that uses a controller-service based model to build its routes

api-go-template This is a simple Go API template that uses a controller-service

Feb 18, 2022
Template for Golang rest API using Fiber

Rest API Setup DB sudo -S docker-compose -f db.yml up -d Build container sudo -S docker build -t rest-api-image . Run container from image sudo -S doc

Dec 5, 2021