bot

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2016 License: MIT Imports: 10 Imported by: 1

README

bot

Is a mini framework that alow you to create a plugin or system that works across multiple chat platform.

Currently it support small portions of telegram api.

TODO:

example project:

  • fam100 a game of family feud

Still experimental, interface is not stable yet

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OutboxBufferSize = 100

	// compile time info
	VERSION = ""
)
View Source
var TChatTypeMap = map[string]ChatType{
	"private":    Private,
	"group":      Group,
	"supergroup": SuperGroup,
	"channel":    Channel,
}

TChatTypeMap maps betwwen string to bot.ChatType

Functions

func SetLogger

func SetLogger(l zap.Logger)

Types

type ChannelMigratedMessage

type ChannelMigratedMessage struct {
	Message
	FromID     string
	ToID       string
	ReceivedAt time.Time
}

type Chat

type Chat struct {
	ID       string
	Type     ChatType
	Title    string
	Username string
}

Chat represents a chat session

type ChatType

type ChatType string

ChatType is type of the message

const (
	Private    ChatType = "private"
	Group      ChatType = "group"
	SuperGroup ChatType = "supergroup"
	Channel    ChatType = "channel"
)

Available ChatType

type Message

type Message struct {
	ID             string
	From           User
	Date           time.Time
	Chat           Chat
	Text           string
	Format         MessageFormat
	ReplyMessageID string
	ReceivedAt     time.Time
	Raw            json.RawMessage `json:"-"`
	Retry          int             `json:"-"`
	DiscardAfter   time.Time       `json:"-"`
}

Message represents chat message

type MessageFormat

type MessageFormat string

MessageFormat represents formatting of the message

const (
	Text     MessageFormat = ""
	Markdown MessageFormat = "markdown"
	HTML     MessageFormat = "html"
)

Available MessageFormat

type Plugin

type Plugin interface {
	Name() string
	Init(out chan Message) (chan interface{}, error)
}

Plugin is pluggable module to process messages

type TChat

type TChat struct {
	Type  string `json:"type"`
	Title string `json:"title"`
	TUser
}

TChat represents Telegram chat session

type TMessage

type TMessage struct {
	MessageID       int64     `json:"message_id"`
	From            TUser     `json:"from"`
	Date            int64     `json:"date"`
	Chat            TChat     `json:"chat"`
	Text            string    `json:"text"`
	ParseMode       string    `json:"parse_mode,omitempty"`
	MigrateToChatID *int64    `json:"migrate_to_chat_id,omitempty"`
	ReceivedAt      time.Time `json:"-"`
}

TMessage is Telegram incomming message

type TOutMessage

type TOutMessage struct {
	ChatID    string `json:"chat_id"`
	Text      string `json:"text"`
	ParseMode string `json:"parse_mode,omitempty"`
}

TOutMessage is Telegram outgoing message

type TResponse

type TResponse struct {
	Ok          bool            `json:"ok"`
	Result      json.RawMessage `json:"result,omitempty"`
	ErrorCode   int64           `json:"error_code,omitempty"`
	Description string          `json:"description"`
}

TResponse represents response from telegram

type TUpdate

type TUpdate struct {
	UpdateID int64           `json:"update_id"`
	Message  json.RawMessage `json:"message"`
}

TUpdate represents an update event from telegram

type TUser

type TUser struct {
	ID        int64  `json:"id"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Username  string `json:"username"`
}

TUser is Telegram User

type Telegram

type Telegram struct {
	// contains filtered or unexported fields
}

Telegram API

func NewTelegram

func NewTelegram(key string) *Telegram

NewTelegram creates telegram API Client

func (*Telegram) AddPlugin

func (t *Telegram) AddPlugin(p Plugin) error

AddPlugin add processing module to telegram

func (*Telegram) Leave

func (t *Telegram) Leave(chanID string) error

func (*Telegram) Start

func (t *Telegram) Start()

Start consuming from telegram

type User

type User struct {
	ID        string
	FirstName string
	LastName  string
	Username  string
}

User represents user information

func (User) FullName

func (u User) FullName() string

FullName returns Firstname + LastName

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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