https://github.com/celestix/gotgproto
A wrapper for Go Telegram Client, i.e. gotd/td.
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.9%) to scientific vocabulary
Keywords
Repository
A wrapper for Go Telegram Client, i.e. gotd/td.
Basic Info
Statistics
- Stars: 296
- Watchers: 4
- Forks: 47
- Open Issues: 22
- Releases: 21
Topics
Metadata Files
README.md
GoTGProto
GoTGProto is a helper package for gotd library, It aims to make td's raw functions easy-to-use with the help of features like using session strings, custom helper functions, storing peers and extracting chat or user ids through it etc.
We have an outstanding userbot project going on with GoTGProto, you can check it out by clicking here.
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:
- Support Chat:
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.
bash
go get github.com/celestix/gotgproto
Usage
You can find various examples in the examples' directory, one of them i.e. authorizing as a user is as follows: ```go package main
import ( "log"
"github.com/celestix/gotgproto"
"github.com/celestix/gotgproto/sessionMaker"
"github.com/glebarez/sqlite"
)
func main() { client, err := gotgproto.NewClient( // Get AppID from https://my.telegram.org/apps 123456, // Get ApiHash from https://my.telegram.org/apps "APIHASHHERE", // ClientType, as we defined above gotgproto.ClientTypePhone("PHONENUMBERHERE"), // Optional parameters of client &gotgproto.ClientOpts{ Session: sessionMaker.SqlSession(sqlite.Open("echobot")), }, ) if err != nil { log.Fatalln("failed to start client:", err) } client.Idle() } ```
Basic Operations
Here are some quick examples on basic operations like sending a message, media etc.
Naming convention:
- ctx is a *ext.Context object returned as a paramter in all update handlers.
- update is a *ext.Update object returned as a parameter in all update handlers.
- chatId is the chat id of the chat you want to send the message to. (type int64)
Note: You do not need to specify the peer field in the request, it is automatically filled by the library.
Sending a Message
go
ctx.SendMessage(chatId, &tg.MessagesSendMessageRequest{
Message: "Hello, World!",
// Peer: ... (No need of setting peer as we have passed chatId)
})
Uploading media on telegram
If you want to send a local file, you will need to upload it to telegram using an uploader instance as we've done below for test.jpg:
go
f, err := uploader.NewUploader(ctx.Raw).FromPath(ctx, "test.jpg")
if err != nil {
panic(err)
}
Sending uploaded media to a chat
Let's upload the photo (test.jpg) we just uploaded on telegram:
go
ctx.SendMedia(chatId, &tg.MessagesSendMediaRequest{
Message: "This is your caption",
Media: &tg.InputMediaUploadedPhoto{
File: f,
},
})
For media types other than photos, use tg.InputMediaUploadedDocument.
Sending an audio
```go media := &tg.InputMediaUploadedDocument{ File: f, MimeType: "audio/mp4", // or any other mime type like "video/mp4" for videos, "audio/mp4" for audios etc. Thumb: f, // Optional, you can set it to nil if you don't want to set a thumbnail. Attributes: []tg.DocumentAttributeClass{&tg.DocumentAttributeFilename{FileName: f.GetName()}}, }
ctx.SendMedia(chatID, &tg.MessagesSendMediaRequest{ Media: media, Message: "This is your caption" }) ```
Retrieving a photo from a message and sending it
If you want to send a photo from a message, you can do it like this:
go
m := update.EffectiveMessage
// we recommend you to check if the media is a photo casting it in real life applications.
photo := m.Media.(*tg.MessageMediaPhoto).Photo.(*tg.Photo)
ctx.SendMedia(chatId, &tg.MessagesSendMediaRequest{
Media: &tg.InputMediaPhoto{
// Specifying ID, AccessHash and FileReference of the photo is compulsory.
ID: &tg.InputPhoto{
ID: photo.ID,
AccessHash: photo.AccessHash,
FileReference: photo.FileReference,
},
},
})
Sending a file to a chat after retrieving it from a message
go
m := update.EffectiveMessage
// we recommend you to check if the media is a photo casting it in real life applications.
doc := m.Media.(*tg.MessageMediaDocument).Document.(*tg.Document)
ctx.SendMedia(chatId, &tg.MessagesSendMediaRequest{
Media: &tg.InputMediaDocument{
ID: &tg.InputDocument{
ID: doc.ID,
AccessHash: doc.AccessHash,
FileReference: doc.FileReference,
},
},
})
Working with raw tl functions
Telegram has a big library of functions, Gotgproto doesn't have helper for all of them currently, but you can use the raw functions to call any function you want and also utilize this library's features. Here is an example of calling the messages.getHistory function to get chat history:
go
// peer storage is managed by the library automatically with each session. It stores the chat ids and their access hash which are needed to create input peer queries.
peerStorage = ctx.PeerStorage
// get the peer from the chat id
inputPeer := peerStorage.GetInputPeerById(chatId)
// draw out a raw function call using ctx.Raw api
ctx.Raw.MessagesGetHistory(
ctx,
&tg.MessagesGetHistoryRequest{
// Peer is compulsory
Peer: inputPeer,
Limit: 10,
},
)
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 the examples as appropriate.
License
Licensed Under GNU General Public License v3
Owner
- Name: Anony
- Login: celestix
- Kind: user
- Location: Earth
- Company: Humans
- Website: veer.codes
- Twitter: TheVeerRana
- Repositories: 2
- Profile: https://github.com/celestix
Hi👋, I am Veer a.k.a. Anony and the universe is not so small ¯\_(ツ)_/¯
GitHub Events
Total
- Create event: 14
- Commit comment event: 1
- Release event: 4
- Issues event: 22
- Watch event: 79
- Delete event: 5
- Issue comment event: 39
- Push event: 33
- Pull request review event: 2
- Pull request event: 33
- Fork event: 17
Last Year
- Create event: 14
- Commit comment event: 1
- Release event: 4
- Issues event: 22
- Watch event: 79
- Delete event: 5
- Issue comment event: 39
- Push event: 33
- Pull request review event: 2
- Pull request event: 33
- Fork event: 17
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 44
- Total pull requests: 45
- Average time to close issues: about 1 month
- Average time to close pull requests: 7 days
- Total issue authors: 35
- Total pull request authors: 26
- Average comments per issue: 1.52
- Average comments per pull request: 0.69
- Merged pull requests: 21
- Bot issues: 0
- Bot pull requests: 2
Past Year
- Issues: 12
- Pull requests: 25
- Average time to close issues: 18 days
- Average time to close pull requests: 5 days
- Issue authors: 12
- Pull request authors: 14
- Average comments per issue: 1.67
- Average comments per pull request: 0.36
- Merged pull requests: 11
- Bot issues: 0
- Bot pull requests: 1
Top Authors
Issue Authors
- TNT-ma (3)
- XT3RM1NATOR (3)
- celestix (3)
- annihilatorrrr (2)
- AlexShnap (2)
- TrixiS (2)
- maksemen2 (1)
- TheKaram (1)
- dev-freelance-ru (1)
- tiulinh (1)
- SergeyAkaikin (1)
- krau (1)
- timohahaa (1)
- TeaDove (1)
- refaldyrk (1)
Pull Request Authors
- celestix (5)
- Nubuki-all (4)
- qingmeng1 (4)
- krau (4)
- KoNekoD (4)
- DukeAnn (2)
- TeaDove (2)
- dependabot[bot] (2)
- crispony (1)
- Jisin0 (1)
- cynicalwork (1)
- jigarvarma2k20 (1)
- taimast (1)
- PotatoCloud (1)
- dev-freelance-ru (1)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/cache v3 composite
- actions/checkout v3 composite
- actions/setup-go v3 composite
- golangci/golangci-lint-action v3 composite
- github.com/allegro/bigcache v1.2.1
- github.com/cenkalti/backoff/v4 v4.1.3
- github.com/go-faster/errors v0.6.1
- github.com/go-faster/jx v0.40.0
- github.com/go-faster/xor v0.3.0
- github.com/gotd/ige v0.2.2
- github.com/gotd/neo v0.1.5
- github.com/gotd/td v0.71.0
- github.com/jinzhu/inflection v1.0.0
- github.com/jinzhu/now v1.1.3
- github.com/klauspost/compress v1.15.12
- github.com/mattn/go-sqlite3 v1.14.9
- github.com/pkg/errors v0.9.1
- github.com/segmentio/asm v1.2.0
- go.opentelemetry.io/otel v1.11.1
- go.opentelemetry.io/otel/trace v1.11.1
- go.uber.org/atomic v1.10.0
- go.uber.org/multierr v1.8.0
- go.uber.org/zap v1.23.0
- golang.org/x/crypto v0.1.0
- golang.org/x/net v0.1.0
- golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
- golang.org/x/sys v0.1.0
- gorm.io/driver/sqlite v1.2.6
- gorm.io/gorm v1.22.4
- nhooyr.io/websocket v1.8.7
- rsc.io/qr v0.2.0
- github.com/allegro/bigcache v1.2.1
- github.com/benbjohnson/clock v1.1.0
- github.com/cenkalti/backoff/v4 v4.1.3
- github.com/davecgh/go-spew v1.1.0
- github.com/davecgh/go-spew v1.1.1
- github.com/gin-contrib/sse v0.1.0
- github.com/gin-gonic/gin v1.6.3
- github.com/go-faster/errors v0.6.1
- github.com/go-faster/jx v0.39.0
- github.com/go-faster/jx v0.40.0
- github.com/go-faster/xor v0.3.0
- github.com/go-playground/assert/v2 v2.0.1
- github.com/go-playground/locales v0.13.0
- github.com/go-playground/universal-translator v0.17.0
- github.com/go-playground/validator/v10 v10.2.0
- github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee
- github.com/gobwas/pool v0.2.0
- github.com/gobwas/ws v1.0.2
- github.com/golang/protobuf v1.3.3
- github.com/golang/protobuf v1.3.5
- github.com/google/go-cmp v0.4.0
- github.com/google/go-cmp v0.5.8
- github.com/google/go-cmp v0.5.9
- github.com/google/gofuzz v1.0.0
- github.com/gorilla/websocket v1.4.1
- github.com/gotd/ige v0.2.2
- github.com/gotd/neo v0.1.5
- github.com/gotd/td v0.67.0
- github.com/gotd/td v0.71.0
- github.com/jinzhu/inflection v1.0.0
- github.com/jinzhu/now v1.1.2
- github.com/jinzhu/now v1.1.3
- github.com/json-iterator/go v1.1.9
- github.com/klauspost/compress v1.10.3
- github.com/klauspost/compress v1.15.9
- github.com/klauspost/compress v1.15.12
- github.com/leodido/go-urn v1.2.0
- github.com/mattn/go-isatty v0.0.12
- github.com/mattn/go-isatty v0.0.14
- github.com/mattn/go-isatty v0.0.16
- github.com/mattn/go-sqlite3 v1.14.9
- github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421
- github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742
- github.com/pkg/errors v0.9.1
- github.com/pmezard/go-difflib v1.0.0
- github.com/segmentio/asm v1.2.0
- github.com/stretchr/objx v0.1.0
- github.com/stretchr/testify v1.3.0
- github.com/stretchr/testify v1.4.0
- github.com/stretchr/testify v1.7.0
- github.com/stretchr/testify v1.8.0
- github.com/stretchr/testify v1.8.1
- github.com/ugorji/go v1.1.7
- github.com/ugorji/go/codec v1.1.7
- go.opentelemetry.io/otel v1.9.0
- go.opentelemetry.io/otel v1.11.1
- go.opentelemetry.io/otel/trace v1.9.0
- go.opentelemetry.io/otel/trace v1.11.1
- go.uber.org/atomic v1.7.0
- go.uber.org/atomic v1.10.0
- go.uber.org/goleak v1.1.11
- go.uber.org/multierr v1.8.0
- go.uber.org/zap v1.22.0
- go.uber.org/zap v1.23.0
- golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
- golang.org/x/crypto v0.1.0
- golang.org/x/net v0.0.0-20220812174116-3211cb980234
- golang.org/x/net v0.1.0
- golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
- golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
- golang.org/x/sys v0.0.0-20200116001909-b77594299b42
- golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664
- golang.org/x/sys v0.1.0
- golang.org/x/text v0.3.2
- golang.org/x/time v0.0.0-20191024005414-555d28b269f0
- golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e
- golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
- gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
- gopkg.in/yaml.v2 v2.2.2
- gopkg.in/yaml.v2 v2.2.8
- gopkg.in/yaml.v2 v2.3.0
- gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
- gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
- gopkg.in/yaml.v3 v3.0.1
- gorm.io/driver/sqlite v1.2.6
- gorm.io/gorm v1.22.3
- gorm.io/gorm v1.22.4
- nhooyr.io/websocket v1.8.7
- rsc.io/qr v0.2.0