telegram_client

package
v1.0.29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

модуль для использования Телеграмм Клиента (или бота)

Index

Constants

View Source
const MAX_MESSAGE_LEN = 4096

MAX_MESSAGE_LEN - максимальная длина сообщения

Variables

View Source
var MaxSendMessageCountIn1Second float32 = 0.13 //0.13 =4 сообщения в секунду

MaxSendMessageCountIn1Second - максимальное количество сообщений в 1 секунду

Functions

func AddContact

func AddContact(ctx context.Context, phone_send_to string) error

AddContact - добавляет новый контакт в список контактов Телеграм

func AsFloodWait

func AsFloodWait(err error) (d int, ok bool)

AsFloodWait returns wait duration and true boolean if err is the "FLOOD_WAIT" error.

Client should wait for that duration before issuing new requests with same method.

func ConnectTelegram

func ConnectTelegram() error

ConnectTelegram подключение к серверу Телеграм

func CreateTelegramClient

func CreateTelegramClient(func_OnNewMessage func(ctx context.Context, entities tg.Entities, u *tg.UpdateNewMessage) error)

CreateTelegramClient создание клиента Телеграм

func FillSettings

func FillSettings()

FillSettings загружает переменные окружения в структуру из переменных окружения

func FindMessageByID

func FindMessageByID(ctx context.Context, id int) (*tg.Message, error)

FindMessageByID - находит сообщение на сервере Телеграм по id

func FloodWait

func FloodWait(ctx context.Context, err error) bool

FloodWait sleeps required duration and returns true if err is FLOOD_WAIT or false and context or original error otherwise.

func OnNewMessage_Test

func OnNewMessage_Test(ctx context.Context, entities tg.Entities, u *tg.UpdateNewMessage) error

OnNewMessage_Test - пример функции для получения новых сообщений

func SendMessage

func SendMessage(phone_send_to string, text string) (int, error)

SendMessage - отправка сообщения в мессенджер Телеграм возвращает: id = id отправленного сообщения в telegram err = error

func StartTelegram

func StartTelegram(func_OnNewMessage func(ctx context.Context, entities tg.Entities, u *tg.UpdateNewMessage) error)

StartTelegram - подключается к телеграмму, запускает остановку приложения. func_OnNewMessage - функция для приёма новых сообщений

func StopTelegram

func StopTelegram()

StopTelegram - остановка работы клиента Телеграм

func TimeLimit

func TimeLimit()

TimeLimit пауза для ограничения количество сообщений в секунду

func WaitStop

func WaitStop()

WaitStop - ожидает отмену глобального контекста

Types

type SettingsINI

type SettingsINI struct {
	TELEGRAM_APP_ID          int
	TELEGRAM_APP_HASH        string
	TELEGRAM_PHONE_FROM      string
	TELEGRAM_PHONE_SEND_TEST string
}

SettingsINI - структура для хранения всех нужных переменных окружения TELEGRAM_APP_ID, TELEGRAM_APP_HASH - первоначально получить по ссылке: https://my.telegram.org/apps TELEGRAM_PHONE_FROM - номер телефона с которого отправляются сообщения

var Settings SettingsINI

Settings хранит все нужные переменные окружения

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL