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) Link(code string) string
- func (*Telegram) Name() string
- 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) error
- 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) Link ¶
Link returns the link which opens a chat with the bot, whose Start button sends it the code
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. Links don't have previews.