telegram

package
v0.1.0 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

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"`
}

type Client

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

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"`
}

type Update

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

type User

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

Jump to

Keyboard shortcuts

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