examples

package module
v0.0.0-...-0a7d951 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: MIT Imports: 12 Imported by: 4

README

Examples

Most examples use environment variable client builders. You can do it manually, see bot-auth-manual for example.

  1. Obtain api_id and api_hash for your application and set as APP_ID, APP_HASH
  2. Set SESSION_FILE to something like ~/session.yourbot.json for persistent auth
  3. Run example.

Please don't share APP_ID or APP_HASH, it can't be easily rotated.

Name Description Features
userbot Userbot example with peer storage and flood wait middelware Custom auth flow, session.Storage, PeerStorage, ResolverCache
bot-auth-manual Bot authentication session.Storage, setup without environment variables
bot-echo Echo bot UpdateDispatcher, message sender
bot-upload One-shot uploader for bot NoUpdates flag, uploads with MIME, custom file name and as audio, resolving peer by username, HTML message
gif-download Saved gif backup (and restore) for user Download, upload, middlewares with rate limit, unpack
bg-run Using client without Run contrib/bg package
pretty-print Pretty-print requests, responses and updates The tgp package, middleware and custom UpdateHandler for all updates
updates Updates engine example The updates package that recovers missed updates

Environment variables

Name Description
BOT_TOKEN Token from BotFather
APP_ID api_id of Telegram app from my.telegram.org
APP_HASH api_hash of Telegram app from my.telegram.org
SESSION_FILE Path to session file, like /home/super-bot/.gotd/session.super-bot.json
SESSION_DIR Path to session directory, if SESSION_FILE is not set, like /home/super-bot/.gotd

Support

Still don't know how to use specific features? See user support.

Documentation

Overview

Package examples contains usage examples for gotd features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(f func(ctx context.Context, log *zap.Logger) error)

Run runs f callback with context and logger, panics on error.

Types

type Terminal

type Terminal struct {
	PhoneNumber string // optional, will be prompted if empty
}

Terminal implements auth.UserAuthenticator prompting the terminal for input.

This is only example implementation, you should not use it in your code. Copy it and modify to fit your needs.

func (Terminal) AcceptTermsOfService

func (Terminal) AcceptTermsOfService(ctx context.Context, tos tg.HelpTermsOfService) error

func (Terminal) Code

func (Terminal) Code(ctx context.Context, sentCode *tg.AuthSentCode) (string, error)

func (Terminal) Password

func (Terminal) Password(_ context.Context) (string, error)

func (Terminal) Phone

func (a Terminal) Phone(_ context.Context) (string, error)

func (Terminal) SignUp

func (Terminal) SignUp(ctx context.Context) (auth.UserInfo, error)

Directories

Path Synopsis
Binary bg-run implements alternative to Run pattern.
Binary bg-run implements alternative to Run pattern.
Binary bot-auth-manual implements example of custom session storage and manually setting up client options without environment variables.
Binary bot-auth-manual implements example of custom session storage and manually setting up client options without environment variables.
Binary bot-echo implements basic example for bot.
Binary bot-echo implements basic example for bot.
Binary bot-upload implements upload example for bot.
Binary bot-upload implements upload example for bot.
Binary gif-download implements example of gif backup.
Binary gif-download implements example of gif backup.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL