telegram

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Scheme = "telegram"
)

Scheme is the identifying part of this service's configuration URL

Variables

View Source
var ParseModes = &parseModeVals{
	None:       0,
	Markdown:   1,
	HTML:       2,
	MarkdownV2: 3,
	Enum: format.CreateEnumFormatter(
		[]string{
			"None",
			"Markdown",
			"HTML",
			"MarkdownV2",
		}),
}

ParseModes is an enum helper for parseMode

Functions

func GetErrorResponse added in v0.5.0

func GetErrorResponse(body string) error

GetErrorResponse retrieves the error message from a failed request

func IsTokenValid

func IsTokenValid(token string) bool

IsTokenValid for use with telegram

Types

type Chat added in v0.5.0

type Chat struct {
	ID       int64  `json:"id"`
	Type     string `json:"type"`
	Title    string `json:"title"`
	Username string `json:"username"`
}

Chat represents a telegram conversation

func (*Chat) Name added in v0.5.0

func (c *Chat) Name() string

Name returns the name of the channel based on its type

type ChatMember added in v0.6.0

type ChatMember struct {
	//	The member's status in the chat
	Status string `json:"status"`
	// Information about the user
	User *User `json:"user"`
}

ChatMember represents the membership state for a user in a telegram chat

type ChatMemberUpdate added in v0.6.0

type ChatMemberUpdate struct {
	// Chat the user belongs to
	Chat *Chat `json:"chat"`
	// Performer of the action, which resulted in the change
	From *User `json:"from"`
	// Date the change was done in Unix time
	Date int `json:"date"`
	// Previous information about the chat member
	OldChatMember *ChatMember `json:"old_chat_member"`
	// New information about the chat member
	NewChatMember *ChatMember `json:"new_chat_member"`
}

ChatMemberUpdate represents a member update in a telegram chat

type Client added in v0.5.0

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

Client for Telegram API

func (*Client) GetBotInfo added in v0.5.0

func (c *Client) GetBotInfo() (*User, error)

GetBotInfo returns the bot User info

func (*Client) GetUpdates added in v0.5.0

func (c *Client) GetUpdates(offset int, limit int, timeout int, allowedUpdates []string) ([]Update, error)

GetUpdates retrieves the latest updates

func (*Client) SendMessage added in v0.5.0

func (c *Client) SendMessage(message *SendMessagePayload) (*Message, error)

SendMessage sends the specified Message

type Config

type Config struct {
	Token        string    `url:"user"`
	Preview      bool      `key:"preview" default:"Yes" desc:"If disabled, no web page preview will be displayed for URLs"`
	Notification bool      `key:"notification" default:"Yes" desc:"If disabled, sends Message silently"`
	ParseMode    parseMode `key:"parsemode" default:"None" desc:"How the text Message should be parsed"`
	Chats        []string  `key:"chats,channels" desc:"Chat IDs or Channel names (using @channel-name)"`
	Title        string    `key:"title" default:"" desc:"Notification title, optionally set by the sender"`
}

Config for use within the telegram plugin

func (*Config) Enums

func (config *Config) Enums() map[string]types.EnumFormatter

Enums returns the fields that should use a corresponding EnumFormatter to Print/Parse their values

func (*Config) GetURL

func (config *Config) GetURL() *url.URL

GetURL returns a URL representation of it's current field values

func (*Config) SetURL

func (config *Config) SetURL(url *url.URL) error

SetURL updates a ServiceConfig from a URL representation of it's field values

type Generator added in v0.5.0

type Generator struct {
	Reader io.Reader
	Writer io.Writer
	// contains filtered or unexported fields
}

Generator is the telegram-specific URL generator

func (*Generator) Generate added in v0.5.0

func (g *Generator) Generate(_ types.Service, props map[string]string, _ []string) (types.ServiceConfig, error)

Generate a telegram Shoutrrr configuration from a user dialog

type Message added in v0.5.0

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

Message represents one chat message

type SendMessagePayload

type SendMessagePayload struct {
	Text                string       `json:"text"`
	ID                  string       `json:"chat_id"`
	MessageThreadID     *int         `json:"message_thread_id,omitempty"`
	ParseMode           string       `json:"parse_mode,omitempty"`
	DisablePreview      bool         `json:"disable_web_page_preview"`
	DisableNotification bool         `json:"disable_notification"`
	ReplyMarkup         *replyMarkup `json:"reply_markup,omitempty"`
	Entities            []entity     `json:"entities,omitempty"`
	ReplyTo             int64        `json:"reply_to_message_id"`
	MessageID           int64        `json:"message_id,omitempty"`
}

SendMessagePayload is the notification payload for the telegram notification service

type Service

type Service struct {
	standard.Standard
	// contains filtered or unexported fields
}

Service sends notifications to a given telegram chat

func (*Service) GetConfig

func (service *Service) GetConfig() *Config

GetConfig returns the Config for the service

func (*Service) Initialize

func (service *Service) Initialize(configURL *url.URL, logger types.StdLogger) error

Initialize loads ServiceConfig from configURL and sets logger for this Service

func (*Service) Send

func (service *Service) Send(message string, params *types.Params) error

Send notification to Telegram

type Update added in v0.5.0

type Update struct {
	// 	The Update's unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you're using Webhooks, since it allows you to ignore repeated updates or to restore the correct Update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next Update will be chosen randomly instead of sequentially.
	UpdateID int `json:"update_id"`
	// 	Optional. New incoming Message of any kind — text, photo, sticker, etc.
	Message *Message `json:"Message"`
	// 	Optional. New version of a Message that is known to the bot and was edited
	EditedMessage *Message `json:"edited_message"`
	// 	Optional. New incoming channel post of any kind — text, photo, sticker, etc.
	ChannelPost *Message `json:"channel_post"`
	// 	Optional. New version of a channel post that is known to the bot and was edited
	EditedChannelPost *Message `json:"edited_channel_post"`
	// 	Optional. New incoming inline query
	InlineQuery *inlineQuery `json:"inline_query"`
	//// 	Optional. The result of an inline query that was chosen by a User and sent to their chat partner. Please see our documentation on the feedback collecting for details on how to enable these updates for your bot.
	ChosenInlineResult *chosenInlineResult `json:"chosen_inline_result"`
	//// 	Optional. New incoming callback query
	CallbackQuery *callbackQuery `json:"callback_query"`

	ChatMemberUpdate *ChatMemberUpdate `json:"my_chat_member"`
}

Update contains state changes since the previous Update

type User added in v0.5.0

type User struct {
	//	Unique identifier for this User or bot
	ID int64 `json:"id"`
	// True, if this User is a bot
	IsBot bool `json:"is_bot"`
	// User's or bot's first name
	FirstName string `json:"first_name"`
	//	Optional. User's or bot's last name
	LastName string `json:"last_name"`
	// Optional. User's or bot's username
	Username string `json:"username"`
	// Optional. IETF language tag of the User's language
	LanguageCode string `json:"language_code"`
	// 	Optional. True, if the bot can be invited to groups. Returned only in getMe.
	CanJoinGroups bool `json:"can_join_groups"`
	// 	Optional. True, if privacy mode is disabled for the bot. Returned only in getMe.
	CanReadAllGroupMessages bool `json:"can_read_all_group_messages"`
	// 	Optional. True, if the bot supports inline queries. Returned only in getMe.
	SupportsInlineQueries bool `json:"supports_inline_queries"`
}

User contains information about a telegram user or bot

Jump to

Keyboard shortcuts

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