all repos — telegram-bot-api @ 9e20459100a7dbf269c7d018373a5e376dd272e6

Golang bindings for the Telegram Bot API

Update docs.
Syfaro syfaro@huefox.com
Fri, 20 Aug 2021 16:15:37 -0400
commit

9e20459100a7dbf269c7d018373a5e376dd272e6

parent

6aa05225a6152ebca3dcb6495e00a6f6c78a2f32

2 files changed, 8 insertions(+), 27 deletions(-)

jump to
M docs/getting-started/files.mddocs/getting-started/files.md

@@ -3,20 +3,22 @@

Telegram supports specifying files in many different formats. In order to accommodate them all, there are multiple structs and type aliases required. +All of these types implement the `RequestFileData` interface. + | Type | Description | | ------------ | ------------------------------------------------------------------------- | -| `string` | Used as a local path to a file | +| `FilePath` | A local path to a file | | `FileID` | Existing file ID on Telegram's servers | | `FileURL` | URL to file, must be served with expected MIME type | | `FileReader` | Use an `io.Reader` to provide a file. Lazily read to save memory. | | `FileBytes` | `[]byte` containing file data. Prefer to use `FileReader` to save memory. | -## `string` +## `FilePath` A path to a local file. ```go -file := "tests/image.jpg" +file := tgbotapi.FilePath("tests/image.jpg") ``` ## `FileID`
M docs/internals/uploading-files.mddocs/internals/uploading-files.md

@@ -28,14 +28,14 @@ // We can have multiple files, so we'll create an array. We also know that

// there always is a document file, so initialize the array with that. files := []RequestFile{{ Name: "document", - File: config.File, + Data: config.File, }} // We'll only add a file if we have one. if config.Thumb != nil { files = append(files, RequestFile{ Name: "thumb", - File: config.Thumb, + Data: config.Thumb, }) }

@@ -58,7 +58,7 @@

First, we start by creating some `InputMediaPhoto`. ```go -photo := tgbotapi.NewInputMediaPhoto("tests/image.jpg") +photo := tgbotapi.NewInputMediaPhoto(tgbotapi.FilePath("tests/image.jpg")) url := tgbotapi.NewInputMediaPhoto(tgbotapi.FileURL("https://i.imgur.com/unQLJIb.jpg")) ```

@@ -85,24 +85,3 @@ are all changed into `attach://file-%d`. When collecting a list of files to

upload, it names them the same way. This creates a nearly transparent way of handling multiple files in the background without the user having to consider what's going on. - -## Library Processing - -If at some point in the future new upload types are required, let's talk about -where the current types are used. - -Upload types are defined in `configs.go`. Where possible, type aliases are -preferred. Structs can be used when multiple fields are required. - -The main usage of the upload types happens in `UploadFiles`. It switches on each -file's type in order to determine how to upload it. Files that aren't uploaded -(file IDs, URLs) are converted back into strings and passed through as strings -into the correct field. Uploaded types are processed as needed (opening files, -etc.) and written into the form using a copy approach in a goroutine to reduce -memory usage. - -In addition to `UploadFiles`, there's more processing of upload types in the -`prepareInputMediaParam` and `prepareInputMediaFile` functions. These look at -the `InputMedia` types to determine which files are uploaded and which are -passed through as strings. They only need to be aware of which files need to be -replaced with `attach://` fields.