Skip to content

This repository is about how to avoid telegram limits for ordinary and group messages.

Notifications You must be signed in to change notification settings

soluchok/tsender

Repository files navigation

Golang package to avoid Telegram limits

GoDoc Build Status codecov

Features:

  • messages per user are delivered consistently
  • group and users messages are supported
  • messages are sent deferred

Install

go get -u github.com/soluchok/tsender

Example

package main

import (
	"fmt"
	"net/http"
	"time"

	"github.com/go-telegram-bot-api/telegram-bot-api"
	"github.com/soluchok/tsender"
)

const (
	token         = "1****:******************A"
	chatID  int64 = 64432422
	groupID int64 = -243783656
	workers int   = 8
)

func getClient() *http.Client {
	transport, ok := http.DefaultTransport.(*http.Transport)
	if !ok {
		panic("http.DefaultClient is not an http.Client")
	}
	transport.MaxIdleConnsPerHost = workers
	return &http.Client{Transport: transport}
}

type Provider struct {
	bot *tgbotapi.BotAPI
}

func (p *Provider) Send(msg interface{}) {
	_, err := p.bot.Send(msg.(tgbotapi.Chattable))
	if err != nil {
		fmt.Println(err)
	}
}

func main() {
	bot, err := tgbotapi.NewBotAPIWithClient(token, getClient())
	if err != nil {
		panic(err)
	}

	sender := tsender.NewSender(&Provider{bot})

	go sender.Run(workers)
	defer sender.Stop()

	for i := 1; i <= 5; i++ {
		sender.Send(chatID, tgbotapi.NewMessage(chatID, fmt.Sprintf("Hi, chat %d", i)))
		sender.Send(groupID, tgbotapi.NewMessage(groupID, fmt.Sprintf("Hi, group %d", i)))
	}

	time.Sleep(time.Second * 5)
}

About

This repository is about how to avoid telegram limits for ordinary and group messages.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages