diff --git a/README.md b/README.md index f128e4e..c046ce4 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,13 @@ # MTProto -![help wanted](https://img.shields.io/badge/-help%20wanted-success) [![godoc reference](https://pkg.go.dev/badge/github.com/xelaj/mtproto?status.svg)](https://pkg.go.dev/github.com/xelaj/mtproto) [![Go Report Card](https://goreportcard.com/badge/github.com/xelaj/mtproto)](https://goreportcard.com/report/github.com/xelaj/mtproto) +[![codecov](https://codecov.io/gh/xelaj/mtproto/branch/master/graph/badge.svg)](https://codecov.io/gh/xelaj/mtproto) [![license MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/xelaj/mtproto/blob/master/README.md) [![chat telegram](https://img.shields.io/badge/chat-telegram-0088cc)](https://bit.ly/2xlsVsQ) -![version v0.1.0](https://img.shields.io/badge/version-v0.1.0-red) +![version v0.5.0](https://img.shields.io/badge/version-v0.5.0-yellow) ![unstable](https://img.shields.io/badge/stability-unstable-yellow) - - -[english](https://{{ .PackageUrl }}/blob/master/doc/en_US/README.md) **русский** - -{{ .Title.Text }} - -

- -

- -## Как установить - -TODO - -## Как использовать - -![preview]({{ .PreviewUrl }}) - -**Примеры кода [здесь](https://{{ .PackageUrl }}/blob/master/examples)** - -### Simple How-To - -{{ .AdditionalHowto }} - -{{ .SimpleFAQ }} - -## Вклад в проект - -пожалуйста, прочитайте [информацию о помощи]https://{{ .PackageUrl }}/blob/master/doc/ru_RU/CONTRIBUTING.md), если хотите помочь. А помощь очень нужна! - -## TODO - -{{ range $item := .TODO }}* {{ $item }} -{{ end }} -## Авторы - -{{ range $author := .Authors }}* **{{ $author.Name }}** — [{{ $author.Nick }}](https://github.com/{{ $author.Nick }}) -{{ end }} -## Лицензия - -This project is licensed under the MIT License - see the [LICENSE](https://{{ .PackageUrl }}/blob/master/doc/ru_RU/LICENSE.md) file for details diff --git a/docs/ru_RU/nocode_contributing.md b/docs/ru_RU/nocode_contributing.md new file mode 100644 index 0000000..4ff15fc --- /dev/null +++ b/docs/ru_RU/nocode_contributing.md @@ -0,0 +1,31 @@ +# Способы внести свой вклад без кода всего за 5-10 минут + +Итак, вы готовы помочь этому проекту, но не хотите писать код? Это руководство написано специально для вас! Многие из вас спрашивали, как помочь в развитии проекта, но не все умеют писать какие-либо алгоритмы или даже не умеют писать программы на го 😄 + +Но боятся не нужно! Есть много проблем, которые вы можете решить, чтобы помочь проекту! Так что здесь мы собрали несколько замечательных идей, как сделать этот проект лучше! + +## Помогите распостранить информацию + +* Напишите туториалы, cheatsheets или просто обзор (только чур честный) на любых форумах разработки, в блогах и подобных местах. Хорошими вариантами являются [golangbridge](https://forum.golangbridge.org/), [группа в Google](https://groups.google.com/g/golang-nuts), [ycombinator](https://news.ycombinator.com/newest), [Habr] (http://habr.com), (хабр кстати приветствует английские посты, можете писать на английском), яндекс дзен и т. д. или любые телеграммы, такие как [gogolang](https://t.me/gogolang) (если вы нашли какие-либо другие ресурсы, добавьте их, просто создайте PR, в котором допишите еще интересные места) +* Друзьям расскажите своим! Ну типа, прям буквально, поделитесь информацией об этом проекте с кем-нибудь лично или (если в вашем будущем из-за ковида еще ничего не открылось) через какой-нибудь цифровой механизм, типа чатов, или зума. А если ваша компания или команда работает с апи телеграма, то это еще лучше, поделитесь с ними! Это очень просто, но действительно может помочь! +* Share on Twitter, Reddit, Facebook, or odnoklassniki or even Friendster (jk). Anyway, post your review with link to this repo. + +The more people that use the package - the better it will get. I can share with you (don't tell anyone!) that this package uses 10-50 unique people every day. it can grow up up to hundreds or even thousands. So int this community we can find amazing developers which can improve this project! + +## Send bug reports and ask questions + +This is one of the most important contributions in any package for improving stability. Found bug? Create issue. Have some problems? ask it! (just don't ask about what food does love your cat, i mean, problems with this package) + +## Improve docs or tell us about hacking package + +* Did you learn how to do something cool in mtproto but it wasn't obvious on first try? You can contribute to our documentation! +* Docs doesn't cover some specific things? tell us about that! +* you know how to do something, which this package doesn't fit? Cool, share this info about that! + +## Improve current TL schema! + +Unfortunately, native telegram tl schema doesn't have docs. But we love docs! So just copypaste it from official telegram docs, it would be amazing contribution! + +## Another ways to contribute + +This is not **full** list of ideas, how to help this project. Wait, i got another one idea: if you have more nocode contributing ideas: **make PR, post this idea here!** No seriously, we can even make standard guide how to contribute for nocoders like code of conduct but in another way, you know, "code of nocode contributors" 🙃 diff --git a/examples/auth_bot/README.md b/examples/auth_bot/README.md new file mode 100644 index 0000000..9267f21 --- /dev/null +++ b/examples/auth_bot/README.md @@ -0,0 +1,44 @@ +# Example of using Mtproto for Telegram bot + +Mtproto lib can be used with Telegram bot, that can acess to full Telegram API, not just the simplified Telegram Bot API. + +First, we need get register our bot via Telegram [@BotFather](https://t.me/BotFather) and obtain *bot token* and *bot username*. + +![Obtain bot token via BotFather](img/bot_father.jpg) + +Next we [register our app in Telegram](https://my.telegram.org/apps) and obtain + +- ApiID +- ApiHash +- IP addresses of MTProto servers +- Public keys + +![App credentials](img/telegram_org.jpg) + +Save text from "Public keys" field to the `keys.pem` file. + +Other credentials put to `const` section of `main.go` file. + +```go +const ( + // from https://my.telegram.org/apps + TgAppID = XXXXX // integer value from "App api_id" field + TgAppHash = "XXXXXXXXXXXX" // string value from "App api_hash" field + TgTestServer = "149.154.167.40:443" // string value from "Test configuration" field + TgProdServer = "149.154.167.50:443" // string value from "Production configuration" field + + // from https://t.me/BotFather + TgBotToken = "XXXXX" // bot token from BotFather + TgBotUserName = "YourBotUserName" // username of the bot +) +``` + +Then run: + +``` +go run main.go +``` + +For my bot I have next output: + +![Bot info](img/go_run.jpg) diff --git a/examples/auth_bot/img/bot_father.jpg b/examples/auth_bot/img/bot_father.jpg new file mode 100644 index 0000000..a3c20ba Binary files /dev/null and b/examples/auth_bot/img/bot_father.jpg differ diff --git a/examples/auth_bot/img/go_run.jpg b/examples/auth_bot/img/go_run.jpg new file mode 100644 index 0000000..4cdc6e5 Binary files /dev/null and b/examples/auth_bot/img/go_run.jpg differ diff --git a/examples/auth_bot/img/telegram_org.jpg b/examples/auth_bot/img/telegram_org.jpg new file mode 100644 index 0000000..2a68e0d Binary files /dev/null and b/examples/auth_bot/img/telegram_org.jpg differ diff --git a/examples/auth_bot/keys.pem b/examples/auth_bot/keys.pem new file mode 100644 index 0000000..68bc3ed --- /dev/null +++ b/examples/auth_bot/keys.pem @@ -0,0 +1 @@ +put here the text from "Public keys" field at https://my.telegram.org/apps \ No newline at end of file diff --git a/examples/auth_bot/main.go b/examples/auth_bot/main.go new file mode 100644 index 0000000..2a3fa60 --- /dev/null +++ b/examples/auth_bot/main.go @@ -0,0 +1,105 @@ +// Example of using Mtproto for Telegram bot +package main + +import ( + "fmt" + "os" + + "github.com/xelaj/mtproto/telegram" +) + +const ( + // from https://my.telegram.org/apps + TgAppID = XXXXX // integer value from "App api_id" field + TgAppHash = "XXXXXXXXXXXX" // string value from "App api_hash" field + TgTestServer = "149.154.167.40:443" // string value from "Test configuration" field + TgProdServer = "149.154.167.50:443" // string value from "Production configuration" field + + // from https://t.me/BotFather + TgBotToken = "XXXXX" // bot token from BotFather + TgBotUserName = "YourBotUserName" // username of the bot +) + +func main() { + client, err := telegram.NewClient(telegram.ClientConfig{ + // current dir must be writable + // file 'session.json' will be created here + SessionFile: "./session.json", + // file 'keys.pem' must contain text from "Public keys" field + // from https://my.telegram.org/apps + PublicKeysFile: "./keys.pem", + // we need to use production Telegram API server + // because test server don't know about our bot + ServerHost: TgProdServer, + AppID: TgAppID, + AppHash: TgAppHash, + }) + if err != nil { + fmt.Println("NewClient error:", err.Error()) + os.Exit(1) + } + + // Trying to auth as bot with our bot token + _, err = client.AuthImportBotAuthorization(&telegram.AuthImportBotAuthorizationParams{ + Flags: 1, // reserved, must be set (not 0) + ApiId: TgAppID, + ApiHash: TgAppHash, + BotAuthToken: TgBotToken, + }) + if err != nil { + fmt.Println("ImportBotAuthorization error:", err.Error()) + os.Exit(1) + } + + // Request info about username of our bot + uname, err := client.ContactsResolveUsername(&telegram.ContactsResolveUsernameParams{Username: TgBotUserName}) + if err != nil { + fmt.Println("ResolveUsername error:", err.Error()) + os.Exit(1) + } + + chatsCount := len(uname.Chats) + // No chats for requested username of our bot + if chatsCount > 0 { + fmt.Println("Chats number:", chatsCount) + os.Exit(1) + } + + usersCount := len(uname.Users) + // Users vector must contain single item with information about our bot + if usersCount != 1 { + fmt.Println("Users number:", usersCount) + os.Exit(1) + } + + user := uname.Users[0].(*telegram.UserObj) + + // dump our bot info + fmt.Println("\nSelf ->", user.Self) + fmt.Println("Username ->", user.Username) + fmt.Println("FirstName ->", user.FirstName) + fmt.Println("LastName ->", user.LastName) + fmt.Println("Id ->", user.Id) + fmt.Println("Bot ->", user.Bot) + fmt.Println("Verified ->", user.Verified) + fmt.Println("Restricted ->", user.Restricted) + fmt.Println("Support ->", user.Support) + fmt.Println("Scam ->", user.Scam) + fmt.Println("BotInfoVersion ->", user.BotInfoVersion) + + // fmt.Println("Contact ->", user.Contact) + // fmt.Println("MutualContact ->", user.MutualContact) + // fmt.Println("Deleted ->", user.Deleted) + // fmt.Println("BotChatHistory ->", user.BotChatHistory) + // fmt.Println("BotNochats ->", user.BotNochats) + // fmt.Println("Min ->", user.Min) + // fmt.Println("BotInlineGeo ->", user.BotInlineGeo) + // fmt.Println("ApplyMinPhoto ->", user.ApplyMinPhoto) + // fmt.Println("AccessHash ->", user.AccessHash) + // fmt.Println("Phone ->", user.Phone) + // fmt.Println("Photo ->", user.Photo) + // fmt.Println("Status ->", user.Status) + // fmt.Println("RestrictionReason ->", user.RestrictionReason) + // fmt.Println("BotInlinePlaceholder ->", user.BotInlinePlaceholder) + // fmt.Println("LangCode ->", user.LangCode) +}