2022-04-26 00:02:51 +08:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2024-04-08 16:50:37 +08:00
|
|
|
"encoding/json"
|
2022-04-26 00:02:51 +08:00
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
type InputFileType int
|
|
|
|
|
2022-04-29 17:21:42 +08:00
|
|
|
// InputFile https://core.telegram.org/bots/api#inputfile
|
2022-04-26 00:02:51 +08:00
|
|
|
type InputFile interface {
|
|
|
|
inputFileTag()
|
|
|
|
}
|
|
|
|
|
|
|
|
type InputFileUpload struct {
|
|
|
|
Filename string
|
|
|
|
Data io.Reader
|
|
|
|
}
|
|
|
|
|
2024-04-08 16:50:37 +08:00
|
|
|
func (*InputFileUpload) inputFileTag() {}
|
2022-04-26 00:02:51 +08:00
|
|
|
|
|
|
|
func (i *InputFileUpload) MarshalJSON() ([]byte, error) {
|
|
|
|
return []byte(`"@` + i.Filename + `"`), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type InputFileString struct {
|
|
|
|
Data string
|
|
|
|
}
|
|
|
|
|
2024-04-08 16:50:37 +08:00
|
|
|
func (*InputFileString) inputFileTag() {}
|
2022-04-26 00:02:51 +08:00
|
|
|
|
|
|
|
func (i *InputFileString) MarshalJSON() ([]byte, error) {
|
|
|
|
return []byte(`"` + i.Data + `"`), nil
|
|
|
|
}
|
2024-04-08 16:50:37 +08:00
|
|
|
|
|
|
|
func (i *InputFileString) UnmarshalJSON(data []byte) error {
|
|
|
|
return json.Unmarshal(data, &i.Data)
|
|
|
|
}
|