tgfun

package module
v1.14.29 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MPL-2.0 Imports: 21 Imported by: 0

README

tgfun

Documentation

Index

Constants

View Source
const (
	PaymentStatusCreated   = "created"
	PaymentStatusSuccess   = "success"
	PaymentStatusNotExists = "empty"

	PaymentSystemTypeTelegram = "telegram"
	PaymentSystemTypeLink     = "link"
)

Variables

This section is empty.

Functions

func IsNumber added in v1.11.11

func IsNumber(s string) bool

IsNumber проверяет, является ли строка числом (целым или дробным).

func LimitStringLen added in v1.11.10

func LimitStringLen(str string, maxLength int) string

Types

type AudioData added in v1.11.0

type AudioData struct {
	Path     string `json:"path"`
	Name     string `json:"name"`
	Duration int    `json:"duration"`
}

type BackLinkStatsFeature added in v1.14.27

type BackLinkStatsFeature struct {
	OnClick OnBackLinkClick
}

type BuildMessageCallback added in v1.3.0

type BuildMessageCallback func(telegramUserID int64) interface{}

type CheckPaymentStatus added in v1.14.7

type CheckPaymentStatus func(
	telegramUserID int64,
	eventID string,
) (PaymentStatus, error)

type CreateInvoicePayload added in v1.14.7

type CreateInvoicePayload struct {
	Payload InvoiceData
	Payment PaymentData

	Token     string
	FilesRoot string
}

type CreateInvoiceResponse added in v1.14.17

type CreateInvoiceResponse struct {
	Invoice *telebot.Invoice
	Photo   *telebot.Photo
}

type CustomCommandsFeature added in v1.12.8

type CustomCommandsFeature struct {
	Callback HandleCommandCallback
}

type EventMessage

type EventMessage struct {
	// main data
	Text string `json:"text"`

	// instead of main data
	Callback BuildMessageCallback `json:"-"` // use it to redefine message

	// additional events
	OnEvent OnEventCallback `json:"-"`

	// optional
	Image            string               `json:"image"` // local filename or URL
	ImageData        ImageData            `json:"imageData"`
	File             FileData             `json:"file"`
	Audio            AudioData            `json:"audio"`
	Video            VideoData            `json:"video"`
	Buttons          []MessageButton      `json:"buttons"`
	Format           ParseFormat          `json:"format"`
	ButtonsIsColumns bool                 `json:"buttonsIsColumns"`
	ButtonsSplit     int                  `json:"buttonsSplit"`
	Conversion       string               `json:"conversion"`  // optional
	Conversions      []string             `json:"conversions"` // optional
	OnConversion     OnConversionCallback `json:"-"`
	PinThisMessage   bool                 `json:"pin"`
	DisablePreview   bool                 `json:"disablePreview"`
}

EventMessage - funnel event message data

type FileData added in v1.7.2

type FileData struct {
	Path             string `json:"path"`
	Name             string `json:"name"`
	PreviewImagePath string `json:"preview"`
}

type FindInvoiceCallback added in v1.14.25

type FindInvoiceCallback func(
	telegramUserID int64,
	eventID string,
	status PaymentStatus,
) (InvoiceFullData, error)

when invoice not found, func should return empty struct

type Funnel

type Funnel struct {
	// public
	Data   FunnelData
	Script FunnelScript

	OnWebAppCallback func(ctx tb.Context) error
	// contains filtered or unexported fields
}

Funnel - telegram bot funnel

func NewFunnel

func NewFunnel(data FunnelData, script FunnelScript) *Funnel

NewFunnel - funnel constructor

func (*Funnel) EnableBackLinkStatsFeature added in v1.14.27

func (f *Funnel) EnableBackLinkStatsFeature(feature BackLinkStatsFeature) error

func (*Funnel) EnableCustomCommandsFeature added in v1.12.8

func (f *Funnel) EnableCustomCommandsFeature(feature CustomCommandsFeature)

func (*Funnel) EnablePaymentsFeature added in v1.14.7

func (f *Funnel) EnablePaymentsFeature(feature PaymentsFeature) error

func (*Funnel) EnableUTMTagsFeauture added in v1.9.7

func (f *Funnel) EnableUTMTagsFeauture(feature UTMTagsFeature)

func (*Funnel) EnableUserInputFeature added in v1.12.2

func (f *Funnel) EnableUserInputFeature(feature UserInputFeature) error

func (*Funnel) EnableUsersFeature added in v1.0.9

func (f *Funnel) EnableUsersFeature(feature UsersFeature)

EnableUsersFeature !

func (*Funnel) GetEventQueryHandler added in v1.6.0

func (f *Funnel) GetEventQueryHandler(
	eventMessageID string,
) (*QueryHandler, error)

func (*Funnel) Run

func (f *Funnel) Run() error

Run funnel. This is a non-blocking operation

func (*Funnel) SetupOnWebAppLaunchCallback added in v1.8.0

func (f *Funnel) SetupOnWebAppLaunchCallback(cb func(ctx tb.Context) error)

type FunnelData

type FunnelData struct {
	Token              string `json:"token"`
	ImageRoot          string `json:"imageRoot"`
	ResourcesCachePath string `json:"cachePath"`
}

FunnelData - data container for Funnel struct

type FunnelEvent

type FunnelEvent struct {
	Message      EventMessage            `json:"message"`
	Subscription SubscriptionEventLocker `json:"locker"`
	Payment      PaymentEventLocker      `json:"paymentLocker"`
}

FunnelEvent - user interaction event

type FunnelScript

type FunnelScript map[string]FunnelEvent // message ID -> event

FunnelScript - funnel scenario

type GetInvoiceByIDCallback added in v1.14.23

type GetInvoiceByIDCallback func(id uint64) (InvoiceData, error)

type GetUTMTagsCallback added in v1.9.7

type GetUTMTagsCallback func(telegramUserID int64) UTMTags

type HandleCommandCallback added in v1.12.8

type HandleCommandCallback func(ctx tb.Context, command string, data string) error

type ImageData added in v1.12.4

type ImageData struct {
	URLFormat    string `json:"urlFormat"`
	ArgumentType string `json:"argType"`
}

type InvoiceData added in v1.14.7

type InvoiceData struct {
	UserTelegramID int64   `json:"tid"`
	ForEventID     string  `json:"eventID"`
	Amount         float64 `json:"amount"`
}

func (InvoiceData) IsSet added in v1.14.25

func (i InvoiceData) IsSet() bool

type InvoiceFullData added in v1.14.25

type InvoiceFullData struct {
	InvoiceID       uint64      // from db
	InvoiceUniqueID string      // from payment system
	Payload         InvoiceData // payload
}

func (InvoiceFullData) IsSet added in v1.14.25

func (i InvoiceFullData) IsSet() bool

type InvoiceImage added in v1.14.15

type InvoiceImage struct {
	Path   string `json:"path"`
	URL    string `json:"url"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

type MessageButton

type MessageButton struct {
	Text              string `json:"text"`
	NextMessageID     string `json:"nextID"`     // optional for URL-buttons
	URL               string `json:"url"`        // optional. only for URL-buttons
	UseUTMTags        bool   `json:"useUtmTags"` // optional
	SkipRenderInGraph bool   `json:"skipRender"` // optional
}

MessageButton - funnel event message button

type MessageType added in v1.7.5

type MessageType string
const (
	MessageTypeText     MessageType = "text"
	MessageTypePhoto    MessageType = "photo"
	MessageTypeDocument MessageType = "document"
	MessageTypeVideo    MessageType = "video"
	MessageTypeAudio    MessageType = "audio"
)

type OnBackLinkClick added in v1.14.27

type OnBackLinkClick func(telegramUserID int64, eventID string)

type OnConversionCallback added in v1.6.2

type OnConversionCallback func(
	telegramUserID int64,
	conversionTag string,
	payload UserPayload,
) error

type OnEventCallback added in v1.3.0

type OnEventCallback func(tb.Context) error

type ParseFormat added in v1.6.3

type ParseFormat string
const (
	ParseFormatMarkdown ParseFormat = ParseFormat(tb.ModeMarkdown)
	ParseFormatHTML     ParseFormat = ParseFormat(tb.ModeHTML)
)

type PaymentData added in v1.14.7

type PaymentData struct {
	// required
	Amount      float64 `json:"amount"`
	Title       string  `json:"title"`
	Description string  `json:"description"`
	Label       string  `json:"label"`

	// optional
	ReusablePayment bool         `json:"reusable"`
	CurrencyCode    string       `json:"currencyCode"`
	Image           InvoiceImage `json:"image"`
	BtnLabel        string       `json:"btnLabel"`
}

type PaymentEventLocker added in v1.14.7

type PaymentEventLocker struct {
	Enabled bool        `json:"enabled"`
	Data    PaymentData `json:"data"`
}

type PaymentNotify added in v1.14.18

type PaymentNotify struct {
	ChatID   int64  `json:"chatID"`
	Format   string `json:"format"`
	Template string `json:"template"`
}

type PaymentStatus added in v1.14.7

type PaymentStatus string

type PaymentSystemType added in v1.14.22

type PaymentSystemType string

type PaymentsFeature added in v1.14.7

type PaymentsFeature struct {
	// public
	Token string

	CheckoutFailedEventID  string
	CheckoutSuccessEventID string
	CheckoutWaitEventID    string

	CheckPaymentCallback    CheckPaymentStatus
	GetInvoiceByID          GetInvoiceByIDCallback
	UpdatePaymentStatus     UpdatePaymentStatusCB
	UpdatePaymentStatusByID UpdatePaymentStatusByIDCB
	SavePayment             SaveInvoiceCB
	FindInvoice             FindInvoiceCallback
	SetInvoiceUniqueID      SetInvoiceUniqueIDCB

	PaymentType PaymentSystemType
	Notify      PaymentNotify

	BotUserName string // for yookassa link payments
	AccountID   string // for yookassa link payments
	SecretKey   string // for yookassa link payments
	// contains filtered or unexported fields
}

func (PaymentsFeature) IsNotifyEnabled added in v1.14.19

func (p PaymentsFeature) IsNotifyEnabled() bool

type QueryHandler added in v1.6.0

type QueryHandler struct {
	Script FunnelScript

	EventMessageID string
	EventData      FunnelEvent
	Menu           *tb.ReplyMarkup
	ParseMode      tb.ParseMode
	Bot            *tb.Bot
	FilesRoot      string // inherit from Funnel
	Features       *funnelFeatures
	// contains filtered or unexported fields
}

telegram user query handler

func (*QueryHandler) ActualizeCache added in v1.14.0

func (q *QueryHandler) ActualizeCache(st fileState, response *tb.Message)

func (*QueryHandler) CustomHandle added in v1.6.0

func (q *QueryHandler) CustomHandle(telegramUserID int64) error

type Resource added in v1.14.0

type Resource struct {
	FileUniqueID string    `json:"fileUniqueID"`
	FileID       string    `json:"fileID"`
	Size         int64     `json:"size"`
	Hash         string    `json:"hash"`
	ExpireAt     time.Time `json:"expireAt"`
}

type ResourcesCache added in v1.14.0

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

func NewResourceCache added in v1.14.0

func NewResourceCache(cachePath string, pathRoot string) *ResourcesCache

func (*ResourcesCache) Actualize added in v1.14.0

func (r *ResourcesCache) Actualize(
	localFilePath string,
	fileData telebot.File,
)

func (*ResourcesCache) Get added in v1.14.0

func (r *ResourcesCache) Get(localFilePath string) telebot.File

func (*ResourcesCache) IsNeedUpdate added in v1.14.0

func (r *ResourcesCache) IsNeedUpdate(
	localFilePath string,
	fileData telebot.File,
) bool

func (*ResourcesCache) Update added in v1.14.0

func (r *ResourcesCache) Update(
	localFilePath string,
	fileData telebot.File,
) error

type SaveInvoiceCB added in v1.14.23

type SaveInvoiceCB func(InvoiceData) (uint64, error)

type SetInvoiceUniqueIDCB added in v1.14.25

type SetInvoiceUniqueIDCB func(invoiceID uint64, newUniqueID string) error

type SubscriptionEventLocker added in v1.14.7

type SubscriptionEventLocker struct {
	Enabled         bool   `json:"enabled"`
	ChatID          int64  `json:"chatID"`
	LockerMessageID string `json:"lockerMessageID"`
}

type UTMTags added in v1.9.7

type UTMTags struct {
	Source   string `json:"source"`
	Campaign string `json:"campaign"`
	Content  string `json:"content"`
}

type UTMTagsFeature added in v1.9.7

type UTMTagsFeature struct {
	GetUserUTMTags GetUTMTagsCallback
}

type UpdatePaymentStatusByIDCB added in v1.14.24

type UpdatePaymentStatusByIDCB func(
	id uint64,
	newStatus PaymentStatus,
) error

type UpdatePaymentStatusCB added in v1.14.9

type UpdatePaymentStatusCB func(
	telegramUserID int64,
	eventID string,
	newStatus PaymentStatus,
) error

type UserInputFeature added in v1.12.2

type UserInputFeature struct {
	Regexp               string
	InputVerifiedEventID string
	InvalidFormatEventID string
	OnEventVerified      func(telegramUserID int64, input string)
	GetUserInputCallback func(telegramUserID int64) (string, error)
	// contains filtered or unexported fields
}

type UserPayload added in v1.11.10

type UserPayload struct {
	UTMSource       string `json:"s"`
	UTMCampaign     string `json:"c"`
	UTMContent      string `json:"t"`
	BackLinkEventID string `json:"b"`
	Yclid           string `json:"y"`
	InvoiceID       string `json:"i"`
}

func FilterUserPayload added in v1.11.12

func FilterUserPayload(
	payloadRaw string,
) (UserPayload, error)

payload format: source_campaign_yclid example: dzen_start or: dzen_start_100

func (UserPayload) IsEmpty added in v1.12.1

func (p UserPayload) IsEmpty() bool

func (UserPayload) IsOnlyBacklinkAvailable added in v1.14.27

func (p UserPayload) IsOnlyBacklinkAvailable() bool

func (UserPayload) String added in v1.12.1

func (p UserPayload) String() string

type UsersFeature added in v1.0.9

type UsersFeature struct {
	// required
	DBConn    *sql.DB
	TableName string

	// optional
	AdminChatID int64
}

UsersFeature - feature to enable users db

type VideoData added in v1.7.5

type VideoData struct {
	Path             string `json:"path"`
	PreviewImagePath string `json:"preview"`
	Width            int    `json:"width"`
	Height           int    `json:"height"`
}

Directories

Path Synopsis
lib module

Jump to

Keyboard shortcuts

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