telegramclient

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 8 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EscapeMarkdown

func EscapeMarkdown(text string) string

Types

type Client

type Client struct {
	Log logger.Interface
	Cfg ConfigStruct
}

func NewClient

func NewClient(config ConfigStruct) *Client

func (Client) SendMessage

func (c Client) SendMessage(chatID int64, message MessageStruct) error

type ClientInterface

type ClientInterface interface {
	SendMessage(chatID int64, messageOut MessageStruct) error
}

type ConfigStruct

type ConfigStruct struct {
	APIKey              string
	WebhookURL          string
	BaseURL             string
	EndpointSetWebhook  string
	EndpointSendMessage string
	EndpointSendPhoto   string
	ChatID              int64
}

type Handler

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

func NewHandler

func NewHandler(
	config *ConfigStruct,
	fn func(messageIn WebhookMessageStruct),
) *Handler

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(res http.ResponseWriter, req *http.Request)

type MessageResponseBodyStruct

type MessageResponseBodyStruct struct {
	Ok          bool   `json:"ok"`
	ErrorCode   int16  `json:"error_code"` //nolint:tagliatelle
	Description string `json:"description"`
}

type MessageStruct

type MessageStruct struct {
	ChatID                int64  `json:"chat_id"`             //nolint:tagliatelle
	ReplyToMessageID      int64  `json:"reply_to_message_id"` //nolint:tagliatelle
	Text                  string `json:"text"`
	Photo                 string `json:"photo"`
	Caption               string `json:"caption"`
	ParseMode             string `json:"parse_mode"`               //nolint:tagliatelle
	DisableWebPagePreview bool   `json:"disable_web_page_preview"` //nolint:tagliatelle
	DisableNotification   bool   `json:"disable_notification"`     //nolint:tagliatelle
}

func MarkdownMessage

func MarkdownMessage(text string) MessageStruct

func MarkdownPhoto

func MarkdownPhoto(photo string, caption string) MessageStruct

func MarkdownReply

func MarkdownReply(text string, messageID int64) MessageStruct

func Message

func Message(text string) MessageStruct

func Photo

func Photo(photo string, caption string) MessageStruct

func Reply

func Reply(text string, messageID int64) MessageStruct

type MockClient

type MockClient struct{}

func NewMockClient

func NewMockClient() *MockClient

func (MockClient) SendMessage

func (c MockClient) SendMessage(_ int64, _ MessageStruct) error

type WebhookBodyStruct

type WebhookBodyStruct struct {
	Message WebhookMessageStruct `json:"message"`
}

type WebhookHandlerInterface

type WebhookHandlerInterface interface {
	ServeHTTP(res http.ResponseWriter, req *http.Request)
}

type WebhookMessageChatStruct

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

func TestWebhookMessageChat

func TestWebhookMessageChat() WebhookMessageChatStruct

type WebhookMessagePhotoStruct

type WebhookMessagePhotoStruct struct {
	FileID       string `json:"file_id"`        //nolint:tagliatelle
	FileUniqueID string `json:"file_unique_id"` //nolint:tagliatelle
	FileSize     int    `json:"file_size"`      //nolint:tagliatelle
	Width        int    `json:"width"`
	Height       int    `json:"height"`
}

type WebhookMessageStruct

type WebhookMessageStruct struct {
	ID      int64                       `json:"message_id"` //nolint:tagliatelle
	From    WebhookMessageUserStruct    `json:"from"`
	Chat    WebhookMessageChatStruct    `json:"chat"`
	Text    string                      `json:"text"`
	Date    int64                       `json:"date"`
	Photo   []WebhookMessagePhotoStruct `json:"photo"`
	Caption string                      `json:"caption"`
}

func TestWebhookMessage

func TestWebhookMessage(text string) WebhookMessageStruct

func (WebhookMessageStruct) TextOrCaption

func (m WebhookMessageStruct) TextOrCaption() string

func (WebhookMessageStruct) WordCount

func (m WebhookMessageStruct) WordCount() int

type WebhookMessageUserStruct

type WebhookMessageUserStruct struct {
	ID           int64  `json:"id"`
	IsBot        bool   `json:"is_bot"`     //nolint:tagliatelle
	FirstName    string `json:"first_name"` //nolint:tagliatelle
	LastName     string `json:"last_name"`  //nolint:tagliatelle
	Username     string `json:"username"`
	LanguageCode string `json:"language_code"` //nolint:tagliatelle
}

func TestWebhookMessageUser

func TestWebhookMessageUser(isBot bool) WebhookMessageUserStruct

func (WebhookMessageUserStruct) FirstnameOrUsername

func (u WebhookMessageUserStruct) FirstnameOrUsername() string

func (WebhookMessageUserStruct) UsernameOrName

func (u WebhookMessageUserStruct) UsernameOrName() string

Jump to

Keyboard shortcuts

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