Template Guide

Template Guide #

This guide is intended to introduce variables and functions that are available in the tdl template.

Template syntax is based on Go’s text/template package.

Download #

Variables (beta) #

VarDesc
DialogIDTelegram dialog id
MessageIDTelegram message id
MessageDateTelegram message date(timestamp)
FileNameTelegram file name
FileCaptionTelegram file caption, aka. text message
FileSizeHuman-readable file size, like 1GB
DownloadDateDownload date(timestamp)

Functions (beta) #

FuncDescUsageExample
repeatRepeat STRING N timesrepeat STRING N{{ repeat "test" 3 }}
replacePerform replacement on STRING with PAIRSreplace STRING PAIRS...{{ replace "Test" "t" "T" "e" "E" }}
upperConvert STRING to uppercaseupper STRING{{ upper "Test" }}
lowerConvert STRING to lowercaselower STRING{{ lower "Test" }}
snakecaseConvert STRING to snake_casesnakecase STRING{{ snakecase "Test" }}
camelcaseConvert STRING to camelCasecamelcase STRING{{ camelcase "Test" }}
kebabcaseConvert STRING to kebab-casekebabcase STRING{{ kebabcase "Test" }}
randGenerate random number in range MIN to MAXrand MIN MAX{{ rand 1 10 }}
nowGet current timestampnow{{ now }}
formatDateFormat TIMESTAMP with format
Default: 20060102150405
formatDate TIMESTAMP
formatDate TIMESTAMP "format"
{{ formatDate 1600000000 }}
{{ formatDate 1600000000 "2006-01-02-15-04-05"}}
filenamifyConvert STRING to a valid filename with the best effort.filenamify STRING{{ filenamify .FileName }}

Examples: #

{{ .DialogID }}_{{ .MessageID }}_{{ replace .FileCaption `/` `_` `\` `_` `:` `_` }}

{{ .FileName }}_{{ formatDate .DownloadDate }}_{{ .FileSize }}

{{ .FileName }}_{{ formatDate .DownloadDate "2006-01-02-15-04-05"}}_{{ .FileSize }}

{{ lower (replace .FileName ` ` `_`) }}

{{ formatDate (now) }}

Default: #

{{ .DialogID }}_{{ .MessageID }}_{{ filenamify .FileName }}