Documentation ¶
Index ¶
- Variables
- func TelegramEscape(s string) string
- type Attachment
- type ChannelMigratedMessage
- type Chat
- type ChatInfo
- type ChatType
- type Client
- type ErrorLevel
- type File
- type FileAddress
- type JoinMessage
- type LeftMessage
- type LogRecord
- type Message
- type MessageFormat
- type Plugin
- type Slack
- func (s *Slack) AddPlugins(plugins ...Plugin) error
- func (s *Slack) ChatInfo(ctx context.Context, chatID string) (ChatInfo, error)
- func (s *Slack) EmulateReceiveMessage(raw []byte) error
- func (s *Slack) FetchImage(_ context.Context, fileURL string) (io.ReadCloser, error)
- func (s *Slack) Mention(u User) string
- func (s *Slack) Mentioned(field string) bool
- func (s *Slack) MessagePermalink(ctx context.Context, msg *Message) (string, error)
- func (s *Slack) ParseRawMessage(rawMsg []byte) (*Message, error)
- func (s *Slack) SendMessage(ctx context.Context, msg Message)
- func (s *Slack) SetTopic(ctx context.Context, chatID string, topic string) error
- func (s *Slack) Start(ctx context.Context) error
- func (s *Slack) ThreadReplies(ctx context.Context, chat Chat, threadID string) ([]*Message, error)
- func (s *Slack) UploadFile(ctx context.Context, chatID string, filename string, r io.Reader) error
- func (s *Slack) UserByName(username string) (User, bool)
- func (s *Slack) UserName() string
- type TChat
- type TChatMember
- type TError
- type TMessage
- type TOutMessage
- type TResponse
- type TUpdate
- type TUser
- type Telegram
- func (t *Telegram) AddPlugins(plugins ...Plugin) error
- func (t *Telegram) Chat(ctx context.Context, id string) (*TChat, error)
- func (t *Telegram) ChatInfo(ctx context.Context, chatID string) (ChatInfo, error)
- func (t *Telegram) FetchImage(ctx context.Context, fileURL string) (io.ReadCloser, error)
- func (t *Telegram) Kick(ctx context.Context, chatID, userID string) error
- func (t *Telegram) Leave(ctx context.Context, chatID string) error
- func (t *Telegram) Member(ctx context.Context, chatID, userID string) (*TChatMember, error)
- func (t *Telegram) MembersCount(ctx context.Context, chatID string) (int, error)
- func (t *Telegram) Mention(u User) string
- func (t *Telegram) Mentioned(field string) bool
- func (t *Telegram) MessagePermalink(ctx context.Context, msg *Message) (string, error)
- func (t *Telegram) SendMessage(ctx context.Context, msg Message)
- func (t *Telegram) SetTopic(ctx context.Context, chatID string, topic string) error
- func (t *Telegram) Start(ctx context.Context) error
- func (t *Telegram) Stop()
- func (t *Telegram) ThreadReplies(ctx context.Context, chat Chat, threadID string) ([]*Message, error)
- func (t *Telegram) Unban(ctx context.Context, chatID, userID string) error
- func (t *Telegram) UploadFile(ctx context.Context, chatID string, filename string, r io.Reader) error
- func (t *Telegram) UserByName(username string) (User, bool)
- func (t *Telegram) UserName() string
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // OutboxBufferSize is the size of the outbox channel OutboxBufferSize = 100 // OutboxWorker is the number of worker that sends message to telegram api OutboxWorker = 5 // VERSION compile time info VERSION = "" )
Options
var ( StatsMsgPerUpdateCount = metrics.NewRegisteredCounter("telegram.messagePerUpdate", metrics.DefaultRegistry) StatsUpdateCount = metrics.NewRegisteredCounter("telegram.updates.count", metrics.DefaultRegistry) StatsUpdateDuration = metrics.NewRegisteredTimer("telegram.updates.duration", metrics.DefaultRegistry) StatsSendMessageDuration = metrics.NewRegisteredTimer("telegram.sendMessage.duration", metrics.DefaultRegistry) StatsMsgTimeoutCount = metrics.NewRegisteredCounter("telegram.sendMessage.timeout", metrics.DefaultRegistry) StatsMsgFailedCount = metrics.NewRegisteredCounter("telegram.sendMessage.failed", metrics.DefaultRegistry) StatsMsgDiscardedCount = metrics.NewRegisteredCounter("telegram.sendMessage.discarded", metrics.DefaultRegistry) StatsMsgDroppedCount = metrics.NewRegisteredCounter("telegram.sendMessage.dropped", metrics.DefaultRegistry) )
Metrics for telegram
var Log = func(record LogRecord) {}
Log function that will be called for logging. By default it's null logger, client can override this to implement their logging of their choice
var TChatTypeMap = map[string]ChatType{ "private": Private, "group": Group, "supergroup": SuperGroup, "channel": Channel, }
TChatTypeMap maps betwwen string to bot.ChatType
Functions ¶
func TelegramEscape ¶ added in v0.2.0
TelegramEscape escapes html that is acceptable by telegram noinspection GoUnusedExportedFunction
Types ¶
type Attachment ¶ added in v0.2.0
type ChannelMigratedMessage ¶
type ChannelMigratedMessage struct { FromID string ToID string ReceivedAt time.Time Raw json.RawMessage `json:"-"` }
ChannelMigratedMessage represents that a chat type has been upgraded. Currently works on telegram
type Client ¶ added in v0.2.0
type Client interface { // AddPlugins will add each plugin as middleware, each message will flow to the Handle for each plugin unless // previous plugin return handled equals true AddPlugins(...Plugin) error // Start listening for new messages and block Start(context.Context) error // UserName of the bot UserName() string //Mentioned will return true filed is a mention to a user Mentioned(field string) bool // Mention a user Mention(user User) string // UserByName find user by username UserByName(username string) (User, bool) // Get chat information such as topic etc ChatInfo(ctx context.Context, chatID string) (ChatInfo, error) // SetTopic for a channel SetTopic(ctx context.Context, chatID, topic string) error // UploadFile to a channel UploadFile(ctx context.Context, chatID string, filename string, r io.Reader) error // Get all replies to a threaded message ThreadReplies(ctx context.Context, chat Chat, threadID string) ([]*Message, error) // Get Permanent link of a message MessagePermalink(ctx context.Context, msg *Message) (string, error) // Fetch Private Image that needs authentication FetchImage(ctx context.Context, fileURL string) (io.ReadCloser, error) // SendMessage SendMessage(ctx context.Context, msg Message) }
Client represent a chat client. Currently supports telegram
type ErrorLevel ¶ added in v0.2.1
type ErrorLevel int
const ( Error ErrorLevel = iota Info Warn Debug )
Error level in order of value Error < Info < Warn < Debug
type File ¶ added in v0.3.0
type File struct { Id string Name string Mimetype string Filetype string Url string UrlPublic string To []FileAddress From []FileAddress PlainText string `json:"plain_text"` }
type FileAddress ¶ added in v0.3.0
type JoinMessage ¶ added in v0.2.0
type JoinMessage struct {
*Message
}
JoinMessage represents information that a user join a chat
type LeftMessage ¶ added in v0.2.0
type LeftMessage struct {
*Message
}
LeftMessage represents information that a user left a chat
type LogRecord ¶ added in v0.2.1
type LogRecord struct { Message string Level ErrorLevel }
type Message ¶
type Message struct { ID string From User Date time.Time Chat Chat Text string Format MessageFormat ReplyTo *Message ReplyToID string ReceivedAt time.Time Attachments []Attachment Files []File PreviousMessage *Message // if message was edited, this is original message Raw json.RawMessage `json:"-"` Retry int `json:"-"` DiscardAfter time.Time `json:"-"` // contains filtered or unexported fields }
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(ctx context.Context, out chan Message, cl Client) error Handle(ctx context.Context, in interface{}) (handled bool, msg interface{}) }
Plugin is pluggable module to process messages
type Slack ¶ added in v0.2.0
type Slack struct {
// contains filtered or unexported fields
}
func (*Slack) AddPlugins ¶ added in v0.2.0
func (*Slack) EmulateReceiveMessage ¶ added in v0.2.0
func (*Slack) FetchImage ¶ added in v0.4.0
func (*Slack) MessagePermalink ¶ added in v0.4.0
func (*Slack) ParseRawMessage ¶ added in v0.3.0
func (*Slack) SendMessage ¶ added in v0.5.4
func (*Slack) ThreadReplies ¶ added in v0.4.0
func (*Slack) UploadFile ¶ added in v0.2.0
type TChatMember ¶ added in v0.2.0
TChatMember represent user membership of a group
type TError ¶ added in v0.2.0
type TError struct { ErrorCode int64 `json:"error_code,omitempty"` Description string `json:"description"` }
TError error response structure
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"` ReplyTo *TMessage `json:"reply_to_message,omitempty"` NewChatMember *TUser `json:"new_chat_member,omitempty"` LeftChatMember *TUser `json:"left_chat_member,omitempty"` ReceivedAt time.Time `json:"-"` Raw json.RawMessage `json:"-"` }
TMessage is Telegram incomming message
func (*TMessage) ToMigratedMessage ¶ added in v0.2.0
func (m *TMessage) ToMigratedMessage() ChannelMigratedMessage
ToMigratedMessage converts Telegram Message to bot.ChannelMigratedMessage
type TOutMessage ¶
type TOutMessage struct { ChatID string `json:"chat_id"` Text string `json:"text"` ParseMode string `json:"parse_mode,omitempty"` ReplyToMessageID *int64 `json:"reply_to_message_id,omitempty"` }
TOutMessage is Telegram outgoing message
type TResponse ¶
type TResponse struct { Ok bool `json:"ok"` Result json.RawMessage `json:"result,omitempty"` TError }
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 ¶
NewTelegram creates telegram API Client noinspection GoUnusedExportedFunction
func (*Telegram) AddPlugins ¶ added in v0.2.0
AddPlugin add processing module to telegram
func (*Telegram) FetchImage ¶ added in v0.4.0
func (*Telegram) MembersCount ¶ added in v0.2.0
MembersCount gets the counts of member for a chat id