tlbot

package module
v0.0.0-...-dd6c46f Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2016 License: MIT Imports: 12 Imported by: 2

README

tlbot

tlbot is a Go package to help writing Telegram bots

installation

go get github.com/igungor/tlbot

usage

Documentation

Also look at echobot

license

MIT. See LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string
const (
	Typing            Action = "typing"
	UploadingPhoto    Action = "upload_photo"
	UploadingVideo    Action = "upload_video"
	UploadingAudio    Action = "upload_audio"
	UploadingDocument Action = "upload_document"
	FindingLocation   Action = "find_location"
)

Types of actions to broadcast

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

func New(token string) Bot

New creates a new Telegram bot with the given token, which is given by Botfather. See https://core.telegram.org/bots#botfather

func (Bot) GetFile

func (b Bot) GetFile(fileID string) (File, error)

func (Bot) GetFileDownloadURL

func (b Bot) GetFileDownloadURL(fileID string) (string, error)

func (Bot) Listen

func (b Bot) Listen(addr string) <-chan Message

Listen listens on the given address addr and returns a read-only Message channel.

func (Bot) SendChatAction

func (b Bot) SendChatAction(recipient int, action Action) error

SendChatAction broadcasts type of action to recipient, such as `typing`, `uploading a photo` etc.

func (Bot) SendLocation

func (b Bot) SendLocation(recipient int, location Location, opts *SendOptions) (Message, error)

SendLocation sends location point on the map.

func (Bot) SendMessage

func (b Bot) SendMessage(recipient int, message string, opts *SendOptions) (Message, error)

SendMessage sends text message to the recipient. Callers can send plain text or markdown messages by setting mode parameter.

func (Bot) SendPhoto

func (b Bot) SendPhoto(recipient int, photo Photo, opts *SendOptions) (Message, error)

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) SendVenue

func (b Bot) SendVenue(recipient int, venue Venue, opts *SendOptions) (Message, error)

SendVenue sends information about a venue.

func (Bot) SetWebhook

func (b Bot) SetWebhook(webhook string) error

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

func (c Chat) IsGroupChat() bool

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 File struct {
	// File is embedded in most of the types. So a `File` prefix is used
	FileID   string `json:"file_id"`
	FileSize int    `json:"file_size"`
	FilePath string `json:"file_path"`

	Name string    `json:"-"`
	Body io.Reader `json:"-"`
	URL  string    `json:"-"`
}

func (File) Exists

func (f File) Exists() bool

Exists reports whether the file is already at Telegram servers.

type Location

type Location struct {
	Lat  float64 `json:"latitude"`
	Long float64 `json:"longitude"`
}

Location represents a point on the map.

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

func (m Message) Args() []string

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

func (m Message) Command() string

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) IsReply

func (m Message) IsReply() bool

IsReply reports whether the message is a reply to another message.

func (Message) IsService

func (m Message) IsService() bool

IsService reports whether the message is a Telegram service message, not a user sent message.

func (Message) String

func (m Message) String() string

String returns a human-readable representation of Message.

func (Message) Time

func (m Message) Time() time.Time

Time returns the moment of message in UTC time.

type ParseMode

type ParseMode string
const (
	ModeNone     ParseMode = ""
	ModeMarkdown ParseMode = "markdown"
)

Parse modes

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 Update

type Update struct {
	ID      int     `json:"update_id"`
	Payload Message `json:"message"`
}

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.

func Me

func Me(b Bot) (User, error)

Me return bot info

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

type Video

type Video struct {
	File
	Width     int    `json:"width"`
	Height    int    `json:"height"`
	Duration  int    `json:"duration"`
	Thumbnail Photo  `json:"thumb"`
	MimeType  string `json:"mime_type"`
	Caption   string `json:"caption"`
}

Video represents a video file.

type Voice

type Voice struct {
	File
	Duration int    `json:"duration"`
	MimeType string `json:"mime_type"`
}

Voice represents an voice note.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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