kittenbark/tg

What's that?

This library is designed around
functional components
for reusability and straightforward composition.
With a beautiful codegen behind, there's a method for every single Telegram API endpoint — you can be sure, the code is super consistent, i.e. msg, err := tg.SendMessage(ctx, chatId, "Hello world!").
DevOps in mind, there's tgdeploy — prepared templates Dockerfile & compose.yml, every bot could be easily deployed in the cloud. Docker containers usually take up 8MB of memory and <0.01 CPU on idle.

Example

Let's make a classic echo bot. If you want a more in-depth example, check out kittenbark.com/tg/docs/examples, where we write a Twitter/X media downloader step-by-step from scratch.
package main

import (
	"context"
	"github.com/kittenbark/tg"
)

func main() {
	tg.NewFromEnv().
		OnError(tg.OnErrorLog).                                                // Log any errors/panics.
		Filter(tg.OnPrivate).                                                  // Filter out groups.
		Command("/start", tg.CommonTextReply("hii from kittenbark.com/tg")).   // A special greet on /start.
		Branch(tg.OnMessage, func(ctx context.Context, upd *tg.Update) error { // Echo the message.
			msg := upd.Message
			_, err := tg.CopyMessage(ctx, msg.Chat.Id, msg.Chat.Id, msg.MessageId)
			return err
		}).
		Start()
}