gogram

package module
v0.0.0-...-5aa7747 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: GPL-3.0 Imports: 30 Imported by: 0

README

GσGram
========

.. epigraph::

  ⚒️ Under Development.



Gogram is an open-source Telegram MTProto_ client written in the Go programming language (also known as Golang). It provides an easy-to-use API for building applications that interact with the Telegram API.

Gogram is designed to be fast and efficient, and it has no external dependencies, making it easy to use and integrate into your projects. It also supports native entity parser, inter DC requests, and friendlier methods, which can help simplify the process of interacting with Telegram's API.

*If you're looking to build a Telegram client or bot using the Go programming language, Gogram is definitely worth considering. Its open-source nature also means that you can contribute to its development and suggest new features or improvements.*


Layer - 170


What is this?
-------------

Telegram is a popular messaging application. This library is meant
to make it easy for you to write Golang programs that can interact
with Telegram. Think of it as a wrapper that has already done the
heavy job for you, so you can focus on developing an application.

Known Bugs
----------

• Find em:)

PRs and Issues are always welcome.

|imx| |imgo| |cma|



Features
--------

Light Weight compared to other go- mtproto clients. Fast compiling and execution, All commonly used methods are made more friendly,
Reliable updates handling system

Installing
----------

.. code-block:: sh

  go get -u github.com/roj1512/gogram

    
Set-Up Client
-----------------

.. code-block:: golang

    client, _ := gogram.TelegramClient(gogram.ClientConfig{
         AppID: 0, 
         AppHash: "", 
    })
    client.ConnectBot(botToken) // client.Login(phoneNumber)
    client.Idle() // start infinite polling


Doing stuff
-----------

.. code-block:: golang

    var b = telegram.Button{}
    opts := &telegram.SendOptions{
        Caption: "Game of Thrones",
        ReplyMarkup: b.Keyboard(b.Row(b.URL("Imdb", "http://imdb.com/title/tt0944947/"))),
    })

    fmt.Println(client.GetMe())

    message, _ := client.SendMessage("username", "Hello I'm talking to you from gogram!")
    message.Edit("Yep!")

    album, _ := client.SendAlbum("username", []string{'file1.jpg', 'file2.jpg'})
    message.GetMediaGroup()

    message.ReplyMedia(url, opts)

    client.DeleteMessage("username", message.ID)

    message.ForwardTo(message.ChatID())
    peer := client.ResolvePeer("username")
    client.GetParticipant("chat", "user")

    client.EditAdmin(chatID, userID, &telegram.AdminOptions{
        AdminRights: &telegram.ChatAdminRights{
            AddAdmins: true,
        },
        Rank: "Admin",
    })

    client.GetMessages(chatID, &telegram.SearchOptions{Limit: 1})

    action, _ := client.SendAction(chat, "typing")
    defer action.Cancel()

    client.KickParticipant(chatID, userID)
    client.EditBanned(chatID, userID, &telegram.BannedOptions{Mute: true})
    client.DownloadMedia(message, "download.jpg")
    client.EditTitle("me", "MyNewAmazingName")

    client.UploadFile("file.txt")
    p := client.GetChatMember("chat", "user")

    p.CanChangeInfo()
    p.GetRank()
    client.InlineQuery("@pic", &telegram.InlineOptions{Query: "", Dialog: "@chat"})
    client.GetChatPhotos(chatID)
    client.GetDialogs()
    client.GetStats("channel")
    client.GetCustomEmoji("documentID")
    
    conv, _ = client.NewConversation("username")
    conv.GetResponse()
    
    client.CreateChannel("Title")
    
    albumHandle := client.AddAlbumHandler(func (a *telegram.Album) error {
           fmt.Println(a.GroupedID)
           a.Forward(chat_id)
           return nil
    }
    albumHandle.Remove()
    
    client.SendDice("username", "🎲")

TODO
----------

- ✔️ Basic MTProto implementation
- ✔️ Implement all Methods for latest layer (147)
- ✔️ Entity Cache + Friendly Methods
- ✔️ Add Update Handle System
- ✔️ Make a reliable HTML Parser
- ✔️ Friendly Methods to Handle CallbackQuery, VoiceCalls
- ✔️ Add Flag2.0 Parser (Then update to Layer-170)
- ✔️ Fix File handling
- 📝 Write beautiful Docs
- 📝 Multiple tests


.. _MTProto: https://core.telegram.org/mtproto
.. _chat: https://t.me/rosexchat
.. |image| image:: https://te.legra.ph/file/fe4dbc185ff2138cbdf45.jpg
  :width: 400
  :alt: Logo

.. |imx| image:: https://img.shields.io/github/issues/amarnathcjd/gogram
   :alt: GitHub issues

.. |imgo| image:: https://img.shields.io/github/go-mod/go-version/amarnathcjd/gogram/master
   :alt: GitHub go.mod Go version (branch & subdirectory of monorepo)

.. |cma| image:: https://img.shields.io/github/commit-activity/y/amarnathcjd/gogram
   :alt: GitHub commit activity

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MessageRequireToAck

func MessageRequireToAck(msg tl.Object) bool

func RpcErrorToNative

func RpcErrorToNative(r *objects.RpcError) error

func Sha1

func Sha1(input string) []byte

func Sha1Byte

func Sha1Byte(input []byte) []byte

func TryExpandError

func TryExpandError(errStr string) (nativeErrorName string, additionalData any)

Types

type BadMsgError

type BadMsgError struct {
	*objects.BadMsgNotification
	Description string
}

func BadMsgErrorFromNative

func BadMsgErrorFromNative(in *objects.BadMsgNotification) *BadMsgError

func (*BadMsgError) Error

func (e *BadMsgError) Error() string

type BadSystemMessageCode

type BadSystemMessageCode int32
const (
	ErrBadMsgUnknown             BadSystemMessageCode = 0
	ErrBadMsgIdTooLow            BadSystemMessageCode = 16
	ErrBadMsgIdTooHigh           BadSystemMessageCode = 17
	ErrBadMsgIncorrectMsgIdBits  BadSystemMessageCode = 18
	ErrBadMsgWrongContainerMsgId BadSystemMessageCode = 19 // this must never happen
	ErrBadMsgMessageTooOld       BadSystemMessageCode = 20
	ErrBadMsgSeqNoTooLow         BadSystemMessageCode = 32
	ErrBadMsgSeqNoTooHigh        BadSystemMessageCode = 33
	ErrBadMsgSeqNoExpectedEven   BadSystemMessageCode = 34
	ErrBadMsgSeqNoExpectedOdd    BadSystemMessageCode = 35
	ErrBadMsgServerSaltIncorrect BadSystemMessageCode = 48
	ErrBadMsgInvalidContainer    BadSystemMessageCode = 64
)

type Config

type Config struct {
	AuthKeyFile    string
	StringSession  string
	SessionStorage session.SessionLoader
	MemorySession  bool
	AppID          int32

	ServerHost string
	PublicKey  *rsa.PublicKey
	DataCenter int
	LogLevel   string
	SocksProxy *url.URL
}

type ErrResponseCode

type ErrResponseCode struct {
	Code           int
	Message        string
	Description    string
	AdditionalInfo any // some errors has additional data like timeout seconds, dc id etc.
}

func (*ErrResponseCode) Error

func (e *ErrResponseCode) Error() string

type MTProto

type MTProto struct {
	Addr string

	PublicKey *rsa.PublicKey

	Logger *utils.Logger
	// contains filtered or unexported fields
}

func NewMTProto

func NewMTProto(c Config) (*MTProto, error)

func (*MTProto) AddCustomServerRequestHandler

func (m *MTProto) AddCustomServerRequestHandler(handler func(i any) bool)

func (*MTProto) AppID

func (m *MTProto) AppID() int32

func (*MTProto) CreateConnection

func (m *MTProto) CreateConnection(withLog bool) error

func (*MTProto) DeleteSession

func (m *MTProto) DeleteSession() (err error)

func (*MTProto) Disconnect

func (m *MTProto) Disconnect() error

func (*MTProto) ExportAuth

func (m *MTProto) ExportAuth() ([]byte, []byte, string, int, int32)

func (*MTProto) ExportNewSender

func (m *MTProto) ExportNewSender(dcID int, mem bool) (*MTProto, error)

func (*MTProto) GetAuthKey

func (m *MTProto) GetAuthKey() []byte

GetAuthKey returns decryption key of current session salt 🧐

func (*MTProto) GetDC

func (m *MTProto) GetDC() int

func (*MTProto) GetSeqNo

func (m *MTProto) GetSeqNo() int32

GetSeqNo returns seqno 🧐

func (*MTProto) GetServerSalt

func (m *MTProto) GetServerSalt() int64

GetServerSalt returns current server salt 🧐

func (*MTProto) GetSessionID

func (m *MTProto) GetSessionID() int64

func (*MTProto) ImportAuth

func (m *MTProto) ImportAuth(stringSession string) (bool, error)

func (*MTProto) ImportRawAuth

func (m *MTProto) ImportRawAuth(authKey []byte, authKeyHash []byte, addr string, _ int, appID int32) (bool, error)

func (*MTProto) InvokeRequestWithoutUpdate

func (m *MTProto) InvokeRequestWithoutUpdate(data tl.Object, expectedTypes ...reflect.Type) error

func (*MTProto) LoadSession

func (m *MTProto) LoadSession(s *session.Session)

func (*MTProto) MakeRequest

func (m *MTProto) MakeRequest(msg tl.Object) (any, error)

func (*MTProto) MakeRequestWithHintToDecoder

func (m *MTProto) MakeRequestWithHintToDecoder(msg tl.Object, expectedTypes ...reflect.Type) (any, error)

func (*MTProto) Pin

func (mtproto *MTProto) Pin(pinner *runtime.Pinner)

func (*MTProto) Ping

func (m *MTProto) Ping() time.Duration

func (*MTProto) Reconnect

func (m *MTProto) Reconnect(WithLogs bool) error

func (*MTProto) ReconnectToNewDC

func (m *MTProto) ReconnectToNewDC(dc int) (*MTProto, error)

func (*MTProto) SaveSession

func (m *MTProto) SaveSession() (err error)

func (*MTProto) SetAuthKey

func (m *MTProto) SetAuthKey(key []byte)

func (*MTProto) TcpActive

func (m *MTProto) TcpActive() bool

func (*MTProto) Terminate

func (m *MTProto) Terminate() error

func (*MTProto) UpdateSeqNo

func (m *MTProto) UpdateSeqNo() int32

Jump to

Keyboard shortcuts

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