echotron

package module
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: GPL-3.0 Imports: 13 Imported by: 1

README

echotron Language PkgGoDev Go Report Card License Build Status Coverage Status Mentioned in Awesome Go Maintainability

Library for telegram bots written in pure go

Fetch with

go get github.com/NicoNex/echotron/v2

Usage

Long Polling

A very simple implementation:

package main

import (
    "log"

    "github.com/NicoNex/echotron/v2"
)

type bot struct {
    chatId int64
    echotron.API
}

const token = "YOUR TELEGRAM TOKEN"

func newBot(chatId int64) echotron.Bot {
    return &bot{
        chatId,
        echotron.NewAPI(token),
    }
}

func (b *bot) Update(update *echotron.Update) {
    if update.Message.Text == "/start" {
        b.SendMessage("Hello world", b.chatId)
    }
}

func main() {
    dsp := echotron.NewDispatcher(token, newBot)
    log.Println(dsp.Poll())
}

Also proof of concept with self destruction for low ram usage

package main

import (
    "log"
    "time"

    "github.com/NicoNex/echotron/v2"
)

type bot struct {
    chatId int64
    echotron.API
}

const token = "YOUR TELEGRAM TOKEN"

var dsp echotron.Dispatcher

func newBot(chatId int64) echotron.Bot {
    var bot = &bot{
        chatId,
        echotron.NewAPI(token),
    }
    go bot.selfDestruct(time.After(time.Hour))
    return bot
}

func (b *bot) selfDestruct(timech <- chan time.Time) {
    select {
    case <-timech:
        b.SendMessage("goodbye", b.chatId)
        dsp.DelSession(b.chatId)
    }
}

func (b *bot) Update(update *echotron.Update) {
    if update.Message.Text == "/start" {
        b.SendMessage("Hello world", b.chatId)
    }
}

func main() {
    dsp := echotron.NewDispatcher(token, newBot)
    log.Println(dsp.Poll())
}
Webhook
package main

import "github.com/NicoNex/echotron/v2"

type bot struct {
	chatId int64
	echotron.API
}

const token = "YOUR TELEGRAM TOKEN"

func newBot(chatId int64) echotron.Bot {
	return &bot{
		chatId,
		echotron.NewAPI(token),
	}
}

func (b *bot) Update(update *echotron.Update) {
	if update.Message.Text == "/start" {
		b.SendMessage("Hello world", b.chatId)
	}
}

func main() {
	dsp := echotron.NewDispatcher(token, newBot)
	dsp.ListenWebhook("https://example.com:443/my_bot_token")
}

Documentation

Index

Constants

View Source
const (
	ParseMarkdown         Option = "&parse_mode=markdown"
	ParseMarkdownV2              = "&parse_mode=markdownv2"
	ParseHTML                    = "&parse_mode=html"
	DisableWebPagePreview        = "&disable_web_page_preview=true"
	DisableNotification          = "&disable_notification=true"
)

These are all the possible options that can be used by some methods.

View Source
const (
	Typing          ChatAction = "typing"
	UploadPhoto                = "upload_photo"
	RecordVideo                = "record_video"
	UploadVideo                = "upload_video"
	RecordAudio                = "record_audio"
	UploadAudio                = "upload_audio"
	UploadDocument             = "upload_document"
	FindLocation               = "find_location"
	RecordVideoNote            = "record_video_note"
	UploadVideoNote            = "upload_video_note"
)

These are all the possible actions that can be sent through the SendChatAction method.

View Source
const (
	ARTICLE  InlineQueryType = "article"
	PHOTO                    = "photo"
	GIF                      = "gif"
	MPEG4GIF                 = "mpeg4_gif"
	VIDEO                    = "video"
	AUDIO                    = "audio"
	VOICE                    = "voice"
	DOCUMENT                 = "document"
	LOCATION                 = "location"
	VENUE                    = "venue"
	CONTACT                  = "contact"
	GAME                     = "game"
	STICKER                  = "sticker"
)

These are all the possible types for the various InlineQueryResult*'s Type field.

Variables

This section is empty.

Functions

This section is empty.

Types

type API added in v2.2.0

type API string

API is the object that contains all the functions that wrap those of the Telegram Bot API.

func NewAPI added in v2.2.0

func NewAPI(token string) API

NewAPI returns a new API object.

func (API) AnswerCallbackQuery added in v2.2.0

func (a API) AnswerCallbackQuery(callbackID, text string, showAlert bool) (APIResponseMessage, error)

AnswerCallbackQuery is used to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.

func (API) AnswerInlineQuery added in v2.2.0

func (a API) AnswerInlineQuery(inlineQueryID string, results []InlineQueryResult) (APIResponseBase, error)

AnswerInlineQuery is a wrapper method for AnswerInlineQueryOptions.

func (API) AnswerInlineQueryOptions added in v2.2.0

func (a API) AnswerInlineQueryOptions(inlineQueryID string, results []InlineQueryResult, opts InlineQueryOptions) (APIResponseBase, error)

AnswerInlineQueryOptions is used to send answers to an inline query.

func (API) Command added in v2.2.0

func (a API) Command(command, description string) BotCommand

Command is a wrapper method for the BotCommand type. It's used to create a new command for the bot.

func (API) DeleteMessage added in v2.2.0

func (a API) DeleteMessage(chatID int64, messageID int) (APIResponseMessage, error)

DeleteMessage is used to delete a message, including service messages, with the following limitations: - A message can only be deleted if it was sent less than 48 hours ago. - A dice message in a private chat can only be deleted if it was sent more than 24 hours ago. - Bots can delete outgoing messages in private chats, groups, and supergroups. - Bots can delete incoming messages in private chats. - Bots granted can_post_messages permissions can delete outgoing messages in channels. - If the bot is an administrator of a group, it can delete any message there. - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.

func (API) DeleteWebhook added in v2.2.0

func (a API) DeleteWebhook() (APIResponseUpdate, error)

DeleteWebhook is used to remove webhook integration if you decide to switch back to getUpdates.

func (API) EditMessageReplyMarkup added in v2.2.0

func (a API) EditMessageReplyMarkup(chatID int64, messageID int, keyboard []byte) (APIResponseMessage, error)

EditMessageReplyMarkup is used to edit only the reply markup of messages.

func (API) EditMessageText added in v2.2.0

func (a API) EditMessageText(chatID int64, messageID int, text string, opts ...Option) (APIResponseMessage, error)

EditMessageText is used to edit text and game messages.

func (API) EditMessageTextWithKeyboard added in v2.2.0

func (a API) EditMessageTextWithKeyboard(chatID int64, messageID int, text string, keyboard []byte, opts ...Option) (APIResponseMessage, error)

EditMessageTextWithKeyboard is the same as EditMessageText, but allows to send a custom keyboard.

func (API) GetChat added in v2.2.0

func (a API) GetChat(chatID int64) (APIResponseChat, error)

GetChat is used to get up to date information about the chat. (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.)

func (API) GetChatAdministrators added in v2.3.0

func (a API) GetChatAdministrators(chatID int64) (APIResponseAdmins, error)

GetChatAdministrators is used to get a list of administrators in a chat.

func (API) GetMyCommands added in v2.2.0

func (a API) GetMyCommands() (APIResponseCommands, error)

GetMyCommands is used to get the current list of the bot's commands.

func (API) GetStickerSet added in v2.2.0

func (a API) GetStickerSet(name string) (APIResponseStickerSet, error)

GetStickerSet is used to get a sticker set.

func (API) GetUpdates added in v2.2.0

func (a API) GetUpdates(offset, timeout int) (APIResponseUpdate, error)

GetUpdates is used to receive incoming updates using long polling.

func (API) InlineKbdBtn added in v2.2.0

func (a API) InlineKbdBtn(text, url, callbackData string) InlineButton

InlineKbdBtn is a wrapper method for the InlineButton type. It's used to create a new inline keyboard button.

func (API) InlineKbdBtnCbd added in v2.2.0

func (a API) InlineKbdBtnCbd(text, callbackData string) InlineButton

InlineKbdBtnCbd is a wrapper method for InlineKbdBtn, but only with callbackData.

func (API) InlineKbdBtnURL added in v2.2.0

func (a API) InlineKbdBtnURL(text, url string) InlineButton

InlineKbdBtnURL is a wrapper method for InlineKbdBtn, but only with url.

func (API) InlineKbdMarkup added in v2.2.0

func (a API) InlineKbdMarkup(inlineKbdRows ...InlineKbdRow) (jsn []byte)

InlineKbdMarkup represents an inline keyboard that appears right next to the message it belongs to. This method generates the actual JSON that will be sent to Telegram to make the desired inline keyboard show up in a message.

func (API) InlineKbdRow added in v2.2.0

func (a API) InlineKbdRow(inlineButtons ...InlineButton) InlineKbdRow

InlineKbdRow is a wrapper method for the InlineKbdRow type. It's used to create a row of inline keyboard buttons.

func (API) KeyboardButton added in v2.2.0

func (a API) KeyboardButton(text string, requestContact, requestLocation bool) Button

KeyboardButton is a wrapper method for the Button type. It's used to create a new keyboard button.

func (API) KeyboardMarkup added in v2.2.0

func (a API) KeyboardMarkup(resizeKeyboard, oneTimeKeyboard, selective bool, keyboardRows ...KbdRow) (kbd []byte)

KeyboardMarkup represents a custom keyboard with reply options. This method generates the actual JSON that will be sent to Telegram to make the desired keyboard show up in a message.

func (API) KeyboardRemove added in v2.2.0

func (a API) KeyboardRemove(selective bool) (kbdrmv []byte)

KeyboardRemove generates the object to send in a message to remove the current custom keyboard and display the default letter-keyboard.

func (API) KeyboardRow added in v2.2.0

func (a API) KeyboardRow(buttons ...Button) (kbdRow KbdRow)

KeyboardRow is a wrapper method for the KbdRow type. It's used to create a row of keyboard buttons.

func (API) SendAnimation added in v2.2.0

func (a API) SendAnimation(fpath, caption string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendAnimation is used to send animation files (GIF or H.264/MPEG-4 AVC video without sound).

func (API) SendAnimationByID added in v2.2.0

func (a API) SendAnimationByID(animationID, caption string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendAnimationByID is used to send animation files (GIF or H.264/MPEG-4 AVC video without sound) that already exist on the Telegram servers.

func (API) SendAnimationBytes added in v2.2.0

func (a API) SendAnimationBytes(fpath, caption string, chatID int64, data []byte, opts ...Option) (APIResponseMessage, error)

SendAnimationBytes is used to send animation files (GIF or H.264/MPEG-4 AVC video without sound) as a slice of bytes.

func (API) SendAnimationWithKeyboard added in v2.4.0

func (a API) SendAnimationWithKeyboard(fpath, caption string, chatID int64, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendAnimationWithKeyboard is used to send animation files (GIF or H.264/MPEG-4 AVC video without sound) with a keyboard.

func (API) SendAnimationWithKeyboardBytes added in v2.4.0

func (a API) SendAnimationWithKeyboardBytes(fpath, caption string, chatID int64, data []byte, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendAnimationWithKeyboardBytes is used to send animation files (GIF or H.264/MPEG-4 AVC video without sound) as a slice of bytes with a keyboard.

func (API) SendAudio added in v2.2.0

func (a API) SendAudio(fpath, caption string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendAudio is used to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format.

func (API) SendAudioByID added in v2.2.0

func (a API) SendAudioByID(audioID, caption string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendAudioByID is used to send audio files that already exist on the Telegram servers, if you want Telegram clients to display them in the music player.

func (API) SendAudioBytes added in v2.2.0

func (a API) SendAudioBytes(fpath, caption string, chatID int64, data []byte, opts ...Option) (APIResponseMessage, error)

SendAudioBytes is used to send audio files as a slice of bytes, if you want Telegram clients to display them in the music player.

func (API) SendAudioWithKeyboard added in v2.4.0

func (a API) SendAudioWithKeyboard(fpath, caption string, chatID int64, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendAudioWithKeyboard is used to send audio files with a keyboard.

func (API) SendAudioWithKeyboardBytes added in v2.4.0

func (a API) SendAudioWithKeyboardBytes(fpath, caption string, chatID int64, data []byte, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendAudioWithKeyboardBytes is used to send audio files as a slice of bytes with a keyboard.

func (API) SendChatAction added in v2.2.0

func (a API) SendChatAction(action ChatAction, chatID int64) (APIResponseMessage, error)

SendChatAction is used to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).

func (API) SendContact added in v2.2.0

func (a API) SendContact(phoneNumber, firstName, lastName string, chatID int64) (APIResponseMessage, error)

SendContact is used to send phone contacts.

func (API) SendDocument added in v2.2.0

func (a API) SendDocument(fpath, caption string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendDocument is used to send general files.

func (API) SendDocumentByID added in v2.2.0

func (a API) SendDocumentByID(documentID, caption string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendDocumentByID is used to send general files that already exist on the Telegram servers.

func (API) SendDocumentBytes added in v2.2.0

func (a API) SendDocumentBytes(fpath, caption string, chatID int64, data []byte, opts ...Option) (APIResponseMessage, error)

SendDocumentBytes is used to send general files as a slice of bytes.

func (API) SendDocumentWithKeyboard added in v2.4.0

func (a API) SendDocumentWithKeyboard(fpath, caption string, chatID int64, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendDocumentWithKeyboard is used to send general files with a keyboard.

func (API) SendDocumentWithKeyboardBytes added in v2.4.0

func (a API) SendDocumentWithKeyboardBytes(fpath, caption string, chatID int64, data []byte, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendDocumentWithKeyboardBytes is used to send general files as a slice of bytes with a keyboard.

func (API) SendMessage added in v2.2.0

func (a API) SendMessage(text string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendMessage is used to send text messages.

func (API) SendMessageReply added in v2.2.0

func (a API) SendMessageReply(text string, chatID int64, messageID int, opts ...Option) (APIResponseMessage, error)

SendMessageReply is used to send a message as a reply to a previously received one.

func (API) SendMessageWithKeyboard added in v2.2.0

func (a API) SendMessageWithKeyboard(text string, chatID int64, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendMessageWithKeyboard is used to send a message with a keyboard.

func (API) SendPhoto added in v2.2.0

func (a API) SendPhoto(fpath, caption string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendPhoto is used to send photos.

func (API) SendPhotoByID added in v2.2.0

func (a API) SendPhotoByID(photoID, caption string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendPhotoByID is used to send photos through an ID of a photo that already exists on the Telegram servers.

func (API) SendPhotoBytes added in v2.2.0

func (a API) SendPhotoBytes(fpath, caption string, chatID int64, data []byte, opts ...Option) (APIResponseMessage, error)

SendPhotoBytes is used to send photos as a slice of bytes.

func (API) SendPhotoWithKeyboard added in v2.2.0

func (a API) SendPhotoWithKeyboard(fpath, caption string, chatID int64, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendPhotoWithKeyboard is used to send photos with a keyboard.

func (API) SendPhotoWithKeyboardBytes added in v2.2.0

func (a API) SendPhotoWithKeyboardBytes(fpath, caption string, chatID int64, data []byte, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendPhotoWithKeyboardBytes is used to send photos as a slice of bytes with a keyboard.

func (API) SendSticker added in v2.2.0

func (a API) SendSticker(stickerID string, chatID int64) (APIResponseMessage, error)

SendSticker is used to send static .WEBP or animated .TGS stickers.

func (API) SendVideo added in v2.2.0

func (a API) SendVideo(fpath, caption string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendVideo is used to send video files. Telegram clients support mp4 videos (other formats may be sent with SendDocument).

func (API) SendVideoByID added in v2.2.0

func (a API) SendVideoByID(videoID, caption string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendVideoByID is used to send video files that already exist on the Telegram servers.

func (API) SendVideoBytes added in v2.2.0

func (a API) SendVideoBytes(fpath, caption string, chatID int64, data []byte, opts ...Option) (APIResponseMessage, error)

SendVideoBytes is used to send video files as a slice of bytes.

func (API) SendVideoNote added in v2.2.0

func (a API) SendVideoNote(fpath string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendVideoNote is used to send video messages.

func (API) SendVideoNoteByID added in v2.2.4

func (a API) SendVideoNoteByID(videoID string, chatID int64) (APIResponseMessage, error)

SendVideoNoteByID is used to send video messages that already exist on the Telegram servers.

func (API) SendVideoNoteBytes added in v2.2.4

func (a API) SendVideoNoteBytes(fpath string, chatID int64, data []byte, opts ...Option) (APIResponseMessage, error)

SendVideoNoteBytes is used to send video messages as a slice of bytes.

func (API) SendVideoNoteWithKeyboard added in v2.4.0

func (a API) SendVideoNoteWithKeyboard(fpath string, chatID int64, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendVideoNoteWithKeyboard is used to send video messages with a keyboard.

func (API) SendVideoNoteWithKeyboardBytes added in v2.4.0

func (a API) SendVideoNoteWithKeyboardBytes(fpath string, chatID int64, data []byte, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendVideoNoteWithKeyboardBytes is used to send video messages as a slice of bytes with a keyboard.

func (API) SendVideoWithKeyboard added in v2.4.0

func (a API) SendVideoWithKeyboard(fpath, caption string, chatID int64, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendVideoWithKeyboard is used to send video files with a keyboard.

func (API) SendVideoWithKeyboardBytes added in v2.4.0

func (a API) SendVideoWithKeyboardBytes(fpath, caption string, chatID int64, data []byte, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendVideoWithKeyboardBytes is used to send video files as a slice of bytes with a keyboard.

func (API) SendVoice added in v2.2.0

func (a API) SendVoice(fpath, caption string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendVoice is used to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS (other formats may be sent as Audio or Document).

func (API) SendVoiceByID added in v2.2.0

func (a API) SendVoiceByID(voiceID, caption string, chatID int64, opts ...Option) (APIResponseMessage, error)

SendVoiceByID is used to send audio files that already exists on the Telegram servers, if you want Telegram clients to display the file as a playable voice message.

func (API) SendVoiceBytes added in v2.2.0

func (a API) SendVoiceBytes(fpath, caption string, chatID int64, data []byte, opts ...Option) (APIResponseMessage, error)

SendVoiceBytes is used to send audio files as a slice of bytes, if you want Telegram clients to display the file as a playable voice message.

func (API) SendVoiceWithKeyboard added in v2.4.0

func (a API) SendVoiceWithKeyboard(fpath, caption string, chatID int64, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendVoiceWithKeyboard is used to send audio files with a keyboard, if you want Telegram clients to display the file as a playable voice message.

func (API) SendVoiceWithKeyboardBytes added in v2.4.0

func (a API) SendVoiceWithKeyboardBytes(fpath, caption string, chatID int64, data []byte, keyboard []byte, opts ...Option) (APIResponseMessage, error)

SendVoiceWithKeyboardBytes is used to send audio files as a slice of bytes with a keyboard, if you want Telegram clients to display the file as a playable voice message.

func (API) SetMyCommands added in v2.2.0

func (a API) SetMyCommands(commands ...BotCommand) (APIResponseCommands, error)

SetMyCommands is used to change the list of the bot's commands.

func (API) SetWebhook added in v2.2.0

func (a API) SetWebhook(url string) (APIResponseUpdate, error)

SetWebhook is used to specify a url and receive incoming updates via an outgoing webhook.

type APIResponseAdmins added in v2.3.0

type APIResponseAdmins struct {
	Result []ChatMember `json:"result,omitempty"`
	APIResponseBase
}

APIResponseAdmins represents the incoming response from Telegram servers. Used by GetChatAdministrator (since it returns an array of ChatMembers).

type APIResponseBase

type APIResponseBase struct {
	Ok          bool   `json:"ok"`
	ErrorCode   int    `json:"error_code,omitempty"`
	Description string `json:"description,omitempty"`
}

APIResponseBase is a base type that represents the incoming response from Telegram servers. Used by APIResponse* to slim down the implementation.

type APIResponseChat added in v2.2.2

type APIResponseChat struct {
	Result *Chat `json:"result,omitempty"`
	APIResponseBase
}

APIResponseChat represents the incoming response from Telegram servers. Used by GetChat (since it returns a Chat).

type APIResponseCommands

type APIResponseCommands struct {
	Result []BotCommand `json:"result,omitempty"`
	APIResponseBase
}

APIResponseCommands represents the incoming response from Telegram servers. Used by SetMyCommands and GetMyCommands (since they return an array of BotCommands).

type APIResponseMessage

type APIResponseMessage struct {
	Result *Message `json:"result,omitempty"`
	APIResponseBase
}

APIResponseMessage represents the incoming response from Telegram servers. Used by the methods in the api.go module (since they return a Message).

type APIResponseStickerSet added in v2.2.2

type APIResponseStickerSet struct {
	Result *StickerSet `json:"result,omitempty"`
	APIResponseBase
}

APIResponseStickerSet represents the incoming response from Telegram servers. Used by GetStickerSet (since it returns a StickerSet).

type APIResponseUpdate

type APIResponseUpdate struct {
	Result []*Update `json:"result,omitempty"`
	APIResponseBase
}

APIResponseUpdate represents the incoming response from Telegram servers. Used by getUpdates (since it returns an array of Updates).

type Animation added in v2.2.2

type Animation struct {
	FileID   string     `json:"file_id"`
	FileUID  string     `json:"file_unique_id"`
	Width    int        `json:"width"`
	Height   int        `json:"height"`
	Duration int        `json:"duration"`
	Thumb    *PhotoSize `json:"thumb,omitempty"`
	FileName string     `json:"file_name,omitempty"`
	MimeType string     `json:"mime_type,omitempty"`
	FileSize int        `json:"file_size,omitempty"`
}

Animation represents an animation file (GIF or H.264/MPEG-4 AVC video without sound).

type Audio

type Audio struct {
	FileID    string     `json:"file_id"`
	FileUID   string     `json:"file_unique_id"`
	Duration  int        `json:"duration"`
	Performer string     `json:"performer,omitempty"`
	Title     string     `json:"title,omitempty"`
	FileName  string     `json:"file_name,omitempty"`
	MimeType  string     `json:"mime_type,omitempty"`
	FileSize  int        `json:"file_size,omitempty"`
	Thumb     *PhotoSize `json:"thumb,omitempty"`
}

Audio represents an audio file to be treated as music by the Telegram clients.

type Bot

type Bot interface {
	// Update will be called upon receiving any update from Telegram.
	Update(*Update)
}

Bot is the interface that must be implemented by your definition of the struct thus it represent each open session with a user on Telegram.

type BotCommand

type BotCommand struct {
	Command     string `json:"command"`
	Description string `json:"description"`
}

BotCommand represents a bot command.

type Button

type Button struct {
	Text            string `json:"text"`
	RequestContact  bool   `json:"request_contact,omitempty"`
	RequestLocation bool   `json:"request_location,omitempty"`
}

Button represents a button in a keyboard.

type CallbackQuery

type CallbackQuery struct {
	ID              string   `json:"id"`
	User            *User    `json:"from"`
	Message         *Message `json:"message,omitempty"`
	InlineMessageID string   `json:"inline_message_id,omitempty"`
	Data            string   `json:"data,omitempty"`
}

CallbackQuery represents an incoming callback query from a callback button in an inline keyboard. If the button that originated the query was attached to a message sent by the bot, the field message will be present. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be present. Exactly one of the fields data or game_short_name will be present.

type Chat

type Chat struct {
	ID                    int64            `json:"id"`
	Type                  string           `json:"type"`
	Title                 string           `json:"title,omitempty"`
	Username              string           `json:"username,omitempty"`
	FirstName             string           `json:"first_name,omitempty"`
	LastName              string           `json:"last_name,omitempty"`
	Photo                 *ChatPhoto       `json:"photo,omitempty"`
	Bio                   string           `json:"bio,omitempty"`
	Description           string           `json:"description,omitempty"`
	InviteLink            string           `json:"invite_link,omitempty"`
	PinnedMessage         *Message         `json:"pinned_message,omitempty"`
	Permissions           *ChatPermissions `json:"permissions,omitempty"`
	SlowModeDelay         int              `json:"slow_mode_delay,omitempty"`
	MessageAutoDeleteTime int              `json:"message_auto_delete_time,omitempty"`
	StickerSetName        string           `json:"sticker_set_name,omitempty"`
	CanSetStickerSet      bool             `json:"can_set_sticker_set,omitempty"`
	LinkedChatID          int64            `json:"linked_chat_id,omitempty"`
	Location              *ChatLocation    `json:"location,omitempty"`
}

Chat represents a chat.

type ChatAction

type ChatAction string

ChatAction is a custom type for the various actions that can be sent through the SendChatAction method.

type ChatInviteLink struct {
	InviteLink  string `json:"invite_link"`
	Creator     *User  `json:"creator"`
	IsPrimary   bool   `json:"is_primary"`
	IsRevoked   bool   `json:"is_revoked"`
	ExpireDate  int    `json:"expire_date,omitempty"`
	MemberLimit int    `json:"member_limit,omitempty"`
}

ChatInviteLink represents an invite link for a chat.

type ChatLocation added in v2.2.2

type ChatLocation struct {
	Location *Location `json:"location"`
	Address  string    `json:"address"`
}

ChatLocation represents a location to which a chat is connected.

type ChatMember added in v2.2.2

type ChatMember struct {
	User                  *User  `json:"user"`
	Status                string `json:"status"`
	CustomTitle           string `json:"custom_title,omitempty"`
	IsAnonymous           bool   `json:"is_anonymous,omitempty"`
	CanBeEdited           bool   `json:"can_be_edited,omitempty"`
	CanManageChat         bool   `json:"can_manage_chat,omitempty"`
	CanPostMessages       bool   `json:"can_post_messages,omitempty"`
	CanEditMessages       bool   `json:"can_edit_messages,omitempty"`
	CanDeleteMessages     bool   `json:"can_delete_messages,omitempty"`
	CanManageVoiceChats   bool   `json:"can_manage_voice_chats,omitempty"`
	CanRestrictMembers    bool   `json:"can_restrict_members,omitempty"`
	CanPromoteMembers     bool   `json:"can_promote_members,omitempty"`
	CanChangeInfo         bool   `json:"can_change_info,omitempty"`
	CanInviteUsers        bool   `json:"can_invite_users,omitempty"`
	CanPinMessages        bool   `json:"can_pin_messages,omitempty"`
	IsMember              bool   `json:"is_member,omitempty"`
	CanSendMessages       bool   `json:"can_send_messages,omitempty"`
	CanSendMediaMessages  bool   `json:"can_send_media_messages,omitempty"`
	CanSendPolls          bool   `json:"can_send_polls,omitempty"`
	CanSendOtherMessages  bool   `json:"can_send_other_messages,omitempty"`
	CanAddWebPagePreviews bool   `json:"can_add_web_page_previews,omitempty"`
	UntilDate             int    `json:"until_date,omitempty"`
}

ChatMember contains information about one member of a chat.

type ChatMemberUpdated added in v2.2.2

type ChatMemberUpdated struct {
	Chat          *Chat           `json:"chat"`
	User          *User           `json:"from"`
	Date          int             `json:"date"`
	OldChatMember *ChatMember     `json:"old_chat_member"`
	NewChatMember *ChatMember     `json:"new_chat_member"`
	InviteLink    *ChatInviteLink `json:"invite_link,omitempty"`
}

ChatMemberUpdated represents changes in the status of a chat member.

type ChatPermissions added in v2.2.2

type ChatPermissions struct {
	CanSendMessages       bool `json:"can_send_messages,omitempty"`
	CanSendMediaMessages  bool `json:"can_send_media_messages,omitempty"`
	CanSendPolls          bool `json:"can_send_polls,omitempty"`
	CanSendOtherMessages  bool `json:"can_send_other_messages,omitempty"`
	CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"`
	CanChangeInfo         bool `json:"can_change_info,omitempty"`
	CanInviteUsers        bool `json:"can_invite_users,omitempty"`
	CanPinMessages        bool `json:"can_pin_messages,omitempty"`
}

ChatPermissions describes actions that a non-administrator user is allowed to take in a chat.

type ChatPhoto added in v2.2.2

type ChatPhoto struct {
	SmallFileID  string `json:"small_file_id"`
	SmallFileUID string `json:"small_file_unique_id"`
	BigFileID    string `json:"big_file_id"`
	BigFileUID   string `json:"big_file_unique_id"`
}

ChatPhoto represents a chat photo.

type ChosenInlineResult

type ChosenInlineResult struct {
	ResultID        string    `json:"result_id"`
	From            *User     `json:"from"`
	Location        *Location `json:"location,omitempty"`
	InlineMessageID string    `json:"inline_message_id,omitempty"`
	Query           string    `json:"query"`
}

ChosenInlineResult represents a result of an inline query that was chosen by the user and sent to their chat partner.

type Contact

type Contact struct {
	PhoneNumber string `json:"phone_number"`
	FirstName   string `json:"first_name"`
	LastName    string `json:"last_name,omitempty"`
	UserID      int    `json:"user_id,omitempty"`
	Vcard       string `json:"vcard,omitempty"`
}

Contact represents a phone contact.

type Dice added in v2.2.2

type Dice struct {
	Emoji string `json:"emoji"`
	Value int    `json:"value"`
}

Dice represents an animated emoji that displays a random value.

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

The Dispatcher passes the updates from the Telegram Bot API to the Bot instance associated with each chatID. When a new chat ID is found, the provided function of type NewBotFn will be called.

func NewDispatcher

func NewDispatcher(token string, newBotFn NewBotFn) *Dispatcher

NewDispatcher returns a new instance of the Dispatcher object. Calls the Update function of the bot associated with each chat ID. If a new chat ID is found, newBotFn will be called first.

func (*Dispatcher) AddSession

func (d *Dispatcher) AddSession(chatID int64)

AddSession allows to arbitrarily create a new Bot instance.

func (*Dispatcher) DelSession

func (d *Dispatcher) DelSession(chatID int64)

DelSession deletes the Bot instance, seen as a session, from the map with all of them.

func (*Dispatcher) ListenWebhook

func (d *Dispatcher) ListenWebhook(webhookURL string) error

ListenWebhook sets a webhook and listens for incoming updates. The webhookUrl should be provided in the following format: '<hostname>:<port>/<path>', eg: 'https://example.com:443/bot_token'. ListenWebhook will then proceed to communicate the webhook url '<hostname>/<path>' to Telegram and run a webserver that listens to ':<port>' and handles the path.

func (*Dispatcher) Poll

func (d *Dispatcher) Poll() error

Poll starts the polling loop so that the dispatcher calls the function Update upon receiving any update from Telegram.

type Document

type Document struct {
	FileID   string     `json:"file_id"`
	FileUID  string     `json:"file_unique_id"`
	Thumb    *PhotoSize `json:"thumb,omitempty"`
	FileName string     `json:"file_name,omitempty"`
	MimeType string     `json:"mime_type,omitempty"`
	FileSize int        `json:"file_size,omitempty"`
}

Document represents a general file (as opposed to photos, voice messages and audio files).

type Game added in v2.2.1

type Game struct {
	Title        string          `json:"title"`
	Description  string          `json:"description"`
	Photo        []PhotoSize     `json:"photo"`
	Text         string          `json:"text,omitempty"`
	TextEntities []MessageEntity `json:"text_entities,omitempty"`
	// contains filtered or unexported fields
}

Game represents a game.

type InlineButton

type InlineButton struct {
	Text         string `json:"text"`
	URL          string `json:"url,omitempty"`
	CallbackData string `json:"callback_data,omitempty"`
}

InlineButton represents a button in an inline keyboard.

type InlineKbdRow

type InlineKbdRow []InlineButton

InlineKbdRow represents a row of buttons in an inline keyboard.

type InlineKeyboard

type InlineKeyboard struct {
	InlineKeyboard []InlineKbdRow `json:"inline_keyboard"`
}

InlineKeyboard represents an inline keyboard.

type InlineQuery

type InlineQuery struct {
	ID       string    `json:"id"`
	From     *User     `json:"from"`
	Location *Location `json:"location,omitempty"`
	Query    string    `json:"query"`
	Offset   string    `json:"offset"`
}

InlineQuery represents an incoming inline query. When the user sends an empty query, your bot could return some default or trending results.

type InlineQueryOptions added in v2.1.0

type InlineQueryOptions struct {
	CacheTime         int
	IsPersonal        bool
	NextOffset        string
	SwitchPmText      string
	SwitchPmParameter string
}

InlineQueryOptions is a custom type which contains the various options required by the AnswerInlineQueryOptions method.

type InlineQueryResult added in v2.1.0

type InlineQueryResult interface {
	ImplementsInlineQueryResult()
}

InlineQueryResult represents an interface that implements all the various InlineQueryResult* types.

type InlineQueryResultArticle added in v2.1.0

type InlineQueryResultArticle struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	Title               string              `json:"title"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	URL                 string              `json:"url,omitempty"`
	HideURL             bool                `json:"hide_url,omitempty"`
	Description         string              `json:"description,omitempty"`
	ThumbURL            string              `json:"thumb_url,omitempty"`
	ThumbWidth          int                 `json:"thumb_width,omitempty"`
	ThumbHeight         int                 `json:"thumb_height,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultArticle represents a link to an article or web page.

func (InlineQueryResultArticle) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultArticle) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultAudio added in v2.1.0

type InlineQueryResultAudio struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	AudioURL            string              `json:"audio_url"`
	Title               string              `json:"title"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	Performer           string              `json:"performer,omitempty"`
	AudioDuration       int                 `json:"audio_duration,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultAudio represents a link to an MP3 audio file. By default, this audio file will be sent by the user. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the audio.

func (InlineQueryResultAudio) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultAudio) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultCachedAudio added in v2.1.0

type InlineQueryResultCachedAudio struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	AudioFileID         string              `json:"audio_file_id"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultCachedAudio represents a link to an MP3 audio file stored on the Telegram servers. By default, this audio file will be sent by the user. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the audio.

func (InlineQueryResultCachedAudio) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultCachedAudio) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultCachedDocument added in v2.1.0

type InlineQueryResultCachedDocument struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	Title               string              `json:"title"`
	DocumentFileID      string              `json:"document_file_id"`
	Description         string              `json:"description,omitempty"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultCachedDocument represents a link to a file stored on the Telegram servers. By default, this file will be sent by the user with an optional caption. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the file.

func (InlineQueryResultCachedDocument) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultCachedDocument) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultCachedGif added in v2.1.0

type InlineQueryResultCachedGif struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	GifFileID           string              `json:"gif_file_id"`
	Title               string              `json:"title,omitempty"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultCachedGif represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file will be sent by the user with an optional caption. Alternatively, you can use InputMessageContent to send a message with specified content instead of the animation.

func (InlineQueryResultCachedGif) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultCachedGif) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultCachedMpeg4Gif added in v2.1.0

type InlineQueryResultCachedMpeg4Gif struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	Mpeg4FileID         string              `json:"mpeg4_file_id"`
	Title               string              `json:"title,omitempty"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultCachedMpeg4Gif represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By default, this animated MPEG-4 file will be sent by the user with an optional caption. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the animation.

func (InlineQueryResultCachedMpeg4Gif) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultCachedMpeg4Gif) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultCachedPhoto added in v2.1.0

type InlineQueryResultCachedPhoto struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	PhotoFileID         string              `json:"photo_file_id"`
	Title               string              `json:"title,omitempty"`
	Description         string              `json:"description,omitempty"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultCachedPhoto represents a link to a photo stored on the Telegram servers. By default, this photo will be sent by the user with an optional caption. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the photo.

func (InlineQueryResultCachedPhoto) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultCachedPhoto) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultCachedSticker added in v2.1.0

type InlineQueryResultCachedSticker struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	StickerFileID       string              `json:"sticker_file_id"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultCachedSticker represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the sticker.

func (InlineQueryResultCachedSticker) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultCachedSticker) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultCachedVideo added in v2.1.0

type InlineQueryResultCachedVideo struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	VideoFileID         string              `json:"video_file_id"`
	Title               string              `json:"title"`
	Description         string              `json:"description,omitempty"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultCachedVideo represents a link to a video file stored on the Telegram servers. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the video.

func (InlineQueryResultCachedVideo) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultCachedVideo) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultCachedVoice added in v2.1.0

type InlineQueryResultCachedVoice struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	VoiceFileID         string              `json:"voice_file_id"`
	Title               string              `json:"title"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultCachedVoice represents a link to a voice message stored on the Telegram servers. By default, this voice message will be sent by the user. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the voice message.

func (InlineQueryResultCachedVoice) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultCachedVoice) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultContact added in v2.1.0

type InlineQueryResultContact struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	PhoneNumber         string              `json:"phone_number"`
	FirstName           string              `json:"first_name"`
	LastName            string              `json:"last_name,omitempty"`
	Vcard               string              `json:"vcard,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	ThumbURL            string              `json:"thumb_url,omitempty"`
	ThumbWidth          int                 `json:"thumb_width,omitempty"`
	ThumbHeight         int                 `json:"thumb_height,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultContact represents a contact with a phone number. By default, this contact will be sent by the user. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the contact.

func (InlineQueryResultContact) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultContact) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultDocument added in v2.1.0

type InlineQueryResultDocument struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	Title               string              `json:"title"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	DocumentURL         string              `json:"document_url"`
	MimeType            string              `json:"mime_type"`
	Description         string              `json:"description,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	ThumbURL            string              `json:"thumb_url,omitempty"`
	ThumbWidth          int                 `json:"thumb_width,omitempty"`
	ThumbHeight         int                 `json:"thumb_height,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultDocument represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the file. Currently, only .PDF and .ZIP files can be sent using this method.

func (InlineQueryResultDocument) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultDocument) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultGame added in v2.1.0

type InlineQueryResultGame struct {
	Type          InlineQueryType `json:"type"`
	ID            string          `json:"id"`
	GameShortName string          `json:"game_short_name"`
	ReplyMarkup   *InlineKeyboard `json:"reply_markup,omitempty"`
}

InlineQueryResultGame represents a Game.

func (InlineQueryResultGame) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultGame) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultGif added in v2.1.0

type InlineQueryResultGif struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	GifURL              string              `json:"gif_url"`
	GifWidth            int                 `json:"gif_width,omitempty"`
	GifHeight           int                 `json:"gif_height,omitempty"`
	GifDuration         int                 `json:"gif_duration,omitempty"`
	ThumbURL            string              `json:"thumb_url"`
	ThumbMimeType       string              `json:"thumb_mime_type,omitempty"`
	Title               string              `json:"title,omitempty"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultGif represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the animation.

func (InlineQueryResultGif) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultGif) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultLocation added in v2.1.0

type InlineQueryResultLocation struct {
	Type                 InlineQueryType     `json:"type"`
	ID                   string              `json:"id"`
	Latitude             float64             `json:"latitude"`
	Longitude            float64             `json:"longitude"`
	Title                string              `json:"title"`
	HorizontalAccuracy   float64             `json:"horizontal_accuracy,omitempty"`
	LivePeriod           int                 `json:"live_period,omitempty"`
	Heading              int                 `json:"heading,omitempty"`
	ProximityAlertRadius int                 `json:"proximity_alert_radius,omitempty"`
	ReplyMarkup          *InlineKeyboard     `json:"reply_markup,omitempty"`
	ThumbURL             string              `json:"thumb_url,omitempty"`
	ThumbWidth           int                 `json:"thumb_width,omitempty"`
	ThumbHeight          int                 `json:"thumb_height,omitempty"`
	InputMessageContent  InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultLocation represents a location on a map. By default, the location will be sent by the user. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the location.

func (InlineQueryResultLocation) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultLocation) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultMpeg4Gif added in v2.1.0

type InlineQueryResultMpeg4Gif struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	Mpeg4URL            string              `json:"mpeg4_url"`
	Mpeg4Width          int                 `json:"mpeg4_width,omitempty"`
	Mpeg4Height         int                 `json:"mpeg4_height,omitempty"`
	Mpeg4Duration       int                 `json:"mpeg4_duration,omitempty"`
	ThumbURL            string              `json:"thumb_url"`
	ThumbMimeType       string              `json:"thumb_mime_type,omitempty"`
	Title               string              `json:"title,omitempty"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultMpeg4Gif represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the animation.

func (InlineQueryResultMpeg4Gif) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultMpeg4Gif) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultPhoto added in v2.1.0

type InlineQueryResultPhoto struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	PhotoURL            string              `json:"photo_url"`
	ThumbURL            string              `json:"thumb_url"`
	PhotoWidth          int                 `json:"photo_width,omitempty"`
	PhotoHeight         int                 `json:"photo_height,omitempty"`
	Title               string              `json:"title,omitempty"`
	Description         string              `json:"description,omitempty"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultPhoto represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the photo.

func (InlineQueryResultPhoto) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultPhoto) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultVenue added in v2.1.0

type InlineQueryResultVenue struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	Latitude            float64             `json:"latitude"`
	Longitude           float64             `json:"longitude"`
	Title               string              `json:"title"`
	Address             string              `json:"address"`
	FoursquareID        string              `json:"foursquare_id,omitempty"`
	FoursquareType      string              `json:"foursquare_type,omitempty"`
	GooglePlaceID       string              `json:"google_place_id,omitempty"`
	GooglePlaceType     string              `json:"google_place_type,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	ThumbURL            string              `json:"thumb_url,omitempty"`
	ThumbWidth          int                 `json:"thumb_width,omitempty"`
	ThumbHeight         int                 `json:"thumb_height,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultVenue represents a venue. By default, the venue will be sent by the user. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the venue.

func (InlineQueryResultVenue) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultVenue) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultVideo added in v2.1.0

type InlineQueryResultVideo struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	VideoURL            string              `json:"video_url"`
	MimeType            string              `json:"mime_type"`
	ThumbURL            string              `json:"thumb_url"`
	Title               string              `json:"title"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	VideoWidth          int                 `json:"video_width,omitempty"`
	VideoHeight         int                 `json:"video_height,omitempty"`
	VideoDuration       int                 `json:"video_duration,omitempty"`
	Description         string              `json:"description,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultVideo represents a link to a page containing an embedded video player or a video file. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the video.

func (InlineQueryResultVideo) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultVideo) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryResultVoice added in v2.1.0

type InlineQueryResultVoice struct {
	Type                InlineQueryType     `json:"type"`
	ID                  string              `json:"id"`
	VoiceURL            string              `json:"voice_url"`
	Title               string              `json:"title"`
	Caption             string              `json:"caption,omitempty"`
	ParseMode           string              `json:"parse_mode,omitempty"`
	CaptionEntities     []*MessageEntity    `json:"caption_entities,omitempty"`
	VoiceDuration       int                 `json:"voice_duration,omitempty"`
	ReplyMarkup         *InlineKeyboard     `json:"reply_markup,omitempty"`
	InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}

InlineQueryResultVoice represents a link to a voice recording in an .OGG container encoded with OPUS. By default, this voice recording will be sent by the user. Alternatively, you can use InputMessageContent to send a message with the specified content instead of the the voice message.

func (InlineQueryResultVoice) ImplementsInlineQueryResult added in v2.1.0

func (i InlineQueryResultVoice) ImplementsInlineQueryResult()

ImplementsInlineQueryResult is used to implement the InlineQueryResult interface.

type InlineQueryType added in v2.1.0

type InlineQueryType string

InlineQueryType is a custom type for the various InlineQueryResult*'s Type field.

type InputContactMessageContent added in v2.1.0

type InputContactMessageContent struct {
	PhoneNumber string `json:"phone_number"`
	FirstName   string `json:"first_name"`
	LastName    string `json:"last_name,omitempty"`
	Vcard       string `json:"vcard,omitempty"`
}

InputContactMessageContent represents the content of a contact message to be sent as the result of an inline query.

func (InputContactMessageContent) ImplementsInputMessageContent added in v2.1.0

func (i InputContactMessageContent) ImplementsInputMessageContent()

ImplementsInputMessageContent is used to implement the InputMessageContent interface.

type InputLocationMessageContent added in v2.1.0

type InputLocationMessageContent struct {
	Latitude             float64 `json:"latitude"`
	Longitude            float64 `json:"longitude"`
	HorizontalAccuracy   float64 `json:"horizontal_accuracy,omitempty"`
	LivePeriod           int     `json:"live_period,omitempty"`
	Heading              int     `json:"heading,omitempty"`
	ProximityAlertRadius int     `json:"proximity_alert_radius,omitempty"`
}

InputLocationMessageContent represents the content of a location message to be sent as the result of an inline query.

func (InputLocationMessageContent) ImplementsInputMessageContent added in v2.1.0

func (i InputLocationMessageContent) ImplementsInputMessageContent()

ImplementsInputMessageContent is used to implement the InputMessageContent interface.

type InputMessageContent added in v2.1.0

type InputMessageContent interface {
	ImplementsInputMessageContent()
}

InputMessageContent represents an interface that implements all the various Input*MessageContent types.

type InputTextMessageContent added in v2.1.0

type InputTextMessageContent struct {
	MessageText           string           `json:"message_text"`
	ParseMode             string           `json:"parse_mode,omitempty"`
	Entities              []*MessageEntity `json:"entities,omitempty"`
	DisableWebPagePreview bool             `json:"disable_web_page_preview,omitempty"`
}

InputTextMessageContent represents the content of a text message to be sent as the result of an inline query.

func (InputTextMessageContent) ImplementsInputMessageContent added in v2.1.0

func (i InputTextMessageContent) ImplementsInputMessageContent()

ImplementsInputMessageContent is used to implement the InputMessageContent interface.

type InputVenueMessageContent added in v2.1.0

type InputVenueMessageContent struct {
	Latitude        float64 `json:"latitude"`
	Longitude       float64 `json:"longitude"`
	Title           string  `json:"title"`
	Address         string  `json:"address"`
	FoursquareID    string  `json:"foursquare_id,omitempty"`
	FoursquareType  string  `json:"foursquare_type,omitempty"`
	GooglePlaceID   string  `json:"google_place_id,omitempty"`
	GooglePlaceType string  `json:"google_place_type,omitempty"`
}

InputVenueMessageContent represents the content of a venue message to be sent as the result of an inline query.

func (InputVenueMessageContent) ImplementsInputMessageContent added in v2.1.0

func (i InputVenueMessageContent) ImplementsInputMessageContent()

ImplementsInputMessageContent is used to implement the InputMessageContent interface.

type KbdRow

type KbdRow []Button

KbdRow represents a row of buttons in a keyboard.

type Keyboard

type Keyboard struct {
	Keyboard        []KbdRow `json:"keyboard"`
	ResizeKeyboard  bool     `json:"resize_keyboard,omitempty"`
	OneTimeKeyboard bool     `json:"one_time_keyboard,omitempty"`
	Selective       bool     `json:"selective,omitempty"`
}

Keyboard represents a keyboard.

type KeyboardRemove

type KeyboardRemove struct {
	RemoveKeyboard bool `json:"remove_keyboard"`
	Selective      bool `json:"selective,omitempty"`
}

KeyboardRemove represents a keyboard removal request.

type Location

type Location struct {
	Longitude            float64 `json:"longitude"`
	Latitude             float64 `json:"latitude"`
	HorizontalAccuracy   float64 `json:"horizontal_accuracy,omitempty"`
	LivePeriod           int     `json:"live_period,omitempty"`
	Heading              int     `json:"heading,omitempty"`
	ProximityAlertRadius int     `json:"proximity_alert_radius,omitempty"`
}

Location represents a point on the map.

type MaskPosition

type MaskPosition struct {
	Point  string  `json:"point"`
	XShift float32 `json:"x_shift"`
	YShift float32 `json:"y_shift"`
	Scale  float32 `json:"scale"`
}

MaskPosition describes the position on faces where a mask should be placed by default.

type Message

type Message struct {
	ID                            int                            `json:"message_id"`
	User                          *User                          `json:"from,omitempty"`
	SenderChat                    *Chat                          `json:"sender_chat,omitempty"`
	Date                          int                            `json:"date"`
	Chat                          *Chat                          `json:"chat"`
	ForwardFrom                   *User                          `json:"forward_from,omitempty"`
	ForwardFromChat               *Chat                          `json:"forward_from_chat,omitempty"`
	ForwardFromMessageID          int                            `json:"forward_from_message_id,omitempty"`
	ForwardSignature              string                         `json:"forward_signature,omitempty"`
	ForwardSenderName             string                         `json:"forward_sender_name,omitempty"`
	ForwardDate                   int                            `json:"forward_date,omitempty"`
	ReplyToMessage                *Message                       `json:"reply_to_message,omitempty"`
	ViaBot                        *User                          `json:"via_bot,omitempty"`
	EditDate                      int                            `json:"edit_date,omitempty"`
	MediaGroupID                  string                         `json:"media_group_id,omitempty"`
	AuthorSignature               string                         `json:"author_signature,omitempty"`
	Text                          string                         `json:"text,omitempty"`
	Entities                      []*MessageEntity               `json:"entities,omitempty"`
	Animation                     *Animation                     `json:"animation,omitempty"`
	Audio                         *Audio                         `json:"audio,omitempty"`
	Document                      *Document                      `json:"document,omitempty"`
	Photo                         []*PhotoSize                   `json:"photo,omitempty"`
	Sticker                       *Sticker                       `json:"sticker,omitempty"`
	Video                         *Video                         `json:"video,omitempty"`
	VideoNote                     *VideoNote                     `json:"video_note,omitempty"`
	Voice                         *Voice                         `json:"voice,omitempty"`
	Caption                       string                         `json:"caption,omitempty"`
	CaptionEntities               []*MessageEntity               `json:"caption_entities,omitempty"`
	Contact                       *Contact                       `json:"contact,omitempty"`
	Dice                          *Dice                          `json:"dice,omitempty"`
	Game                          *Game                          `json:"game,omitempty"`
	Poll                          *Poll                          `json:"poll,omitempty"`
	Venue                         *Venue                         `json:"venue,omitempty"`
	Location                      *Location                      `json:"location,omitempty"`
	NewChatMembers                []*User                        `json:"new_chat_members,omitempty"`
	LeftChatMember                *User                          `json:"left_chat_member,omitempty"`
	NewChatTitle                  string                         `json:"new_chat_title,omitempty"`
	NewChatPhoto                  []*PhotoSize                   `json:"new_chat_photo,omitempty"`
	DeleteChatPhoto               bool                           `json:"delete_chat_photo,omitempty"`
	GroupChatCreated              bool                           `json:"group_chat_created,omitempty"`
	SupergroupChatCreated         bool                           `json:"supergroup_chat_created,omitempty"`
	ChannelChatCreated            bool                           `json:"channel_chat_created,omitempty"`
	MessageAutoDeleteTimerChanged *MessageAutoDeleteTimerChanged `json:"message_auto_delete_timer_changed,omitempty"`
	MigrateToChatID               int                            `json:"migrate_to_chat_id,omitempty"`
	MigrateFromChatID             int                            `json:"migrate_from_chat_id,omitempty"`
	PinnedMessage                 *Message                       `json:"pinned_message,omitempty"`
	ConnectedWebsite              string                         `json:"connected_website,omitempty"`
	ProximityAlertTriggered       *ProximityAlertTriggered       `json:"proximity_alert_triggered,omitempty"`
	VoiceChatStarted              *VoiceChatStarted              `json:"voice_chat_started,omitempty"`
	VoiceChatEnded                *VoiceChatEnded                `json:"voice_chat_ended,omitempty"`
	VoiceChatParticipantsInvited  *VoiceChatParticipantsInvited  `json:"voice_chat_participants_invited,omitempty"`
	ReplyMarkup                   *InlineKeyboard                `json:"reply_markup,omitempty"`
}

Message represents a message.

type MessageAutoDeleteTimerChanged added in v2.2.5

type MessageAutoDeleteTimerChanged struct {
	MessageAutoDeleteTime int `json:"message_auto_delete_time"`
}

MessageAutoDeleteTimerChanged represents a service message about a change in auto-delete timer settings.

type MessageEntity

type MessageEntity struct {
	Type   string `json:"type"`
	Offset int    `json:"offset"`
	Length int    `json:"Length"`
	URL    string `json:"url,omitempty"`
	User   *User  `json:"user,omitempty"`
}

MessageEntity represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.

type NewBotFn

type NewBotFn func(chatId int64) Bot

NewBotFn is called every time echotron receives an update with a chat ID never encountered before.

type Option

type Option string

Option is a custom type for the various frequent options used by some methods of the API.

type PhotoSize

type PhotoSize struct {
	FileID   string `json:"file_id"`
	FileUID  string `json:"file_unique_id"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
	FileSize int    `json:"file_size,omitempty"`
}

PhotoSize represents one size of a photo or a file / sticker thumbnail.

type Poll added in v2.2.2

type Poll struct {
	ID                    string           `json:"id"`
	Question              string           `json:"question"`
	Options               []*PollOption    `json:"options"`
	TotalVoterCount       int              `json:"total_voter_count"`
	IsClosed              bool             `json:"is_closed"`
	IsAnonymous           bool             `json:"is_anonymous"`
	Type                  string           `json:"type"`
	AllowsMultipleAnswers bool             `json:"allows_multiple_answers"`
	CorrectOptionID       int              `json:"correct_option_id,omitempty"`
	Explanation           string           `json:"explanation,omitempty"`
	ExplanationEntities   []*MessageEntity `json:"explanation_entities,omitempty"`
	OpenPeriod            int              `json:"open_period,omitempty"`
	CloseDate             int              `json:"close_date,omitempty"`
}

Poll contains information about a poll.

type PollAnswer added in v2.2.2

type PollAnswer struct {
	PollID    string `json:"poll_id"`
	User      *User  `json:"user"`
	OptionIDs []int  `json:"option_ids"`
}

PollAnswer represents an answer of a user in a non-anonymous poll.

type PollOption added in v2.2.2

type PollOption struct {
	Text       string `json:"text"`
	VoterCount int    `json:"voter_count"`
}

PollOption contains information about one answer option in a poll.

type ProximityAlertTriggered added in v2.2.5

type ProximityAlertTriggered struct {
	Traveler *User `json:"traveler"`
	Watcher  *User `json:"watcher"`
	Distance int   `json:"distance"`
}

ProximityAlertTriggered represents the content of a service message, sent whenever a user in the chat triggers a proximity alert set by another user.

type Sticker

type Sticker struct {
	FileID       string       `json:"file_id"`
	FileUID      string       `json:"file_unique_id"`
	Width        int          `json:"width"`
	Height       int          `json:"height"`
	IsAnimated   bool         `json:"is_animated"`
	Thumb        *PhotoSize   `json:"thumb,omitempty"`
	Emoji        string       `json:"emoji,omitempty"`
	SetName      string       `json:"set_name,omitempty"`
	MaskPosition MaskPosition `json:"mask_position"`
	FileSize     int          `json:"file_size,omitempty"`
}

Sticker represents a sticker.

type StickerSet

type StickerSet struct {
	Name          string     `json:"name"`
	Title         string     `json:"title"`
	IsAnimated    bool       `json:"is_animated"`
	ContainsMasks bool       `json:"contains_masks"`
	Stickers      []*Sticker `json:"sticker"`
	Thumb         *PhotoSize `json:"thumb,omitempty"`
}

StickerSet represents a sticker set.

type Update

type Update struct {
	ID                 int                 `json:"update_id"`
	Message            *Message            `json:"message,omitempty"`
	EditedMessage      *Message            `json:"edited_message,omitempty"`
	ChannelPost        *Message            `json:"channel_post,omitempty"`
	EditedChannelPost  *Message            `json:"edited_channel_post,omitempty"`
	InlineQuery        *InlineQuery        `json:"inline_query,omitempty"`
	ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"`
	CallbackQuery      *CallbackQuery      `json:"callback_query,omitempty"`
}

Update represents an incoming update. At most one of the optional parameters can be present in any given update.

type User

type User struct {
	ID           int64  `json:"id"`
	IsBot        bool   `json:"is_bot"`
	FirstName    string `json:"first_name"`
	LastName     string `json:"last_name,omitempty"`
	Username     string `json:"username,omitempty"`
	LanguageCode string `json:"language_code,omitempty"`
}

User represents a Telegram user or bot.

type Venue added in v2.2.1

type Venue struct {
	Location        *Location `json:"location"`
	Title           string    `json:"title"`
	Address         string    `json:"address"`
	FoursquareID    string    `json:"foursquare_id,omitempty"`
	FoursquareType  string    `json:"foursquare_type,omitempty"`
	GooglePlaceID   string    `json:"google_place_id,omitempty"`
	GooglePlaceType string    `json:"google_place_type,omitempty"`
}

Venue represents a venue.

type Video

type Video struct {
	FileID   string     `json:"file_id"`
	FileUID  string     `json:"file_unique_id"`
	Width    int        `json:"width"`
	Height   int        `json:"height"`
	Duration int        `json:"duration"`
	Thumb    *PhotoSize `json:"thumb,omitempty"`
	FileName string     `json:"file_name,omitempty"`
	MimeType string     `json:"mime_type,omitempty"`
	FileSize int        `json:"file_size,omitempty"`
}

Video represents a video file.

type VideoNote

type VideoNote struct {
	FileID   string     `json:"file_id"`
	FileUID  string     `json:"file_unique_id"`
	Length   int        `json:"length"`
	Duration int        `json:"duration"`
	Thumb    *PhotoSize `json:"thumb,omitempty"`
	FileSize int        `json:"file_size,omitempty"`
}

VideoNote represents a video message (available in Telegram apps as of v.4.0).

type Voice

type Voice struct {
	FileID   string `json:"file_id"`
	FileUID  string `json:"file_unique_id"`
	Duration int    `json:"duration"`
	MimeType string `json:"mime_type,omitempty"`
	FileSize int    `json:"file_size,omitempty"`
}

Voice represents a voice note.

type VoiceChatEnded added in v2.2.5

type VoiceChatEnded struct {
	Duration int `json:"duration"`
}

VoiceChatEnded represents a service message about a voice chat ended in the chat.

type VoiceChatParticipantsInvited added in v2.2.5

type VoiceChatParticipantsInvited struct {
	Users []*User `json:"users,omitempty"`
}

VoiceChatParticipantsInvited represents a service message about new members invited to a voice chat.

type VoiceChatStarted added in v2.2.5

type VoiceChatStarted struct{}

VoiceChatStarted represents a service message about a voice chat started in the chat.

Jump to

Keyboard shortcuts

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