telegram

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package telegram provides a small Telegram Bot API client for sending messages, polling updates, restricting allowed users, and parsing commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseCommand

func ParseCommand(text string) (cmd, args string)

ParseCommand extracts the command and arguments from a message text. Returns empty strings if the message is not a command. Example: "/anki some text here" → "anki", "some text here"

Types

type Chat

type Chat struct {
	ID int64 `json:"id"`
}

Chat identifies the Telegram chat where a message was sent.

type Client

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

Client is a Telegram Bot API client.

func New

func New(token string, allowedUserIDs []int64) *Client

New creates a Telegram bot client. allowedUserIDs restricts who can interact with the bot. If empty, all users are allowed.

func (*Client) IsAllowed

func (c *Client) IsAllowed(userID int64) bool

IsAllowed returns true if the user is allowed to use the bot.

func (*Client) Poll

func (c *Client) Poll(ctx context.Context, handler func(context.Context, Update))

Poll starts long-polling getUpdates and dispatches each message to handler. Blocks until ctx is cancelled.

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, chatID int64, text string) error

SendMessage sends a text message to a chat.

type Message

type Message struct {
	MessageID int    `json:"message_id"`
	Chat      Chat   `json:"chat"`
	From      *User  `json:"from"`
	Text      string `json:"text"`
}

Message is the message payload attached to a Telegram update.

type Update

type Update struct {
	UpdateID int      `json:"update_id"`
	Message  *Message `json:"message"`
}

Update is a Telegram getUpdates item.

type User

type User struct {
	ID       int64  `json:"id"`
	Username string `json:"username"`
}

User identifies a Telegram user.

Jump to

Keyboard shortcuts

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