Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot is a telegram bot model.
func NewBot ¶
NewBot receives a string of the bot identity ("<botID>:<botToken>") and returns the new Bot instance. Returns an error if given identity is not in valid format.
Examples of the identity strings: - `bot12345:botToken1` - `54321:botToken2`
func (*Bot) GetIdentity ¶
func (b *Bot) GetIdentity() BotIdentity
GetIdentity returns a Bot identity string to pass it to the API.
type BotIdentity ¶
type BotIdentity string
BotIdentity is a Bot identity string.
func (BotIdentity) String ¶
func (t BotIdentity) String() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a tool to communicate with a Telegram API via the HTTPS.
func NewClient ¶
func NewClient(httpClient HTTPClient) *Client
NewClient creates a new telegram Client instance.
func NewDefaultClient ¶
func NewDefaultClient() *Client
NewDefaultClient creates a new default telegram Client instance.
func (*Client) Get ¶
Get sends a GET request to the Telegram API. The successful response is decoded into the target.
func (*Client) GetMe ¶
GetMe returns information about the Bot in the TgUser format. See: https://core.telegram.org/bots/api#getme
func (*Client) Post ¶
Post sends a POST request to the Telegram API. The successful response is decoded into the target.
func (*Client) SendMessage ¶
func (c *Client) SendMessage(bot *Bot, msg TgMessageRequest) (*TgMessage, error)
SendMessage sends a message from the bot via the Telegram API. See: https://core.telegram.org/bots/api#sendmessage
type HTTPClient ¶ added in v0.0.6
type HTTPClient interface { Get(url string) (resp *http.Response, err error) Post(url, contentType string, body io.Reader) (resp *http.Response, err error) }
HTTPClient is an HTTP client interface; the http.Client fits.
type HTTPClientJSONMock ¶ added in v0.0.6
type HTTPClientJSONMock struct {
// contains filtered or unexported fields
}
HTTPClientJSONMock is a test client returning the predefined response.
func (*HTTPClientJSONMock) Get ¶ added in v0.0.6
func (m *HTTPClientJSONMock) Get(url string) (resp *http.Response, err error)
func (*HTTPClientJSONMock) RegisterResponse ¶ added in v0.0.6
func (m *HTTPClientJSONMock) RegisterResponse(method string, url string, responseCode int, responseBody any)
RegisterResponse registers response for the url.
type TgErrorResponse ¶
type TgErrorResponse struct { Ok bool `json:"ok"` ErrorCode int `json:"error_code,omitempty"` Description string `json:"description,omitempty"` }
TgErrorResponse is a Telegram response describing the error.
func (TgErrorResponse) Error ¶
func (r TgErrorResponse) Error() string
type TgMessage ¶
type TgMessage struct { MessageID int `json:"message_id"` From TgUser `json:"from"` Date uint64 `json:"date"` MessageThreadId int `json:"message_thread_id,omitempty"` }
TgMessage is a Telegram message model. See https://core.telegram.org/bots/api#message TODO: add a lot of fields :)
type TgMessageRequest ¶
type TgMessageRequest struct { ChatID ChatID `json:"chat_id"` Text string `json:"text"` BusinessConnectionId string `json:"business_connection_id,omitempty"` MessageThreadId int `json:"message_thread_id,omitempty"` ParseMode string `json:"parse_mode,omitempty"` DisableNotification bool `json:"disable_notification,omitempty"` ProtectContent bool `json:"protect_content,omitempty"` }
TgMessageRequest is a message request body. See https://core.telegram.org/bots/api#sendmessage TODO: add entities, link_preview_options, reply_parameters and reply_markup fields.
type TgMessageResponse ¶
TgMessageResponse is a Telegram response with a single message result.
type TgUser ¶
type TgUser struct { ID int64 `json:"id"` FirstName string `json:"first_name"` LastName string `json:"last_name,omitempty"` Username string `json:"username,omitempty"` LanguageCode string `json:"language_code,omitempty"` IsBot bool `json:"is_bot"` IsPremium bool `json:"is_premium,omitempty"` AddedToAttachmentMenu bool `json:"added_to_attachment_menu,omitempty"` CanJoinGroups bool `json:"can_join_groups,omitempty"` CanReadAllGroupMessages bool `json:"can_read_all_group_messages,omitempty"` SupportsInlineQueries bool `json:"supports_inline_queries,omitempty"` CanConnectToBusiness bool `json:"can_connect_to_business,omitempty"` }
TgUser is a model of the Telegram User. See https://core.telegram.org/bots/api#user
type TgUserResponse ¶
TgUserResponse is a response from the Telegram with a single TgUser object inside.