telegrambot

package
v1.1.10122 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TB_TOKEN = "TBTOKEN"
	CHAT_ID  = "TBCHATID"
)

environment values for init telegramBot

Variables

View Source
var (
	ErrBadTelegramBot         = errors.New("Bad TelegramBot parameters")
	ErrTelegramBotMultiple500 = errors.New("Telegram does not response, multiple 500")
	ErrEmptyMessText          = errors.New("Telegram message is empty")
	ErrTooLongMessText        = errors.New("Telegram message is too long")
)

Functions

This section is empty.

Types

type ErrBadBotParams added in v1.0.285

type ErrBadBotParams struct {
	BadParam string
}

func (ErrBadBotParams) Error added in v1.0.285

func (err ErrBadBotParams) Error() string

type TbResponseMessageStruct added in v1.0.18

type TbResponseMessageStruct struct {
	Ok          bool   `json:"ok"`
	ErrorCode   int    `json:"error_code"`
	Description string `json:"description"`
	Result      struct {
		MessageId int `json:"message_id"`
		Chat      struct {
			Id       int64  `json:"id"`
			Title    string `json:"title"`
			Username string `json:"username"`
			Type     string `json:"type"`
		} `json:"chat"`
		Date int64  `json:"date"`
		Text string `json:"text"`
	} `json:"result"`
}

TbResponseMessageStruct json struct to parse response

func (*TbResponseMessageStruct) String added in v1.0.26

func (tbResp *TbResponseMessageStruct) String() string

type TelegramBot

type TelegramBot struct {
	Token          string `yaml:"BotToken"`
	ChatID         string `yaml:"ChatID"`
	RequestURL     string
	Request        *fasthttp.Request
	Response       *fasthttp.Response
	FastHTTPClient *fasthttp.Client
	// contains filtered or unexported fields
}

TelegramBot struct with token and one chats id

func NewTelegramBot

func NewTelegramBot(confPath string) (tb *TelegramBot, err error)

NewTelegramBot reads a config file for bot token and chatID and creates new TelegramBot struct

func NewTelegramBotFromEnv

func NewTelegramBotFromEnv() (tb *TelegramBot, err error)

NewTelegramBotFromEnv is a constructor from ENV

func (*TelegramBot) FastRequest

func (tb *TelegramBot) FastRequest(action string, params map[string]string) (error, *TbResponseMessageStruct)

FastRequest make fasthttp request

func (*TelegramBot) GetChat

func (tb *TelegramBot) GetChat(name string) error

SendMessage is used for sending messages

func (*TelegramBot) GetChatMember

func (tb *TelegramBot) GetChatMember(name string, user string) error

SendMessage is used for sending messages

func (*TelegramBot) GetChatMemberCount

func (tb *TelegramBot) GetChatMemberCount(name string) error

SendMessage is used for sending messages

func (*TelegramBot) GetResult

func (tb *TelegramBot) GetResult() interface{}

GetResult

func (*TelegramBot) GetUpdates

func (tb *TelegramBot) GetUpdates() error

SendMessage is used for sending messages

func (*TelegramBot) InviteUser

func (tb *TelegramBot) InviteUser(name string) error

SendMessage is used for sending messages

func (*TelegramBot) SendMessage

func (tb *TelegramBot) SendMessage(message string, markdown bool, keys ...interface{}) (err error, response *TbResponseMessageStruct)

SendMessage is used for sending messages. Arguments keys must contain TelegramKeyboard{} to add keys to your message

func (*TelegramBot) String added in v1.0.286

func (tb *TelegramBot) String() string

func (*TelegramBot) Write

func (tb *TelegramBot) Write(msg []byte) (int, error)

TelegramBotHandler reads bot params from configPath and accepts some log struct to find if its needed to print some mess to telegram bot

type TelegramKeyboard added in v1.0.11

type TelegramKeyboard struct {
	Keyboard        [][]string `json:"keyboard"`
	OneTimeKeyboard bool       `json:"one_time_keyboard"`
	ResizeKeyboard  bool       `json:"resize_keyboard"`
}

TelegramKeyboard struct for telegram reply_markup keyboard

Jump to

Keyboard shortcuts

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