tgbot

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

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

Go to latest
Published: Feb 19, 2016 License: MIT Imports: 10 Imported by: 0

README

tgbot

A friendly client to the bot API provided by Telegram.

See package documentation on https://godoc.org/github.com/cfstras/tgbot

License

MIT. See LICENSE.md

Documentation

Index

Constants

View Source
const DefaultBaseURL = "https://api.telegram.org/bot"
View Source
const Timeout = 5

Variables

View Source
var (
	ErrorInvalidArgs    error = errors.New("Invalid Arguments")
	ErrorNotImplemented       = errors.New("Not Implemented")
)

Functions

This section is empty.

Types

type Bot

type Bot struct {
	BaseURL string
	// contains filtered or unexported fields
}

func New

func New(apiKey string) (*Bot, error)

func (*Bot) Debug

func (b *Bot) Debug(enable bool)

func (*Bot) Info

func (b *Bot) Info() TGUser

func (*Bot) Listen

func (b *Bot) Listen(errHandler func(error) bool) (incoming <-chan TGMessage, stop chan<- bool)

Listen starts listening for updates. The given errHandler function will be called when an error occurs. If it returns false, listening is stopped.

Two channels are returned: incoming, an unbuffered channel providing updates, and stop, which causes the listening to stop if a value is written to it. Stop can take up to 10 seconds to react.

func (*Bot) Req

func (b *Bot) Req(method string, receiver interface{}) error

func (*Bot) Send

func (b *Bot) Send(chatId ID, text string) (TGMessage, error)

func (*Bot) SendAdv

func (b *Bot) SendAdv(chatId ID, text string, disablePreview bool,
	replyingToId *Integer) (TGMessage, error)

type ID

type ID interface {
	ID() Integer
}

type Integer

type Integer int32

func GetTokenFromEnv

func GetTokenFromEnv() (token string, id Integer)

func (Integer) ID

func (i Integer) ID() Integer

type TGGroupChat

type TGGroupChat struct {
	TGID
	Title string
}

type TGID

type TGID struct {
	Id Integer `json:"id"`
}

func (TGID) ID

func (t TGID) ID() Integer

type TGLocation

type TGLocation struct {
	Longitude float32 `json:"longitude"`
	Latitude  float32 `json:"latitude"`
}

type TGMessage

type TGMessage struct {
	MessageId      Integer         `json:"message_id"`       // Unique message identifier
	From           TGUser          `json:"from"`             // Sender
	Date           Integer         `json:"date"`             // Date the message was sent in Unix time
	Chat           TGUserGroupChat `json:"chat"`             // Conversation the message belongs to — user in case of a private message, GroupChat in case of a group
	ForwardFrom    *TGUser         `json:"forward_from"`     // Optional. For forwarded messages, sender of the original message
	ForwardDate    *Integer        `json:"forward_date"`     // Optional. For forwarded messages, date the original message was sent in Unix time
	ReplyToMessage *TGMessage      `json:"reply_to_message"` // Optional. 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.
	Text           *string         `json:"text"`             // Optional. For text messages, the actual UTF-8 text of the message
	//Audio               *Audio          `json:"asdf"` // Optional. Message is an audio file, information about the file
	//Document            *Document       `json:"asdf"` // Optional. Message is a general file, information about the file
	//Photo               []PhotoSize     `json:"asdf"` // Optional. Message is a photo, available sizes of the photo
	//Sticker             *Sticker        `json:"asdf"` // Optional. Message is a sticker, information about the sticker
	//Video               *Video          `json:"asdf"` // Optional. Message is a video, information about the video
	//Contact             *Contact        `json:"asdf"` // Optional. Message is a shared contact, information about the contact
	Location            *TGLocation `json:"location"`              // Optional. Message is a shared location, information about the location
	NewChatParticipant  *TGUser     `json:"new_chat_participant"`  // Optional. A new member was added to the group, information about them (this member may be bot itself)
	LeftChatParticipant *TGUser     `json:"left_chat_participant"` // Optional. A member was removed from the group, information about them (this member may be bot itself)
	NewChatTitle        *string     `json:"new_chat_title"`        // Optional. A group title was changed to this value
	//NewChatPhoto        []PhotoSize    `json:"new_chat_photo"` // Optional. A group photo was change to this value
	DeleteChatPhoto  bool `json:"delete_chat_photo"`  // Optional. Informs that the group photo was deleted
	GroupChatCreated bool `json:"group_chat_created"` // Optional. Informs that the group has been created
}

func (TGMessage) String

func (t TGMessage) String() string

type TGResponse

type TGResponse struct {
	Ok          bool
	Description string `json:",omitempty"`
	Result      json.RawMessage
}

type TGUpdate

type TGUpdate struct {
	UpdateId Integer   `json:"update_id"`
	Message  TGMessage `json:"message,omitempty"`
}

type TGUser

type TGUser struct {
	TGID
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name,omitempty"`
	Username  string `json:",omitempty"`
}

func (TGUser) String

func (u TGUser) String() string

type TGUserGroupChat

type TGUserGroupChat struct {
	TGUser
	TGGroupChat
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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