Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/talentlessguy/telegram-bot-stats
Go library for collecting usage stats of telegram bots.
https://github.com/talentlessguy/telegram-bot-stats
telegram telegram-bots
Last synced: 23 days ago
JSON representation
Go library for collecting usage stats of telegram bots.
- Host: GitHub
- URL: https://github.com/talentlessguy/telegram-bot-stats
- Owner: talentlessguy
- Created: 2020-06-06T16:48:47.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-11T17:59:36.000Z (about 2 years ago)
- Last Synced: 2024-10-02T08:31:16.078Z (about 1 month ago)
- Topics: telegram, telegram-bots
- Language: Go
- Homepage:
- Size: 1.95 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# telegram-bot-stats
Go library for collecting usage stats of telegram bots.
It produces the following json file:
```jsonc
{
"count": 2,
"ids": ["123", "456"] // telegram user IDs
}
```## Install
```sh
go get github.com/talentlessguy/telegram-bot-stats
```## Examples
### [telebot](https://github.com/tucnak/telebot)
```go
package mainimport (
"log"
"os"
"strconv"
"time""github.com/joho/godotenv"
tb "gopkg.in/tucnak/telebot.v2"
stats "github.com/talentlessguy/telegram-bot-stats"
)func main() {
b, err := tb.NewBot(tb.Settings{
Token: "TOKEN",
Poller: &tb.LongPoller{Timeout: 10 * time.Second},
})if err != nil {
log.Fatal(err)
}b.Handle("/start", func(m *tb.Message) {
stats.AddUserToStat(m)
})b.Handle("/getstat", func(m *tb.Message) {
json := stats.ParseStatJSON()
out := "User count: " + strconv.Itoa(json.Count)
b.Send(m.Sender, out)
})b.Start()
}
```