gotgproto

package module
v1.0.0-beta01 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: GPL-3.0 Imports: 15 Imported by: 5

README

GoTGProto

GoTGProto is a helper package for gotd library, It aims to make td's raw functions easy-to-user with the help of features like using session strings, custom helper functions, storing peers and extracting chat or user ids through it etc.

You can use this package to create bots and userbots with Telegram MTProto easily in golang, for any futher help you can check out the documentations or reach us through the following:

  • Updates Channel: Channel
  • Support Chat: Chat

Go Reference GPLv3 license

Note: This library is in the beta stage yet and may not be stable for every case.

Installation

You can download the library with the help of standard go get command.

go get github.com/anonyindian/gotgproto

Usage

You can find various examples in the examples' directory, one of them i.e. authorizing as a user is as follows:

package main
import (
	"context"
	"github.com/anonyindian/gotgproto"
	"github.com/anonyindian/gotgproto/dispatcher"
	"github.com/anonyindian/gotgproto/sessionMaker"
	"github.com/gotd/td/telegram"
)
func main() {
    dp := dispatcher.MakeDispatcher()
    gotgproto.StartClient(gotgproto.ClientHelper{
		AppID: 1234567,
		ApiHash: "API_HASH_HERE",
		Session: sessionMaker.NewSession("session_name", sessionMaker.Session),
		Phone: "PHONE_NUMBER_HERE",
		Dispatcher: dp,
		TaskFunc: func(ctx context.Context, client *telegram.Client) error {
			return nil
		},
	})
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update examples as appropriate.

License

GPLv3
Licensed Under GNU General Public License v3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Self is the global variable for the authorized user.
	Self *tg.User
	// Api is the global variable for the tg.Client which is used to make the raw function calls.
	Api *tg.Client
	// Sender is the global variable for message sending helper.
	Sender *message.Sender
)

Functions

func StartClient

func StartClient(c ClientHelper)

StartClient is the helper for gotd/td which creates client, runs it, prepares storage etc.

Types

type ClientHelper

type ClientHelper struct {
	// Unique Telegram Application ID, get it from https://my.telegram.org/apps.
	AppID int
	// Unique Telegram API Hash, get it from https://my.telegram.org/apps.
	ApiHash string
	// Session info of the authenticated user, use sessionMaker.NewSession function to fill this field.
	Session *sessionMaker.SessionName
	// BotToken is the unique API Token for the bot you're trying to authorize, get it from @BotFather.
	BotToken string
	// Mobile number of the authenticating user.
	Phone string
	// Dispatcher handlers the incoming updates and execute mapped handlers. It is recommended to use dispatcher.MakeDispatcher function for this field.
	Dispatcher telegram.UpdateHandler
	// TaskFunc is used to for all your post authorization function calls and setting up handlers, check examples for further help.
	TaskFunc func(ctx context.Context, client *telegram.Client) error
	// A Logger provides fast, leveled, structured logging. All methods are safe for concurrent use.
	Logger *zap.Logger
}

func (ClientHelper) CreateClient

func (ch ClientHelper) CreateClient(ctx context.Context, opts telegram.Options,
	setup func(ctx context.Context, Client *telegram.Client) error,
	cb func(ctx context.Context, Client *telegram.Client) error,
) error

func (ClientHelper) Run

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

Jump to

Keyboard shortcuts

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