Documentation ¶
Index ¶
- type Action
- type Audio
- type Bot
- func (b Bot) GetFile(fileID string) (File, error)
- func (b Bot) GetFileDownloadURL(fileID string) (string, error)
- func (b Bot) Listen(addr string) <-chan Message
- func (b Bot) SendChatAction(recipient int, action Action) error
- func (b Bot) SendLocation(recipient int, location Location, opts *SendOptions) (Message, error)
- func (b Bot) SendMessage(recipient int, message string, opts *SendOptions) (Message, error)
- func (b Bot) SendPhoto(recipient int, photo Photo, opts *SendOptions) (Message, error)
- func (b Bot) SendVenue(recipient int, venue Venue, opts *SendOptions) (Message, error)
- func (b Bot) SetWebhook(webhook string) error
- type Chat
- type Contact
- type Document
- type File
- type Location
- type Message
- type ParseMode
- type Photo
- type ReplyMarkup
- type SendOptions
- type Sticker
- type Update
- type User
- type Venue
- type Video
- type Voice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Audio ¶
type Audio struct { File Duration int `json:"duration"` Performer string `json:"performer"` Title string `json:"title"` MimeType string `json:"mime_type"` }
Audio represents an audio file.
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot represent a Telegram bot.
func New ¶
New creates a new Telegram bot with the given token, which is given by Botfather. See https://core.telegram.org/bots#botfather
func (Bot) Listen ¶
Listen listens on the given address addr and returns a read-only Message channel.
func (Bot) SendChatAction ¶
SendChatAction broadcasts type of action to recipient, such as `typing`, `uploading a photo` etc.
func (Bot) SendLocation ¶
SendLocation sends location point on the map.
func (Bot) SendMessage ¶
SendMessage sends text message to the recipient. Callers can send plain text or markdown messages by setting mode parameter.
func (Bot) SendPhoto ¶
SendPhoto sends given photo to recipient. Only remote URLs are supported for now. A trivial example is:
b := bot.New("your-token-here") photo := bot.Photo{URL: "http://i.imgur.com/6S9naG6.png"} err := b.SendPhoto(recipient, photo, "sample image", nil)
func (Bot) SetWebhook ¶
SetWebhook assigns bot's webhook url with the given url.
type Chat ¶
type Chat struct { ID int `json:"id"` Type string `json:"type"` Title string `json:"title"` Username string `json:"username"` FirstName string `json:"first_name"` LastName string `json:"last_name"` }
Chat represents a Telegram chat.
func (Chat) IsGroupChat ¶
IsGroupChat reports whether the message is originally sent from a chat group.
type Contact ¶
type Contact struct { PhoneNumber string `json:"phone_number"` FirstName string `json:"first_name"` LastName string `json:"last_name"` UserID string `json:"user_id"` }
Contact represents a phone contact.
type Document ¶
type Document struct { File Filename string `json:"file_name"` Thumbnail Photo `json:"thumb"` MimeType string `json:"mime_type"` }
Document represents a general file (as opposed to photos and audio files).
type File ¶
type Message ¶
type Message struct { // Unique message identifier ID int `json:"message_id"` // Sender (optional. can be empty for messages sent to channel) From User `json:"from"` // Date is when the message was sent in Unix time Unixtime int `json:"date"` // Conversation the message belongs to — user in case of a private chat, // group in case of a group chat Chat Chat `json:"chat"` // For forwarded messages, sender of the original message (Optional) ForwardFrom User `json:"forward_from"` // For forwarded messages, date the original message was sent in // Unix time (Optional) ForwardDate int `json:"forward_date"` // For replies, the original message. Note that the Message // object in this field will not contain further reply_to_message fields // even if it itself is a reply (Optional) ReplyTo *Message `json:"reply_to_message"` // For text messages, the actual UTF-8 text of the message (Optional) Text string `json:"text"` // Message is an audio file, information about the file (Optional) Audio Audio `json:"audio"` // Message is a general file, information about the file (Optional) Document Document `json:"document"` // Message is a photo, available sizes of the photo (Optional) Photos []Photo `json:"photo"` // Message is a sticker, information about the sticker (Optional) Sticker Sticker `json:"sticker"` // Message is a video, information about the video (Optional) Video Video `json:"video"` // Message is a shared contact, information about the contact (Optional) Contact Contact `json:"contact"` // Message is a shared location, information about the location (Optional) Location Location `json:"location"` // A new member was added to the group, information about them // (this member may be bot itself) (Optional) JoinedUser User `json:"new_chat_participant"` // A member was removed from the group, information about them // (this member may be bot itself) (Optional) LeftUser User `json:"left_chat_participant"` // A group title was changed to this value (Optional) NewChatTitle string `json:"new_chat_title"` // A group photo was change to this value (Optional) NewChatPhoto []Photo `json:"new_chat_photo"` // Informs that the group photo was deleted (Optional) ChatPhotoDeleted bool `json:"delete_chat_photo"` // Informs that the group has been created (Optional) GroupChatCreated bool `json:"group_chat_created"` }
Message represents a message to be sent.
func (Message) Args ¶
Args returns all words after the first word in the message text. First word is meant to be the command name and can be accessed with Command method.
func (Message) Command ¶
Command returns the command's name: the first word in the message text. If message text starts with a `/`, function returns the command name, or else empty string.
func (Message) IsService ¶
IsService reports whether the message is a Telegram service message, not a user sent message.
type Photo ¶
type Photo struct { File Width int `json:"width"` Height int `json:"height"` Caption string `json:"caption"` }
Photo represents one size of a photo or a file/sticker thumbnail.
type ReplyMarkup ¶
type ReplyMarkup struct { Keyboard [][]string `json:"keyboard,omitempty"` Resize bool `json:"resize_keyboard,omitempty"` OneTime bool `json:"one_time_keyboard,omitempty"` Selective bool `json:"selective,omitempty"` Hide bool `json:"hide_keyboard,omitempty"` ForceReply bool `json:"force_reply,omitempty"` }
type SendOptions ¶
type SendOptions struct { ReplyTo int ParseMode ParseMode DisableWebPagePreview bool DisableNotification bool ReplyMarkup ReplyMarkup }
type Sticker ¶
type Sticker struct { File Width int `json:"width"` Height int `json:"height"` Thumbnail Photo `json:"thumb"` }
Sticker represents a sticker.
type User ¶
type User struct { ID int `json:"id"` Username string `json:"username"` FirstName string `json:"first_name"` LastName string `json:"last_name"` }
User represents a Telegram user or bot.
type Venue ¶
type Venue struct { Location Location `json:"location"` Title string `json:"title"` Address string `json:"address"` FoursquareID string `json:"foursquare_id"` }
Venue represents a venue