- Notifications
You must be signed in to change notification settings - Fork136
🦋 Full-native go implementation of Telegram API
License
xelaj/mtproto
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Full-native implementation of MTProto protocol on Golang!
MTProto is really hard in implementation, but it's really easy to use. Basically, this lib sends serialized structures to Telegram servers (just like gRPC, but from Telegram LLC.). It looks like this:
funcmain() {client:=telegram.NewClient()// for each method there is specific struct for serialization (<method_name>Params{})result,err:=client.MakeRequest(&telegram.GetSomeInfoParams{FromChatId:12345})iferr!=nil {panic(err) }resp,ok:=result.(*SomeResponseObject)if!ok {panic("Oh no! Wrong type!") }}
Not so hard, huh? But there is even easier way to send request, which is included in TL API specification:
funcmain() {client:=telegram.NewClient()resp,err:=client.GetSomeInfo(12345)iferr!=nil {panic(err) }// resp will be already asserted as described in TL specs of API// if _, ok := resp.(*SomeResponseObject); !ok {// panic("No way, we found a bug! Create new issue!")// }println(resp.InfoAboutSomething)}
You do not need to think about encryption, key exchange, saving and restoring session, and more routine things. It is already implemented just for you.
Code examples arehere
Full docs arehere
Installation is simple. Just dogo get
:
go get github.com/xelaj/mtproto
After that you can generate source structures of methods and functions if you wish to. To do it, usego generate
go generate github.com/xelaj/mtproto
That's it! You don't need to do anything more!
It's Telegram specific feature. If you want to create client instance and get information about the current server's configuration, you need to do something like this:
resp,err:=client.InvokeWithLayer(apiVersion,&telegram.InitConnectionParams{ApiID:124100,DeviceModel:"Unknown",SystemVersion:"linux/amd64",AppVersion:"0.1.0",// just use "en", any other language codes will receive error. See telegram docs for more info.SystemLangCode:"en",LangCode:"en",// HelpGetConfig() is ACTUAL request, but wrapped in InvokeWithLayerQuery:&telegram.HelpGetConfigParams{},})
Why? We don't know! This method is described in Telegram API docs, any other starting requests will receive error.
Examplehere
funcAuthByPhone() {resp,err:=client.AuthSendCode(yourPhone,appID,appHash,&telegram.CodeSettings{}, )iferr!=nil {panic(err) }// You can make any way to enter verification code, like in// http requests, or what you like. You just need to call two// requests, that's main method.fmt.Print("Auth code:")code,_:=bufio.NewReader(os.Stdin).ReadString('\n')code=strings.Replace(code,"\n","",-1)// this is ALL process of authorization! :)fmt.Println(client.AuthSignIn(yourPhone,resp.PhoneCodeHash,code))}
That's it! You don't need any cycles, code is ready-to-go for async execution. You just need to follow the official Telegram API documentation.
Want to deal those freakytg://
links? Seedeeplinks
package, here is the simplest how-to:
package mainimport ("fmt""github.com/xelaj/mtproto/telegram/deeplinks")funcmain() {link,_:=deeplinks.Resolve("t.me/xelaj_developers")// btw, ResolveParameters is just struct for tg://resolve links, not all links are resolveresolve:=link.(*deeplinks.ResolveParameters)fmt.Printf("Oh! Looks like @%v is the best developers channel in telegram!\n",resolve.Domain)}
There is a pretty huge chunk of documentation. We are ready to describe every method and object, but it requires a lot of work. Althoughall methods arealready describedhere.
Technically — yes. In practice — components don't require specific architecture, but we didn't test it yet. If you have any problems running it, just create an issue, we will try to help.
Well... Readthis issue about TON source code. Use google translate, this issue will answer to all your questions.
Please readcontributing guide if you want to help. And the help is very necessary!
Don't want code? Readthis page! We love nocoders!
Please, don't create issue which describes security bug, this can be too offensive! Instead, please readthis notification and follow that steps to notify us about problem.
- Basic MTProto implementation
- Implement all Methods for latest layer
- Make TL Encoder/Decoder
- Get away from panics in parsing TL
- Support MTProxy
- Support socks5 as well
- Multiple tests
- Write amazing docs
- Richard Cooper <rcooper.xelaj@protonmail.com>
- Anton Larionov <Anton.Larionov@infobip.com>
- Arthur Petukhovsky <petuhovskiy@yandex.ru>
- Roman Timofeev <timofeev@uteka.ru>
- Artem <webgutar@gmail.com>
- Bo-Yi Wu <appleboy.tw@gmail.com>
- 0xflotus <0xflotus@gmail.com>
- Luclu7 <me@luclu7.fr>
- Vladimir Stolyarov <xakep6666@gmail.com>
- grinrill@grinrill
- kulallador <ilyastalk@bk.ru>
- rs <yuiop1955@mail.ru>
WARNING! This project is only maintained by Xelaj inc., however copyright of this source codeIS NOT owned by Xelaj inc. at all. If you want to connect with code owners, write mail tothis email. For all other questions like any issues, PRs, questions, etc. Use GitHub issues, or find email on official website.
This project is licensed under the MIT License - see theLICENSE file for details
About
🦋 Full-native go implementation of Telegram API