Add initial support for sendMediaGroup.
parent
7ff5871e28
commit
898e79fe47
14
bot_test.go
14
bot_test.go
|
@ -519,6 +519,20 @@ func TestUpdatesChan(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSendWithMediaGroup(t *testing.T) {
|
||||
bot, _ := getBot(t)
|
||||
|
||||
cfg := tgbotapi.NewMediaGroup(ChatID, []interface{}{
|
||||
tgbotapi.NewInputMediaPhoto("https://i.imgur.com/unQLJIb.jpg"),
|
||||
tgbotapi.NewInputMediaPhoto("https://i.imgur.com/J5qweNZ.jpg"),
|
||||
tgbotapi.NewInputMediaVideo("https://i.imgur.com/F6RmI24.mp4"),
|
||||
})
|
||||
_, err := bot.Send(cfg)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleNewBotAPI() {
|
||||
bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken")
|
||||
if err != nil {
|
||||
|
|
26
configs.go
26
configs.go
|
@ -657,6 +657,32 @@ func (config VoiceConfig) method() string {
|
|||
return "sendVoice"
|
||||
}
|
||||
|
||||
// MediaGroupConfig contains information about a sendMediaGroup request.
|
||||
type MediaGroupConfig struct {
|
||||
BaseChat
|
||||
InputMedia []interface{}
|
||||
}
|
||||
|
||||
func (config MediaGroupConfig) values() (url.Values, error) {
|
||||
v, err := config.BaseChat.values()
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
|
||||
data, err := json.Marshal(config.InputMedia)
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
|
||||
v.Add("media", string(data))
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (config MediaGroupConfig) method() string {
|
||||
return "sendMediaGroup"
|
||||
}
|
||||
|
||||
// LocationConfig contains information about a SendLocation request.
|
||||
type LocationConfig struct {
|
||||
BaseChat
|
||||
|
|
28
helpers.go
28
helpers.go
|
@ -18,6 +18,7 @@ func NewMessage(chatID int64, text string) MessageConfig {
|
|||
}
|
||||
}
|
||||
|
||||
// NewDeleteMessage creates a request to delete a message.
|
||||
func NewDeleteMessage(chatID int64, messageID int) DeleteMessageConfig {
|
||||
return DeleteMessageConfig{
|
||||
ChatID: chatID,
|
||||
|
@ -289,6 +290,33 @@ func NewVoiceShare(chatID int64, fileID string) VoiceConfig {
|
|||
}
|
||||
}
|
||||
|
||||
// NewMediaGroup creates a new media group. Files should be an array of
|
||||
// two to ten InputMediaPhoto or InputMediaVideo.
|
||||
func NewMediaGroup(chatID int64, files []interface{}) MediaGroupConfig {
|
||||
return MediaGroupConfig{
|
||||
BaseChat: BaseChat{
|
||||
ChatID: chatID,
|
||||
},
|
||||
InputMedia: files,
|
||||
}
|
||||
}
|
||||
|
||||
// NewInputMediaPhoto creates a new InputMediaPhoto.
|
||||
func NewInputMediaPhoto(media string) InputMediaPhoto {
|
||||
return InputMediaPhoto{
|
||||
Type: "photo",
|
||||
Media: media,
|
||||
}
|
||||
}
|
||||
|
||||
// NewInputMediaVideo creates a new InputMediaVideo.
|
||||
func NewInputMediaVideo(media string) InputMediaVideo {
|
||||
return InputMediaVideo{
|
||||
Type: "video",
|
||||
Media: media,
|
||||
}
|
||||
}
|
||||
|
||||
// NewContact allows you to send a shared contact.
|
||||
func NewContact(chatID int64, phoneNumber, firstName string) ContactConfig {
|
||||
return ContactConfig{
|
||||
|
|
3
log.go
3
log.go
|
@ -1,13 +1,14 @@
|
|||
package tgbotapi
|
||||
|
||||
import (
|
||||
"os"
|
||||
"errors"
|
||||
stdlog "log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var log = stdlog.New(os.Stderr, "", stdlog.LstdFlags)
|
||||
|
||||
// SetLogger specifies the logger that the package should use.
|
||||
func SetLogger(newLog *stdlog.Logger) error {
|
||||
if newLog == nil {
|
||||
return errors.New("logger is nil")
|
||||
|
|
21
types.go
21
types.go
|
@ -524,6 +524,27 @@ func (info WebhookInfo) IsSet() bool {
|
|||
return info.URL != ""
|
||||
}
|
||||
|
||||
// InputMediaPhoto contains a photo for displaying as part of a media group.
|
||||
type InputMediaPhoto struct {
|
||||
Type string `json:"type"`
|
||||
Media string `json:"media"`
|
||||
Caption string `json:"caption"`
|
||||
ParseMode string `json:"parse_mode"`
|
||||
}
|
||||
|
||||
// InputMediaVideo contains a video for displaying as part of a media group.
|
||||
type InputMediaVideo struct {
|
||||
Type string `json:"type"`
|
||||
Media string `json:"media"`
|
||||
// thumb intentionally missing as it is not currently compatible
|
||||
Caption string `json:"caption"`
|
||||
ParseMode string `json:"parse_mode"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Duration int `json:"duration"`
|
||||
SupportsStreaming bool `json:"supports_streaming"`
|
||||
}
|
||||
|
||||
// InlineQuery is a Query from Telegram for an inline request.
|
||||
type InlineQuery struct {
|
||||
ID string `json:"id"`
|
||||
|
|
Loading…
Reference in New Issue