Documentation
¶
Overview ¶
Package telegram is the Telegram messaging provider, a bot, whose chats are channels. It receives messages by long polling, so the server needs no address on the internet.
Index ¶
- Constants
- type Telegram
- func (t *Telegram) Delete(ctx context.Context, address, id string) error
- func (t *Telegram) Edit(ctx context.Context, address, id, text string) error
- func (t *Telegram) Link(code string) string
- func (*Telegram) Name() string
- func (t *Telegram) Private(address string) bool
- func (t *Telegram) Receive(ctx context.Context, fn func(context.Context, messaging.Message) error) error
- func (t *Telegram) Send(ctx context.Context, address, text string) ([]messaging.Sent, error)
- func (t *Telegram) SendFile(ctx context.Context, address string, file messaging.File, ...) ([]messaging.Sent, error)
- func (t *Telegram) SetLocation(fn func() *time.Location)
- func (t *Telegram) Typing(ctx context.Context, address string) error
- func (t *Telegram) Username() string
Constants ¶
const (
// Name is the provider's name
Name = "telegram"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Telegram ¶
type Telegram struct {
// contains filtered or unexported fields
}
Telegram is a Telegram bot, whose chats are channels
func New ¶
New returns the bot with the token, from BotFather, with the client options, such as the user agent, or an endpoint for tests, once it's checked the token, and has the bot's username, which its links have
func (*Telegram) Edit ¶ added in v1.5.0
Edit changes the text of the message, which the bot sent, to the text, as it is, without formatting, and does nothing when it's the same
func (*Telegram) Link ¶
Link returns the link which opens a chat with the bot, whose Start button sends it the code
func (*Telegram) Private ¶ added in v1.6.3
Private returns true when the chat is a person's own, as a private chat's identifier is the person's, which is positive, and a group's, a supergroup's, or a channel's, is negative
func (*Telegram) Receive ¶
func (t *Telegram) Receive(ctx context.Context, fn func(context.Context, messaging.Message) error) error
Receive calls the function with each message people send the bot, until the context is cancelled, when it returns nil, or updates can't be read. Messages from bots, and without text, are skipped. A message is received once, whatever the function returns.
func (*Telegram) Send ¶
Send sends the text, which is Markdown, to the chat, formatted as Telegram's HTML, as more than one message, when it's longer than one can be, broken between paragraphs, or other blocks, and as plain text, when Telegram can't parse its HTML, and returns the messages it was sent as. Links don't have previews.
func (*Telegram) SendFile ¶ added in v1.5.0
func (t *Telegram) SendFile(ctx context.Context, address string, file messaging.File, open func() (io.ReadCloser, error), caption string) ([]messaging.Sent, error)
SendFile sends the file to the chat, as a photo, when it's an image Telegram shows as one, a voice message, when it's Ogg, or Opus, audio, a track, when it's MP3, or M4A, audio, and otherwise as a document, with the caption, which is Markdown, under it, formatted, when it fits, or as a message before it, when it doesn't, and returns the messages it was sent as. A caption whose formatting Telegram can't parse is sent as plain text, with the file again. A file which is larger than a bot can send is a note, with its name, after its caption.
func (*Telegram) SetLocation ¶ added in v1.5.0
SetLocation sets the function which returns the time zone the names of files which were sent without names are in, such as the person's, or nil, when it isn't known, when they're in UTC