telebot/telebot.go

226 lines
5.8 KiB
Go
Raw Normal View History

2017-11-21 02:49:37 +00:00
// Package telebot is a framework for Telegram bots.
//
2017-11-21 02:49:37 +00:00
// Example:
//
2018-10-26 21:39:47 +00:00
// package main
//
2017-11-21 02:49:37 +00:00
// import (
// "time"
// tb "gopkg.in/tucnak/telebot.v2"
// )
//
2017-11-21 02:49:37 +00:00
// func main() {
2020-07-25 21:01:39 +00:00
// b, err := tele.NewBot(tele.Settings{
2017-11-21 02:49:37 +00:00
// Token: "TOKEN_HERE",
2020-07-25 21:01:39 +00:00
// Poller: &tele.LongPoller{Timeout: 10 * time.Second},
2017-11-21 02:49:37 +00:00
// })
//
2017-11-21 02:49:37 +00:00
// if err != nil {
// return
// }
//
2020-07-25 21:01:39 +00:00
// b.Handle(tele.OnText, func(m *tele.Message) {
// b.Send(m.Sender, "hello world")
2018-10-26 21:39:47 +00:00
// })
2017-11-21 02:49:37 +00:00
//
// b.Start()
// }
//
2015-06-25 19:32:41 +00:00
package telebot
2015-07-06 16:13:08 +00:00
import "github.com/pkg/errors"
var (
ErrSkip = errors.New("telebot: skip")
ErrBadRecipient = errors.New("telebot: recipient is nil")
ErrUnsupportedWhat = errors.New("telebot: unsupported what argument")
ErrCouldNotUpdate = errors.New("telebot: could not fetch new updates")
2020-05-31 16:11:42 +00:00
ErrTrueResult = errors.New("telebot: result is True")
2020-06-19 19:48:05 +00:00
ErrBadContext = errors.New("telebot: context does not contain message")
)
2020-04-25 14:27:17 +00:00
const DefaultApiURL = "https://api.telegram.org"
2017-11-21 02:22:45 +00:00
// These are one of the possible events Handle() can deal with.
//
// For convenience, all Telebot-provided endpoints start with
// an "alert" character \a.
//
const (
// Basic message handlers.
2017-11-23 02:13:15 +00:00
//
// Handler: func(*Message)
OnText = "\atext"
OnPhoto = "\aphoto"
OnAudio = "\aaudio"
2020-04-29 13:02:52 +00:00
OnAnimation = "\aanimation"
OnDocument = "\adocument"
OnSticker = "\asticker"
OnVideo = "\avideo"
OnVoice = "\avoice"
OnVideoNote = "\avideo_note"
OnContact = "\acontact"
OnLocation = "\alocation"
OnVenue = "\avenue"
OnEdited = "\aedited"
OnPinned = "\apinned"
2017-11-21 02:22:45 +00:00
OnChannelPost = "\achan_post"
OnEditedChannelPost = "\achan_edited_post"
2020-04-25 12:31:16 +00:00
OnDice = "\adice"
OnInvoice = "\ainvoice"
OnPayment = "\apayment"
2020-04-26 17:43:17 +00:00
// Will fire when bot is added to a group.
OnAddedToGroup = "\aadded_to_group"
2020-04-26 17:43:17 +00:00
// Group events:
OnUserJoined = "\auser_joined"
OnUserLeft = "\auser_left"
OnNewGroupTitle = "\anew_chat_title"
OnNewGroupPhoto = "\anew_chat_photo"
OnGroupPhotoDeleted = "\achat_photo_del"
// Migration happens when group switches to
2020-06-09 20:28:28 +00:00
// a supergroup. You might want to update
// your internal references to this chat
// upon switching as its ID will change.
//
// Handler: func(from, to int64)
OnMigration = "\amigration"
2017-11-23 02:13:15 +00:00
// Will fire on callback requests.
//
// Handler: func(*Callback)
OnCallback = "\acallback"
// Will fire on incoming inline queries.
//
// Handler: func(*Query)
OnQuery = "\aquery"
2017-12-26 01:07:36 +00:00
// Will fire on chosen inline results.
//
// Handler: func(*ChosenInlineResult)
OnChosenInlineResult = "\achosen_inline_result"
2019-01-28 00:11:10 +00:00
2020-05-20 20:40:42 +00:00
// Will fire on ShippingQuery.
//
// Handler: func(*ShippingQuery)
OnShipping = "\ashipping_query"
2019-01-28 00:11:10 +00:00
// Will fire on PreCheckoutQuery.
//
// Handler: func(*PreCheckoutQuery)
OnCheckout = "\apre_checkout_query"
2020-03-30 16:21:06 +00:00
// Will fire on Poll.
//
// Handler: func(*Poll)
OnPoll = "\apoll"
// Will fire on PollAnswer.
//
// Handler: func(*PollAnswer)
OnPollAnswer = "\apoll_answer"
)
// ChatAction is a client-side status indicating bot activity.
type ChatAction string
const (
Typing ChatAction = "typing"
UploadingPhoto ChatAction = "upload_photo"
UploadingVideo ChatAction = "upload_video"
UploadingAudio ChatAction = "upload_audio"
UploadingDocument ChatAction = "upload_document"
2017-11-18 10:19:58 +00:00
UploadingVNote ChatAction = "upload_video_note"
RecordingVideo ChatAction = "record_video"
RecordingAudio ChatAction = "record_audio"
2020-04-05 16:31:19 +00:00
RecordingVNote ChatAction = "record_video_note"
FindingLocation ChatAction = "find_location"
)
// ParseMode determines the way client applications treat the text of the message
2019-10-28 19:22:30 +00:00
type ParseMode = string
const (
2020-04-05 16:31:19 +00:00
ModeDefault ParseMode = ""
ModeMarkdown ParseMode = "Markdown"
ModeMarkdownV2 ParseMode = "MarkdownV2"
ModeHTML ParseMode = "HTML"
)
// EntityType is a MessageEntity type.
type EntityType string
const (
2020-04-05 16:31:19 +00:00
EntityMention EntityType = "mention"
EntityTMention EntityType = "text_mention"
EntityHashtag EntityType = "hashtag"
EntityCashtag EntityType = "cashtag"
EntityCommand EntityType = "bot_command"
EntityURL EntityType = "url"
EntityEmail EntityType = "email"
EntityPhone EntityType = "phone_number"
EntityBold EntityType = "bold"
EntityItalic EntityType = "italic"
EntityUnderline EntityType = "underline"
EntityStrikethrough EntityType = "strikethrough"
EntityCode EntityType = "code"
EntityCodeBlock EntityType = "pre"
EntityTextLink EntityType = "text_link"
)
// ChatType represents one of the possible chat types.
type ChatType string
2015-07-06 16:13:08 +00:00
const (
ChatPrivate ChatType = "private"
ChatGroup ChatType = "group"
ChatSuperGroup ChatType = "supergroup"
ChatChannel ChatType = "channel"
ChatChannelPrivate ChatType = "privatechannel"
2015-07-06 16:13:08 +00:00
)
2017-11-18 10:19:58 +00:00
2020-04-05 16:31:19 +00:00
// MemberStatus is one's chat status.
2017-11-18 10:19:58 +00:00
type MemberStatus string
const (
Creator MemberStatus = "creator"
Administrator MemberStatus = "administrator"
Member MemberStatus = "member"
Restricted MemberStatus = "restricted"
Left MemberStatus = "left"
Kicked MemberStatus = "kicked"
)
2017-11-18 14:41:23 +00:00
// MaskFeature defines sticker mask position.
type MaskFeature string
const (
FeatureForehead MaskFeature = "forehead"
FeatureEyes MaskFeature = "eyes"
FeatureMouth MaskFeature = "mouth"
FeatureChin MaskFeature = "chin"
)
2018-12-12 22:45:03 +00:00
2020-04-05 16:31:19 +00:00
// PollType defines poll types.
2020-04-24 14:52:15 +00:00
type PollType string
2020-04-05 16:31:19 +00:00
const (
2020-04-24 14:52:15 +00:00
// Despite "any" type isn't described in documentation,
// it needed for proper KeyboardButtonPollType marshaling.
PollAny PollType = "any"
2020-04-05 16:31:19 +00:00
PollQuiz PollType = "quiz"
PollRegular PollType = "regular"
)
2020-04-25 12:59:53 +00:00
type DiceType string
var (
Cube = &Dice{Type: "🎲"}
Dart = &Dice{Type: "🎯"}
2020-06-07 18:46:03 +00:00
Ball = &Dice{Type: "🏀"}
2020-04-25 12:59:53 +00:00
)