facebot

package module
v0.1.0 Latest Latest
Warning

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

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

README

FB Bot

Documentation

Index

Constants

View Source
const (
	OnText    = "\atext"
	OnContact = "\acontact"
	OnVoice   = "\avoice"
	OnAudio   = "\aaudio"
)

Variables

This section is empty.

Functions

func ButtonHandler added in v0.1.0

func ButtonHandler(bot *Bot, recipient FBChat, payload string)

func TextHandler

func TextHandler(bot *Bot, recipient FBChat, text string)

func WebhookListen

func WebhookListen(bot *Bot) fasthttp.RequestHandler

func WebhookVerify

func WebhookVerify(bot *Bot) fasthttp.RequestHandler

Types

type Album added in v0.0.5

type Album []InputMedia

Album lets you group multiple media (so-called InputMedia) into a single message.

On older clients albums look like N regular messages.

type Animation added in v0.0.5

type Animation struct {
	File

	Width    int `json:"width"`
	Height   int `json:"height"`
	Duration int `json:"duration,omitempty"`

	// (Optional)
	Caption   string `json:"caption,omitempty"`
	Thumbnail *Photo `json:"thumb,omitempty"`
	MIME      string `json:"mime_type,omitempty"`
	FileName  string `json:"file_name,omitempty"`
}

Animation object represents a animation file.

func (*Animation) MediaFile added in v0.0.5

func (a *Animation) MediaFile() *File

MediaFile returns &Animation.File

type Attachment

type Attachment struct {
	Type    string   `json:"type"`
	Payload *Payload `json:"payload"`
}

type Audio added in v0.0.5

type Audio struct {
	File

	// Duration of the recording in seconds as defined by sender.
	Duration int `json:"duration,omitempty"`

	// (Optional)
	Caption   string `json:"caption,omitempty"`
	Thumbnail *Photo `json:"thumb,omitempty"`
	Title     string `json:"title,omitempty"`
	Performer string `json:"performer,omitempty"`
	MIME      string `json:"mime_type,omitempty"`
	FileName  string `json:"file_name,omitempty"`
}

Audio object represents an audio file.

func (*Audio) MediaFile added in v0.0.5

func (a *Audio) MediaFile() *File

MediaFile returns &Audio.File

type Bot

type Bot struct {
	PageAccessToken string
	VerifyToken     string
	PageID          string
	// contains filtered or unexported fields
}

func NewBot

func NewBot(settings Settings) (*Bot, error)

func (*Bot) ChatByID added in v0.0.5

func (b *Bot) ChatByID(id string) (*Chat, error)

func (*Bot) GetFile added in v0.0.6

func (b *Bot) GetFile(file *File) (io.ReadCloser, error)

func (*Bot) Handle

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

func (*Bot) Send

func (b *Bot) Send(chat *Chat, what interface{}, options ...interface{}) (*Message, error)

func (*Bot) SendAlbum added in v0.0.5

func (b *Bot) SendAlbum(chat *Chat, album Album, options ...interface{}) ([]Message, error)

func (*Bot) Start

func (b *Bot) Start()

type Btn added in v0.0.5

type Btn struct {
	Unique   string
	Text     string
	URL      string
	Data     string
	Contact  bool
	Location bool
}

func (*Btn) CallbackUnique added in v0.0.5

func (b *Btn) CallbackUnique() string

func (Btn) Inline added in v0.0.6

func (b Btn) Inline() *InlineButton

func (Btn) Reply added in v0.0.5

func (b Btn) Reply() *ReplyButton

type Button

type Button struct {
	Type    string `json:"type,omitempty"`
	URL     string `json:"url,omitempty"`
	Title   string `json:"title,omitempty"`
	Payload string `json:"payload,omitempty"`
}

type Chat

type Chat struct {
	ID int64 `json:"id"`

	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Username  string `json:"username"`
}

type Contact added in v0.0.5

type Contact struct {
	PhoneNumber string `json:"phone_number"`
	FirstName   string `json:"first_name"`

	// (Optional)
	LastName string `json:"last_name"`
	UserID   int    `json:"user_id,omitempty"`
}

Contact object represents a contact to Telegram user

type Document added in v0.0.5

type Document struct {
	File

	// (Optional)
	Thumbnail *Photo `json:"thumb,omitempty"`
	Caption   string `json:"caption,omitempty"`
	MIME      string `json:"mime_type"`
	FileName  string `json:"file_name,omitempty"`
}

Document object represents a general file (as opposed to Photo or Audio). Telegram users can send files of any type of up to 1.5 GB in size.

func (*Document) MediaFile added in v0.0.5

func (d *Document) MediaFile() *File

MediaFile returns &Document.File

type Element

type Element struct {
	Title    string   `json:"title,omitempty"`
	Subtitle string   `json:"subtitle,omitempty"`
	ItemURL  string   `json:"item_url,omitempty"`
	ImageURL string   `json:"image_url,omitempty"`
	Buttons  []Button `json:"buttons,omitempty"`
}

type Entry

type Entry struct {
	ID        string      `json:"id"`
	Time      int         `json:"time"`
	Messaging []Messaging `json:"messaging"`
}

type FBChat added in v0.0.3

type FBChat struct {
	ID string `json:"id"`
}

type File added in v0.0.5

type File struct {
	FileID   string `json:"file_id"`
	UniqueID string `json:"file_unique_id"`
	FileSize int    `json:"file_size"`

	// file on telegram server https://core.telegram.org/bots/api#file
	FilePath string `json:"file_path"`

	// file on local file system.
	FileLocal string `json:"file_local"`

	// file on the internet
	FileURL string `json:"file_url"`

	// file backed with io.Reader
	FileReader io.Reader `json:"-"`
	// contains filtered or unexported fields
}

File object represents any sort of file.

func FromReader added in v0.0.6

func FromReader(reader io.Reader) File

type InlineButton added in v0.0.6

type InlineButton struct {
	// Unique slagish name for this kind of button,
	// try to be as specific as possible.
	//
	// It will be used as a callback endpoint.
	Unique string `json:"unique,omitempty"`

	Text string `json:"text"`
	URL  string `json:"url,omitempty"`
	Data string `json:"callback_data,omitempty"`
}

InlineButton represents a button displayed in the message.

type InputMedia added in v0.0.5

type InputMedia interface {
	// MediaFile As some files must be uploaded (instead of referencing)
	// outer layers of Telebot require it.
	MediaFile() *File
}

InputMedia is a generic type for all kinds of media you can put into an album.

type Location added in v0.0.5

type Location struct {
	// Latitude
	Lat float32 `json:"latitude"`
	// Longitude
	Lng float32 `json:"longitude"`

	// Horizontal Accuracy
	HorizontalAccuracy *float32 `json:"horizontal_accuracy,omitempty"`

	// Period in seconds for which the location will be updated
	// (see Live Locations, should be between 60 and 86400.)
	LivePeriod int `json:"live_period,omitempty"`

	Heading int `json:"heading,omitempty"`

	ProximityAlertRadius int `json:"proximity_alert_radius,omitempty"`
}

Location object represents geographic position.

type Message

type Message struct {
	Chat *Chat  `json:"chat"`
	Text string `json:"text"`

	Contact *Contact `json:"contact"`
	Voice   *Voice   `json:"voice"`
}

type Messaging

type Messaging struct {
	Sender    FBChat       `json:"sender"`
	Recipient FBChat       `json:"recipient"`
	Timestamp int          `json:"timestamp"`
	Message   *SendMessage `json:"message"`
	Read      *Read        `json:"read"`
	Postback  *Postback    `json:"postback"`
}

type ParseMode added in v0.0.5

type ParseMode = string
const (
	ModeDefault    ParseMode = ""
	ModeMarkdown   ParseMode = "Markdown"
	ModeMarkdownV2 ParseMode = "MarkdownV2"
	ModeHTML       ParseMode = "HTML"
)

type Payload

type Payload struct {
	TemplateType string    `json:"template_type,omitempty"`
	Text         string    `json:"text,omitempty"`
	Elements     []Element `json:"elements,omitempty"`
	Buttons      []Button  `json:"buttons,omitempty"`
	URL          string    `json:"url,omitempty"`
}

type Photo added in v0.0.5

type Photo struct {
	File

	Width   int    `json:"width"`
	Height  int    `json:"height"`
	Caption string `json:"caption,omitempty"`
}

Photo object represents a single photo file.

func (*Photo) MediaFile added in v0.0.5

func (p *Photo) MediaFile() *File

MediaFile returns &Photo.File

func (*Photo) UnmarshalJSON added in v0.0.5

func (p *Photo) UnmarshalJSON(jsonStr []byte) error

UnmarshalJSON is custom unmarshaller required to abstract away the hassle of treating different thumbnail sizes. Instead, Telebot chooses the hi-res one and just sticks to it.

I really do find it a beautiful solution.

type Postback added in v0.1.0

type Postback struct {
	Title   string `json:"title"`
	Payload string `json:"payload"`
	MID     string `json:"mid"`
}

type ProximityAlertTriggered added in v0.0.5

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

ProximityAlertTriggered sent whenever a user in the chat triggers a proximity alert set by another user.

type QuickReplies

type QuickReplies struct {
	ContentType string `json:"content_type,omitempty"`
	Text        string `json:"text,omitempty"`
	Payload     string `json:"payload,omitempty"`
	ImageURL    string `json:"image_url,omitempty"`
}

type Read

type Read struct {
	Watermark int `json:"watermark"`
}

type ReplyButton added in v0.0.3

type ReplyButton struct {
	Text     string `json:"text"`
	Contact  bool
	Location bool
}

type ReplyMarkup added in v0.0.3

type ReplyMarkup struct {
	ReplyKeyboard       [][]ReplyButton `json:"keyboard,omitempty"`
	ResizeReplyKeyboard bool            `json:"resize_reply_keyboard"`
	ReplyKeyboardRemove bool            `json:"reply_keyboard_remove"`

	InlineKeyboard [][]InlineButton `json:"inline_keyboard,omitempty"`
}

func (*ReplyMarkup) Contact added in v0.0.5

func (r *ReplyMarkup) Contact(text string) Btn

func (*ReplyMarkup) Data added in v0.0.6

func (r *ReplyMarkup) Data(text, unique string, data ...string) Btn

func (*ReplyMarkup) Inline added in v0.0.6

func (r *ReplyMarkup) Inline(rows ...Row)

func (*ReplyMarkup) Reply added in v0.0.5

func (r *ReplyMarkup) Reply(rows ...Row)

func (*ReplyMarkup) Row added in v0.0.5

func (r *ReplyMarkup) Row(many ...Btn) Row

func (*ReplyMarkup) Text added in v0.0.5

func (r *ReplyMarkup) Text(text string) Btn

type Row added in v0.0.5

type Row []Btn

type SendMessage added in v0.0.3

type SendMessage struct {
	MID  string `json:"mid"`
	Text string `json:"text"`
}

type SendOptions added in v0.0.3

type SendOptions struct {
	ReplyMarkup         *ReplyMarkup
	ParseMode           interface{}
	DisableNotification interface{}
}

type Settings

type Settings struct {
	PageAccessToken string
	VerifyToken     string
	PageID          string
}

type TextMessage

type TextMessage struct {
	Text         *string       `json:"text,omitempty"`
	Attachment   *Attachment   `json:"attachment,omitempty"`
	QuickReplies *QuickReplies `json:"quick_replies,omitempty"`
}

type TextResponse

type TextResponse struct {
	Recipient     FBChat      `json:"recipient,omitempty"`
	MessagingType *string     `json:"messaging_type,omitempty"`
	Message       TextMessage `json:"message,omitempty"`
}

type Tick

type Tick struct {
	Object string  `json:"object"`
	Entry  []Entry `json:"entry"`
}

type User added in v0.0.5

type User struct {
	ID int `json:"id"`

	FirstName    string `json:"first_name"`
	LastName     string `json:"last_name"`
	Username     string `json:"username"`
	LanguageCode string `json:"language_code"`
	IsBot        bool   `json:"is_bot"`

	// Returns only in getMe
	CanJoinGroups   bool `json:"can_join_groups"`
	CanReadMessages bool `json:"can_read_all_group_messages"`
	SupportsInline  bool `json:"supports_inline_queries"`
}

User object represents a Telegram user, bot.

type Venue added in v0.0.5

type Venue struct {
	Location Location `json:"location"`
	Title    string   `json:"title"`
	Address  string   `json:"address"`

	// (Optional)
	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 object represents a venue location with name, address and optional foursquare ID.

type Video added in v0.0.5

type Video struct {
	File

	Width  int `json:"width"`
	Height int `json:"height"`

	Duration int `json:"duration,omitempty"`

	// (Optional)
	Caption           string `json:"caption,omitempty"`
	Thumbnail         *Photo `json:"thumb,omitempty"`
	SupportsStreaming bool   `json:"supports_streaming,omitempty"`
	MIME              string `json:"mime_type,omitempty"`
	FileName          string `json:"file_name,omitempty"`
}

Video object represents a video file.

func (*Video) MediaFile added in v0.0.5

func (v *Video) MediaFile() *File

MediaFile returns &Video.File

type VideoNote added in v0.0.5

type VideoNote struct {
	File

	// Duration of the recording in seconds as defined by sender.
	Duration int `json:"duration"`

	// (Optional)
	Thumbnail *Photo `json:"thumb,omitempty"`
	Length    int    `json:"length,omitempty"`
}

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

type Voice added in v0.0.5

type Voice struct {
	File

	// Duration of the recording in seconds as defined by sender.
	Duration int `json:"duration"`

	// (Optional)
	Caption string `json:"caption,omitempty"`
	MIME    string `json:"mime_type,omitempty"`
}

Voice object represents a voice note.

type Webhook

type Webhook struct {
	Port string
}

func (*Webhook) WebhookServer

func (w *Webhook) WebhookServer(bot *Bot)

Jump to

Keyboard shortcuts

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