Documentation
¶
Overview ¶
Package tgbot provides access to the Telegram Bot API.
Example ¶
package main import ( "fmt" "github.com/fdschonborn/tgbot" ) var bot *tgbot.Bot func main() { me, _ := bot.GetMe() fmt.Println(me.IsBot) }
Output: true
Index ¶
- Constants
- Variables
- type Bot
- func (b *Bot) Close() error
- func (b *Bot) CopyMessage(target int64, from int64, messageID int, options *CopyMessageOptions) (*MessageID, error)
- func (b *Bot) ForwardMessage(target int64, from int64, messageID int, options *ForwardMessageOptions) (*Message, error)
- func (b *Bot) GetChat(target int64) (*Chat, error)
- func (b *Bot) GetMe() (*User, error)
- func (b *Bot) GetUpdates(options *GetUpdatesOptions) ([]*Update, error)
- func (b *Bot) LogOut() error
- func (b *Bot) PollUpdates(options *GetUpdatesOptions) UpdateChan
- func (b *Bot) SendChatAction(target int64, action ChatAction) error
- func (b *Bot) SendDice(target int64, options *SendDiceOptions) (*Message, error)
- func (b *Bot) SendMessage(target int64, text string, options *SendMessageOptions) (*Message, error)
- type BotOptions
- type Chat
- type ChatAction
- type ChatLocation
- type ChatPermissions
- type ChatPhoto
- type ChatType
- type CopyMessageOptions
- type Dice
- type DiceEmoji
- type Error
- type ForceReply
- type ForwardMessageOptions
- type GetUpdatesOptions
- type InlineKeyboardButton
- type InlineKeyboardMarkup
- type KeyboardButton
- type KeyboardButtonPollType
- type Location
- type Message
- type MessageEntity
- type MessageEntityType
- type MessageID
- type MessageType
- type ParseMode
- type PhotoSize
- type ReplyKeyboardMarkup
- type ReplyKeyboardRemove
- type ReplyMarkup
- type Response
- type ResponseParameters
- type SendDiceOptions
- type SendMessageOptions
- type Update
- type UpdateChan
- type UpdateType
- type User
Examples ¶
Constants ¶
View Source
const (
DefaultHost = "api.telegram.org"
)
Variables ¶
View Source
var (
DefaultClient = http.DefaultClient
)
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
func (*Bot) CopyMessage ¶
func (*Bot) ForwardMessage ¶
func (*Bot) GetChat ¶
Example ¶
package main import ( "fmt" "github.com/fdschonborn/tgbot" ) var ( bot *tgbot.Bot target int64 ) func main() { chat, _ := bot.GetChat(target) fmt.Println(chat.ID != 0) }
Output: true
func (*Bot) GetUpdates ¶
func (b *Bot) GetUpdates(options *GetUpdatesOptions) ([]*Update, error)
Example ¶
package main import ( "fmt" "github.com/fdschonborn/tgbot" ) var bot *tgbot.Bot func main() { updates, _ := bot.GetUpdates(&tgbot.GetUpdatesOptions{ Limit: 1, }) fmt.Println(updates != nil) }
Output: true
func (*Bot) PollUpdates ¶
func (b *Bot) PollUpdates(options *GetUpdatesOptions) UpdateChan
Example ¶
package main import ( "fmt" "github.com/fdschonborn/tgbot" ) var bot *tgbot.Bot func main() { channel := bot.PollUpdates(nil) for update := range channel { if update == nil { continue } fmt.Println(update.ID) } }
Output:
func (*Bot) SendChatAction ¶
func (b *Bot) SendChatAction(target int64, action ChatAction) error
Example ¶
package main import ( "fmt" "github.com/fdschonborn/tgbot" ) var ( bot *tgbot.Bot target int64 ) func main() { err := bot.SendChatAction(target, tgbot.ChatActionTyping) fmt.Println(err == nil) }
Output: true
func (*Bot) SendDice ¶
func (b *Bot) SendDice(target int64, options *SendDiceOptions) (*Message, error)
Example ¶
package main import ( "fmt" "github.com/fdschonborn/tgbot" ) var ( bot *tgbot.Bot target int64 ) func main() { message, _ := bot.SendDice(target, &tgbot.SendDiceOptions{ DisableNotification: true, }) fmt.Println(message.Dice.Emoji == tgbot.DiceEmojiDefault) }
Output: true
func (*Bot) SendMessage ¶
Example ¶
package main import ( "fmt" "github.com/fdschonborn/tgbot" ) var ( bot *tgbot.Bot target int64 ) func main() { message, _ := bot.SendMessage(target, "Hello!", &tgbot.SendMessageOptions{ DisableNotification: true, }) fmt.Println(message.Text == "Hello!") }
Output: true
Example (WithKeyboard) ¶
package main import ( "fmt" "github.com/fdschonborn/tgbot" ) var ( bot *tgbot.Bot target int64 ) func main() { message, _ := bot.SendMessage(target, "Hello!", &tgbot.SendMessageOptions{ DisableNotification: true, ReplyMarkup: &tgbot.InlineKeyboardMarkup{ InlineKeyboard: [][]*tgbot.InlineKeyboardButton{ { { Text: "One", URL: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", }, { Text: "Dos", URL: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", }, { Text: "Tre", URL: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", }, }, }, }, }) fmt.Println(message.Text == "Hello!") }
Output: true
type BotOptions ¶
type Chat ¶
type Chat struct { ID int64 `json:"id,omitempty"` Type ChatType `json:"type,omitempty"` Title string `json:"title,omitempty"` // Optional Username string `json:"username,omitempty"` // Optional FirstName string `json:"first_name,omitempty"` // Optional LastName string `json:"last_name,omitempty"` // Optional Photo *ChatPhoto `json:"photo,omitempty"` // Optional Bio string `json:"bio,omitempty"` // Optional Description string `json:"description,omitempty"` // Optional InviteLink string `json:"invite_link,omitempty"` // Optional PinnedMessage *Message `json:"pinned_message,omitempty"` // Optional Permissions *ChatPermissions `json:"permissions,omitempty"` // Optional SlowModeDelay int `json:"slow_mode_delay,omitempty"` // Optional MessageAutoDeleteTime int `json:"message_auto_delete_time,omitempty"` // Optional StickerSetName string `json:"sticker_set_name,omitempty"` // Optional CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` // Optional LinkedChatID int64 `json:"linked_chat_id,omitempty"` // Optional Location *ChatLocation `json:"location,omitempty"` // Optional }
type ChatAction ¶
type ChatAction string
const ( ChatActionTyping ChatAction = "typing" ChatActionUploadPhoto ChatAction = "upload_photo" ChatActionRecordVideo ChatAction = "record_video" ChatActionUploadVideo ChatAction = "upload_video" ChatActionRecordVoice ChatAction = "record_voice" ChatActionUploadVoice ChatAction = "upload_voice" ChatActionUploadDocument ChatAction = "upload_document" ChatActionFindLocation ChatAction = "find_location" ChatActionRecordVideoNote ChatAction = "record_video_note" ChatActionUploadVideoNote ChatAction = "upload_video_note" )
type ChatLocation ¶
type ChatPermissions ¶
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"` }
type CopyMessageOptions ¶
type CopyMessageOptions struct { Caption string `json:"caption,omitempty"` ParseMode ParseMode `json:"parse_mode,omitempty"` CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` DisableNotification bool `json:"disable_notification,omitempty"` ReplyToMessageID int `json:"reply_to_message_id,omitempty"` AllowSendingWithoutReply bool `json:"allow_sending_without_reply,omitempty"` ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"` }
type Error ¶
type Error struct { Description string Code int Parameters *ResponseParameters }
type ForceReply ¶
type ForwardMessageOptions ¶
type ForwardMessageOptions struct {
DisableNotification bool `json:"disable_notification,omitempty"`
}
type GetUpdatesOptions ¶
type GetUpdatesOptions struct { Offset int `json:"offset,omitempty"` Limit int `json:"limit,omitempty"` Timeout int `json:"timeout,omitempty"` AllowedUpdates []UpdateType `json:"allowed_updates,omitempty"` }
type InlineKeyboardButton ¶
type InlineKeyboardButton struct { Text string `json:"text"` URL string `json:"url,omitempty"` // Optional CallbackData string `json:"callback_data,omitempty"` // Optional SwitchInlineQuery string `json:"switch_inline_query,omitempty"` // Optional SwitchInlineQueryCurrentChat string `json:"switch_inline_query_current_chat,omitempty"` // Optional Pay bool `json:"pay,omitempty"` // Optional }
type InlineKeyboardMarkup ¶
type InlineKeyboardMarkup struct {
InlineKeyboard [][]*InlineKeyboardButton `json:"inline_keyboard,omitempty"`
}
type KeyboardButton ¶
type KeyboardButton struct { Text string `json:"text,omitempty"` RequestContact bool `json:"request_contact,omitempty"` // Optional RequestLocation bool `json:"request_location,omitempty"` // Optional RequestPoll KeyboardButtonPollType `json:"request_poll,omitempty"` // Optional }
type KeyboardButtonPollType ¶
type KeyboardButtonPollType struct {
Type string `json:"type,omitempty"`
}
type Location ¶
type Location struct { Longitude float64 `json:"longitude,omitempty"` Latitude float64 `json:"latitude,omitempty"` HorizontalAccuracy float64 `json:"horizontal_accuracy,omitempty"` // Optional LivePeriod int `json:"live_period,omitempty"` // Optional Heading int `json:"heading,omitempty"` // Optional ProximityAlertRadius int `json:"proximity_alert_radius,omitempty"` // Optional }
type Message ¶
type Message struct { ID int `json:"message_id,omitempty"` From *User `json:"from,omitempty"` // Optional SenderChat *Chat `json:"sender_chat,omitempty"` // Optional Date int `json:"date,omitempty"` Chat *Chat `json:"chat,omitempty"` ForwardFrom *User `json:"forward_from,omitempty"` // Optional ForwardFromChat *Chat `json:"forward_from_chat,omitempty"` // Optional ForwardFromMesageID int `json:"forward_from_mesage_id,omitempty"` // Optional ForwardSignature string `json:"forward_signature,omitempty"` // Optional ForwardSenderName string `json:"forward_sender_name,omitempty"` // Optional ForwardDate int `json:"forward_date,omitempty"` // Optional ReplyToMessage *Message `json:"reply_to_message,omitempty"` // Optional ViaBot *User `json:"via_bot,omitempty"` // Optional EditDate int `json:"edit_date,omitempty"` // Optional MediaGroupID string `json:"media_group_id,omitempty"` // Optional AuthorSignature string `json:"author_signature,omitempty"` // Optional Text string `json:"text,omitempty"` // Optional Entities []*MessageEntity `json:"entities,omitempty"` // Optional Photo []*PhotoSize `json:"photo,omitempty"` // Optional Caption string `json:"caption,omitempty"` // Optional CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` // Optional Dice *Dice `json:"dice,omitempty"` // Optional Location *Location `json:"location,omitempty"` // Optional NewChatMembers []*User `json:"new_chat_members,omitempty"` // Optional LeftChatMember *User `json:"left_chat_member,omitempty"` // Optional NewChatTitle string `json:"new_chat_title,omitempty"` // Optional NewChatPhoto []*PhotoSize `json:"new_chat_photo,omitempty"` // Optional DeleteChatPhoto bool `json:"delete_chat_photo,omitempty"` // Optional GroupChatCreated bool `json:"group_chat_created,omitempty"` // Optional SupergroupChatCreated bool `json:"supergroup_chat_created,omitempty"` // Optional ChannelChatCreated bool `json:"channel_chat_created,omitempty"` // Optional MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` // Optional MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"` // Optional PinnedMessage *Message `json:"pinned_message,omitempty"` // Optional ConnectedWebsite string `json:"connected_website,omitempty"` // Optional }
func (*Message) CommandArguments ¶
func (*Message) ForwardTime ¶
func (*Message) Type ¶
func (m *Message) Type() MessageType
type MessageEntity ¶
type MessageEntity struct { Type MessageEntityType `json:"type,omitempty"` Offset int `json:"offset,omitempty"` Length int `json:"length,omitempty"` URL *url.URL `json:"url,omitempty"` // Optional User *User `json:"user,omitempty"` // Optional Language string `json:"language,omitempty"` // Optional }
type MessageEntityType ¶
type MessageEntityType string
const ( MessageEntityTypeMention MessageEntityType = "mention" MessageEntityTypeHashtag MessageEntityType = "hashtag" MessageEntityTypeCashtag MessageEntityType = "cashtag" MessageEntityTypeBotCommand MessageEntityType = "bot_command" MessageEntityTypeURL MessageEntityType = "url" MessageEntityTypeEmail MessageEntityType = "email" MessageEntityTypePhoneNumber MessageEntityType = "phone_number" MessageEntityTypeBold MessageEntityType = "bold" MessageEntityTypeItalic MessageEntityType = "italic" MessageEntityTypeUnderline MessageEntityType = "underline" MessageEntityTypeStrikethrough MessageEntityType = "strikethrough" MessageEntityTypeCode MessageEntityType = "code" MessageEntityTypePre MessageEntityType = "pre" MessageEntityTypeTextLink MessageEntityType = "text_link" MessageEntityTypeTextMention MessageEntityType = "text_mention" )
type MessageType ¶
type MessageType string
const ( MessageTypeText MessageType = "text" MessageTypeAnimation MessageType = "animation" MessageTypeAudio MessageType = "audio" MessageTypeDocument MessageType = "document" MessageTypePhoto MessageType = "photo" MessageTypeSticker MessageType = "sticker" MessageTypeVideo MessageType = "video" MessageTypeVideoNote MessageType = "video_note" MessageTypeVoice MessageType = "voice" MessageTypeContact MessageType = "contact" MessageTypeDice MessageType = "dice" MessageTypeGame MessageType = "game" MessageTypePoll MessageType = "poll" MessageTypeVenue MessageType = "venue" MessageTypeLocation MessageType = "location" MessageTypeNewChatMembers MessageType = "new_chat_members" MessageTypeLeftChatMember MessageType = "left_chat_member" MessageTypeNewChatTitle MessageType = "new_chat_title" MessageTypeNewChatPhoto MessageType = "new_chat_photo" MessageTypeDeleteChatPhoto MessageType = "delete_chat_photo" MessageTypeGroupChatCreated MessageType = "group_chat_created" MessageTypeSupergroupChatCreated MessageType = "supergroup_chat_created" MessageTypeChannelChatCreated MessageType = "channel_chat_created" MessageTypeMessageAutoDeleteTimerChanged MessageType = "message_auto_delete_timer_changed" MessageTypeInvoice MessageType = "invoice" MessageTypeSuccessfulPayment MessageType = "successful_payment" MessageTypeProximityAlertTriggered MessageType = "proximity_alert_triggered" MessageTypeVoiceChatScheduled MessageType = "voice_chat_scheduled" MessageTypeVoiceChatStarted MessageType = "voice_chat_started" MessageTypeVoiceChatEnded MessageType = "voice_chat_ended" MessageTypeVoiceChatParticipantsInvited MessageType = "voice_chat_participants_invited" )
type ReplyKeyboardMarkup ¶
type ReplyKeyboardMarkup struct { Keyboard [][]*KeyboardButton `json:"keyboard,omitempty"` ResizeKeyboard bool `json:"resize_keyboard,omitempty"` // Optional OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"` // Optional InputFieldPlaceholder string `json:"input_field_placeholder,omitempty"` // Optional Selective bool `json:"selective,omitempty"` // Optional }
type ReplyKeyboardRemove ¶
type ReplyMarkup ¶
type ReplyMarkup interface {
// contains filtered or unexported methods
}
type Response ¶
type Response struct { Ok bool `json:"ok,omitempty"` Description string `json:"description,omitempty"` // Optional Result json.RawMessage `json:"result,omitempty"` // Optional ErrorCode int `json:"error_code,omitempty"` // Optional Parameters *ResponseParameters `json:"parameters,omitempty"` // Optional }
type ResponseParameters ¶
type SendDiceOptions ¶
type SendDiceOptions struct { Emoji DiceEmoji `json:"emoji,omitempty"` DisableNotification bool `json:"disable_notification,omitempty"` ReplyToMessageID int `json:"reply_to_message_id,omitempty"` AllowSendingWithoutReply bool `json:"allow_sending_without_reply,omitempty"` ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"` }
type SendMessageOptions ¶
type SendMessageOptions struct { ParseMode ParseMode `json:"parse_mode,omitempty"` Entities []*MessageEntity `json:"entities,omitempty"` DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"` DisableNotification bool `json:"disable_notification,omitempty"` ReplyToMessageID int `json:"reply_to_message_id,omitempty"` AllowSendingWithoutReply bool `json:"allow_sending_without_reply,omitempty"` ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"` }
type Update ¶
type Update struct { ID int `json:"update_id,omitempty"` Message *Message `json:"message,omitempty"` // Optional EditedMessage *Message `json:"edited_message,omitempty"` // Optional ChannelPost *Message `json:"channel_post,omitempty"` // Optional EditedChannelPost *Message `json:"edited_channel_post,omitempty"` // Optional }
func (*Update) Type ¶
func (u *Update) Type() UpdateType
type UpdateChan ¶
type UpdateChan <-chan *Update
type UpdateType ¶
type UpdateType string
const ( UpdateTypeMessage UpdateType = "message" UpdateTypeEditedMessage UpdateType = "edited_message" UpdateTypeChannelPost UpdateType = "channel_post" UpdateTypeEditedChannelPost UpdateType = "edited_channel_post" )
type User ¶
type User struct { ID int64 `json:"id,omitempty"` IsBot bool `json:"is_bot,omitempty"` FirstName string `json:"first_name,omitempty"` // Optional LastName string `json:"last_name,omitempty"` // Optional Username string `json:"username,omitempty"` // Optional LanguageCode language.Tag `json:"language_code,omitempty"` // Optional CanJoinGroups bool `json:"can_join_groups,omitempty"` // Optional CanReadAllGroupMessages bool `json:"can_read_all_group_messages,omitempty"` // Optional SupportsInlineQueries bool `json:"supports_inline_queries,omitempty"` // Optional }
Click to show internal directories.
Click to hide internal directories.