Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Arman92/go-tdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Arman92 committed Jun 4, 2021
2 parents dd0fd93 + 3ea9cda commit 7b90e47
Show file tree
Hide file tree
Showing 7 changed files with 24,854 additions and 10,725 deletions.
111 changes: 111 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"files": [
"README.md"
],
"imageSize": 100,
"commit": false,
"contributors": [
{
"login": "zelenin",
"name": "Aleksandr Zelenin",
"avatar_url": "https://avatars0.githubusercontent.com/u/1427885?v=4",
"profile": "https://github.com/zelenin",
"contributions": [
"example"
]
},
{
"login": "for",
"name": "for",
"avatar_url": "https://avatars1.githubusercontent.com/u/7262123?v=4",
"profile": "https://github.com/for",
"contributions": [
"bug"
]
},
{
"login": "ahmdrz",
"name": "Ahmadreza Zibaei",
"avatar_url": "https://avatars2.githubusercontent.com/u/16955684?v=4",
"profile": "https://zibaei.net",
"contributions": [
"code"
]
},
{
"login": "aivel",
"name": "Max",
"avatar_url": "https://avatars2.githubusercontent.com/u/3083784?v=4",
"profile": "https://github.com/aivel",
"contributions": [
"code"
]
},
{
"login": "rubenv",
"name": "Ruben Vermeersch",
"avatar_url": "https://avatars0.githubusercontent.com/u/42904?v=4",
"profile": "https://rocketeer.be",
"contributions": [
"bug"
]
},
{
"login": "alxshelepenok",
"name": "Alexander Shelepenok",
"avatar_url": "https://avatars2.githubusercontent.com/u/8599449?v=4",
"profile": "https://github.com/alxshelepenok",
"contributions": [
"code",
"maintenance",
"test"
]
},
{
"login": "KarimNahas",
"name": "Karim Nahas",
"avatar_url": "https://avatars3.githubusercontent.com/u/15736459?v=4",
"profile": "https://github.com/KarimNahas",
"contributions": [
"code",
"maintenance",
"bug"
]
},
{
"login": "wcsiu",
"name": "Wachiu Siu",
"avatar_url": "https://avatars0.githubusercontent.com/u/5212960?v=4",
"profile": "https://github.com/wcsiu",
"contributions": [
"example",
"bug",
"doc"
]
},
{
"login": "motylkov",
"name": "motylkov",
"avatar_url": "https://avatars1.githubusercontent.com/u/1659182?v=4",
"profile": "https://github.com/motylkov",
"contributions": [
"code"
]
},
{
"login": "Juliia-b",
"name": "Juliia-b",
"avatar_url": "https://avatars.githubusercontent.com/u/55066322?v=4",
"profile": "https://github.com/Juliia-b",
"contributions": [
"bug"
]
}
],
"contributorsPerLine": 7,
"projectName": "go-tdlib",
"projectOwner": "Arman92",
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true
}
64 changes: 59 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# go-tdlib
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
Golang Telegram TdLib JSON bindings


Expand All @@ -15,7 +18,7 @@ file have been exported using the autogenerate tool [tl-parser](https://github.c
So you can use every single type and method in Tdlib.

## Key features:
* Autogenerated golang structs and methods of tdlib .tl schema
* Autogenerated golang structs and methods out of tdlib .tl schema
* Custom event receivers defined by user (e.g. get only text messages from a specific user)
* Supports all tdjson functions: Send(), Execute(), Receive(), Destroy(), SetFilePath(), SetLogVerbosityLevel()
* Supports all tdlib functions and types
Expand All @@ -39,11 +42,31 @@ If hit any build errors, refer to [Tdlib build instructions](https://github.com/
I'm using static linking against tdlib so it won't require to build the whole tdlib source files.

## Docker
You can use prebuilt tdlib with following Docker image:
You can use the prebuilt tdlib image and Go image of your liking:

***Windows:***
``` shell
docker pull mihaildemidoff/tdlib-go
```
FROM golang:1.15-alpine AS golang
COPY --from=wcsiu/tdlib:1.7-alpine /usr/local/include/td /usr/local/include/td
COPY --from=wcsiu/tdlib:1.7-alpine /usr/local/lib/libtd* /usr/local/lib/
COPY --from=wcsiu/tdlib:1.7-alpine /usr/lib/libssl.a /usr/local/lib/libssl.a
COPY --from=wcsiu/tdlib:1.7-alpine /usr/lib/libcrypto.a /usr/local/lib/libcrypto.a
COPY --from=wcsiu/tdlib:1.7-alpine /lib/libz.a /usr/local/lib/libz.a
RUN apk add build-base
WORKDIR /myApp
COPY . .
RUN go build --ldflags "-extldflags '-static -L/usr/local/lib -ltdjson_static -ltdjson_private -ltdclient -ltdcore -ltdactor -ltddb -ltdsqlite -ltdnet -ltdutils -ldl -lm -lssl -lcrypto -lstdc++ -lz'" -o /tmp/getChats getChats.go
FROM gcr.io/distroless/base:latest
COPY --from=golang /tmp/getChats /getChats
ENTRYPOINT [ "/getChats" ]
```

```
$ docker build -fDockerfile -ttelegram-client .
```

## Example
Expand Down Expand Up @@ -122,3 +145,34 @@ func main() {
```

More examples can be found on [examples folder](https://github.com/Arman92/go-tdlib/tree/master/examples)

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://github.com/zelenin"><img src="https://avatars0.githubusercontent.com/u/1427885?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aleksandr Zelenin</b></sub></a><br /><a href="#example-zelenin" title="Examples">💡</a></td>
<td align="center"><a href="https://github.com/for"><img src="https://avatars1.githubusercontent.com/u/7262123?v=4?s=100" width="100px;" alt=""/><br /><sub><b>for</b></sub></a><br /><a href="https://github.com/Arman92/go-tdlib/issues?q=author%3Afor" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://zibaei.net"><img src="https://avatars2.githubusercontent.com/u/16955684?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ahmadreza Zibaei</b></sub></a><br /><a href="https://github.com/Arman92/go-tdlib/commits?author=ahmdrz" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/aivel"><img src="https://avatars2.githubusercontent.com/u/3083784?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Max</b></sub></a><br /><a href="https://github.com/Arman92/go-tdlib/commits?author=aivel" title="Code">💻</a></td>
<td align="center"><a href="https://rocketeer.be"><img src="https://avatars0.githubusercontent.com/u/42904?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ruben Vermeersch</b></sub></a><br /><a href="https://github.com/Arman92/go-tdlib/issues?q=author%3Arubenv" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/alxshelepenok"><img src="https://avatars2.githubusercontent.com/u/8599449?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alexander Shelepenok</b></sub></a><br /><a href="https://github.com/Arman92/go-tdlib/commits?author=alxshelepenok" title="Code">💻</a> <a href="#maintenance-alxshelepenok" title="Maintenance">🚧</a> <a href="https://github.com/Arman92/go-tdlib/commits?author=alxshelepenok" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/KarimNahas"><img src="https://avatars3.githubusercontent.com/u/15736459?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Karim Nahas</b></sub></a><br /><a href="https://github.com/Arman92/go-tdlib/commits?author=KarimNahas" title="Code">💻</a> <a href="#maintenance-KarimNahas" title="Maintenance">🚧</a> <a href="https://github.com/Arman92/go-tdlib/issues?q=author%3AKarimNahas" title="Bug reports">🐛</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/wcsiu"><img src="https://avatars0.githubusercontent.com/u/5212960?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Wachiu Siu</b></sub></a><br /><a href="#example-wcsiu" title="Examples">💡</a> <a href="https://github.com/Arman92/go-tdlib/issues?q=author%3Awcsiu" title="Bug reports">🐛</a> <a href="https://github.com/Arman92/go-tdlib/commits?author=wcsiu" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/motylkov"><img src="https://avatars1.githubusercontent.com/u/1659182?v=4?s=100" width="100px;" alt=""/><br /><sub><b>motylkov</b></sub></a><br /><a href="https://github.com/Arman92/go-tdlib/commits?author=motylkov" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/Juliia-b"><img src="https://avatars.githubusercontent.com/u/55066322?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Juliia-b</b></sub></a><br /><a href="https://github.com/Arman92/go-tdlib/issues?q=author%3AJuliia-b" title="Bug reports">🐛</a></td>
</tr>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
10 changes: 8 additions & 2 deletions examples/getChats/getChats.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,22 @@ func getChatList(client *tdlib.Client, limit int) error {
if !haveFullChatList && limit > len(allChats) {
offsetOrder := int64(math.MaxInt64)
offsetChatID := int64(0)
var chatList = tdlib.NewChatListMain()
var lastChat *tdlib.Chat

if len(allChats) > 0 {
lastChat = allChats[len(allChats)-1]
offsetOrder = int64(lastChat.Order)
for i := 0; i < len(lastChat.Positions); i++ {
//Find the main chat list
if lastChat.Positions[i].List.GetChatListEnum() == tdlib.ChatListMainType {
offsetOrder = int64(lastChat.Positions[i].Order)
}
}
offsetChatID = lastChat.ID
}

// get chats (ids) from tdlib
chats, err := client.GetChats(tdlib.JSONInt64(offsetOrder),
chats, err := client.GetChats(chatList, tdlib.JSONInt64(offsetOrder),
offsetChatID, int32(limit-len(allChats)))
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions examples/sendText/sendText.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ func main() {
time.Sleep(300 * time.Millisecond)
}

// Send "/start" text every 5 seconds to Forsquare bot chat
// Send "/start" text every 5 seconds to Foursquare bot chat
go func() {
// Should get chatID somehow, check out "getChats" example
chatID := int64(198529620) // Foursquare bot chat id

inputMsgTxt := tdlib.NewInputMessageText(tdlib.NewFormattedText("/start", nil), true, true)
client.SendMessage(chatID, 0, false, true, nil, inputMsgTxt)
client.SendMessage(chatID, int64(0), int64(0), nil, nil, inputMsgTxt)

time.Sleep(5 * time.Second)
}()
Expand Down
Loading

0 comments on commit 7b90e47

Please sign in to comment.