Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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 main

import (
"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()
}
```