easytgbot

package module
v0.0.0-...-e9910a0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: MIT Imports: 11 Imported by: 0

README

EasyTGBot

Documentation

Index

Constants

View Source
const (
	// UserAgent is http user-agent header
	UserAgent = "EasyTGBot/1.0.0"
	// Endpoint is the endpoint for all API methods,
	// with formatting for Sprintf.
	Endpoint = "https://api.telegram.org/bot%s/%s"
	// FileEndpoint
	FileEndpoint = "https://api.telegram.org/file/bot%s/%s"
)

Telegram constants

Variables

View Source
var MessageNodes = []string{"message", "edited_message", "channel_post", "edited_channel_post", "my_chat_member", "chat_member"}

MessageNodes is message node name

View Source
var MessageQueryNodes = []string{"callback_query", "inline_query", "shipping_query", "pre_checkout_query", "chosen_inline_result"}

MessageQueryNodes is message query node name

Functions

This section is empty.

Types

type Bot

type Bot struct {
	Debug   bool
	ID      int64
	Name    string
	Token   string
	Webhook string
	Buffer  int
	Timeout time.Duration
	Self    Update
	// contains filtered or unexported fields
}

Bot allows you to interact with the Telegram Bot API.

func New

func New(token string, opts Settings) (*Bot, error)

New bot instance

func (*Bot) Action

func (bot *Bot) Action(endpoint interface{}, handler interface{})

Action lets you set the handler for some command name or one of the supported endpoints.

func (*Bot) AnswerCallbackQuery

func (bot *Bot) AnswerCallbackQuery(queryID string, text string, extra JSONBody) (Update, error)

AnswerCallbackQuery see https://core.telegram.org/bots/api#answercallbackquery

func (*Bot) ApplyHandlers

func (bot *Bot) ApplyHandlers(context interface{}, update Update) (JSONBody, error)

ApplyHandlers is apply handler

func (*Bot) DeleteMessage

func (bot *Bot) DeleteMessage(chatID int64, messageID int64) (Update, error)

DeleteMessage see https://core.telegram.org/bots/api#deletemessage

func (*Bot) DeleteWebhook

func (bot *Bot) DeleteWebhook() (Update, error)

DeleteWebhook unsets the webhook.

func (*Bot) EditMessageText

func (bot *Bot) EditMessageText(chatID int64, messageID int64, text string, extra JSONBody) (Update, error)

EditMessageText see https://core.telegram.org/bots/api#editmessagetext

func (bot *Bot) ExportChatInviteLink(chatID int64) (Update, error)

ExportChatInviteLink see https://core.telegram.org/bots/api#exportchatinvitelink

func (*Bot) ForwardMessage

func (bot *Bot) ForwardMessage(chatID int64, fromChatID int64, messageID int64, extra JSONBody) (Update, error)

ForwardMessage send message

func (*Bot) GetChat

func (bot *Bot) GetChat(param interface{}) (Update, error)

GetChat see https://core.telegram.org/bots/api#getchat

func (*Bot) GetChatAdministrators

func (bot *Bot) GetChatAdministrators(param interface{}) (Update, error)

GetChatAdministrators see https://core.telegram.org/bots/api#getchatadministrators

func (*Bot) GetChatMember

func (bot *Bot) GetChatMember(param interface{}, userID int64) (Update, error)

GetChatMember see https://core.telegram.org/bots/api#getchatmember

func (*Bot) GetChatMembersCount

func (bot *Bot) GetChatMembersCount(param interface{}) (Update, error)

GetChatMembersCount see https://core.telegram.org/bots/api#getchatmemberscount

func (*Bot) GetFile

func (bot *Bot) GetFile(fileID string) (string, error)

GetFile see https://core.telegram.org/bots/api#getfile

func (*Bot) GetMe

func (bot *Bot) GetMe() (Update, error)

GetMe fetches the currently authenticated bot.

This method is called upon creation to validate the token, and so you may get this data from Bot.Self without the need for another request.

func (*Bot) GetUpdates

func (bot *Bot) GetUpdates(params JSONBody) (chan Update, error)

GetUpdates starts and returns a channel for getting updates.

func (*Bot) GetWebhookInfo

func (bot *Bot) GetWebhookInfo() (Update, error)

GetWebhookInfo allows you to fetch information about a webhook and if one currently is set, along with pending update count and error messages.

func (*Bot) Handle

func (bot *Bot) Handle(endpoint string, handler interface{})

Handle lets you set the handler for some command name or one of the supported endpoints.

func (*Bot) KickChatMember

func (bot *Bot) KickChatMember(chatID int64, userID int64, untilDate int64) (Update, error)

KickChatMember see https://core.telegram.org/bots/api#kickchatmember

func (*Bot) MakeRequest

func (bot *Bot) MakeRequest(endpoint string, params JSONBody) (Update, error)

MakeRequest makes a request to a specific endpoint with our token.

func (*Bot) PinChatMessage

func (bot *Bot) PinChatMessage(chatID int64, messageID int64, extra JSONBody) (Update, error)

PinChatMessage see https://core.telegram.org/bots/api#pinchatmessage

func (*Bot) RestrictChatMember

func (bot *Bot) RestrictChatMember(chatID int64, userID int64, permissions map[string]bool, untilDate int64) (Update, error)

RestrictChatMember see https://core.telegram.org/bots/api#restrictchatmember

func (*Bot) SendMediaGroup

func (bot *Bot) SendMediaGroup(chatID int64, media []JSONBody, extra JSONBody) (Update, error)

SendMediaGroup see https://core.telegram.org/bots/api#sendmediagroup

func (*Bot) SendMessage

func (bot *Bot) SendMessage(chatID int64, text string, extra JSONBody) (Update, error)

SendMessage send message

func (*Bot) SendPhoto

func (bot *Bot) SendPhoto(chatID int64, fileID string, extra JSONBody) (Update, error)

SendPhoto send message

func (*Bot) SendVideo

func (bot *Bot) SendVideo(chatID int64, fileID string, extra JSONBody) (Update, error)

SendVideo send message

func (*Bot) SetBotID

func (bot *Bot) SetBotID(botID int64)

SetBotID

func (*Bot) SetBotName

func (bot *Bot) SetBotName(name string)

SetBotID

func (*Bot) SetWebhook

func (bot *Bot) SetWebhook(params JSONBody) (Update, error)

SetWebhook sets a webhook.

If this is set, GetUpdates will not get any data!

If you do not have a legitimate TLS certificate, you need to include your self signed certificate with the config.

func (*Bot) UnbanChatMember

func (bot *Bot) UnbanChatMember(chatID int64, userID int64) (Update, error)

UnbanChatMember see https://core.telegram.org/bots/api#unbanchatmember

func (*Bot) UnpinAllChatMessages

func (bot *Bot) UnpinAllChatMessages(chatID int64) (Update, error)

UnpinAllChatMessages see https://core.telegram.org/bots/api#unpinallchatmessages

func (*Bot) Use

func (bot *Bot) Use(middleware ...MiddlewareFunc)

Use

type Error

type Error struct {
	Code       int64
	Message    string
	Parameters Update
}

Error is an error containing extra information returned by the Telegram API.

func (Error) Error

func (e Error) Error() string

type HandlerFunc

type HandlerFunc func(interface{}, *Bot, Update) JSONBody

HandlerFunc defines a function to serve HTTP requests.

type JSONBody

type JSONBody map[string]interface{}

JSONBody is send message

func (JSONBody) Error

func (body JSONBody) Error() string

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc) HandlerFunc

MiddlewareFunc defines a function to process middleware.

type Settings

type Settings struct {
	// debug
	Debug bool // default: false
	// Telegram API Url
	Endpoint string

	// Webhook
	Webhook string

	// Telegram token
	Token string

	// Updates channel capacity
	Updates int // Default: 100

	// Timeout
	Timeout time.Duration // Default: 10s

	Proxy string

	GetMe bool
}

Settings represents a utility struct for passing certain properties of a bot around and is required to make bots.

type Update

type Update struct {
	gjson.Result
}

Update is a response from the Telegram API with the result stored raw.

func NewUpdate

func NewUpdate(data string) Update

NewUpdate is create update instance

func (Update) AnswerCallbackQuery

func (update Update) AnswerCallbackQuery(text string, extra JSONBody) JSONBody

AnswerCallbackQuery is AnswerCallbackQuery

func (Update) Array

func (t Update) Array() []Update

Array returns back an array of values. If the result represents a non-existent value, then an empty array will be returned. If the result is not a Update array, the return value will be an array containing one result.

func (Update) Chat

func (update Update) Chat() (Update, error)

Chat get update

func (Update) Command

func (update Update) Command() (string, string)

Command get command

func (Update) DeleteMessage

func (update Update) DeleteMessage() JSONBody

DeleteMessage see: https://core.telegram.org/bots/api#deletemessage

func (Update) EditMessageReplyMarkup

func (update Update) EditMessageReplyMarkup(extra JSONBody) JSONBody

EditMessageReplyMarkup edit message

func (Update) EditMessageText

func (update Update) EditMessageText(text string, extra JSONBody) JSONBody

EditMessageText edit message

func (Update) Entities

func (update Update) Entities() []Update

Entities is Entities

func (Update) From

func (update Update) From() (Update, error)

From get update

func (Update) Get

func (t Update) Get(path string) Update

Get searches result for the specified path. The result should be a Update array or object.

func (Update) GetType

func (update Update) GetType() string

GetType get message type

func (Update) Map

func (t Update) Map() map[string]Update

Map returns back an map of values. The result should be a Update array.

func (Update) Message

func (update Update) Message() (Update, error)

Message get message

func (Update) Reply

func (update Update) Reply(text string, extra JSONBody) JSONBody

Reply reply message

func (Update) SendMediaGroup

func (update Update) SendMediaGroup(media []JSONBody, extra JSONBody) JSONBody

SendMediaGroup is send media group

func (Update) SendMessage

func (update Update) SendMessage(text string, extra JSONBody) JSONBody

SendMessage is send message

Jump to

Keyboard shortcuts

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