|
I am trying to send multiple media files (e.g., images) in a single post using MessagesSendMultiMedia, but I keep getting the error: _, err = v1.tgBot.Client.API().MessagesSendMultiMedia(context.Background(), &tg.MessagesSendMultiMediaRequest{ What I Tried:
|
Replies: 16 comments
|
before using MessagesSendMultiMedia you should upload all files to telegram, please check docs before creating a issue https://core.telegram.org/methods |
|
@borzovplus I checked this and studied the documentation, but I still face the same problem. Have you tried using multiMedia yourself, if you know, can you please show me? |
|
I can not to show, because I have a lot of abstractions (to much codes). |
|
func UploadFile(ctx context.Context, client *telegram.Client, filePath string) (tg.InputFileClass, []byte, error) { } @borzovplus Yes, I am using the same uploader package, but still no result. |
|
no, I still haven't found a solution. If you know a solution, please help @shampigeon |
|
To make it work you should: Looks like this, removed some error handling from the code. multimedia := make([]tg.InputSingleMedia, 0, len(images))
for i := range images {
resp, err := api.MessagesUploadMedia(ctx, &tg.MessagesUploadMediaRequest{
Peer: outputPeer,
Media: &tg.InputMediaUploadedPhoto{
File: images[i],
},
})
mediaPhoto := resp.(*tg.MessageMediaPhoto)
photo := mediaPhoto.Photo.(*tg.Photo)
multimedia = append(multimedia, tg.InputSingleMedia{
Media: &tg.InputMediaPhoto{
ID: &tg.InputPhoto{
ID: photo.ID,
AccessHash: photo.AccessHash,
FileReference: photo.FileReference,
},
},
RandomID: rand.Int63()
})
}
_, err := api.MessagesSendMultiMedia(ctx, &tg.MessagesSendMultiMediaRequest{
Peer: outputPeer,
MultiMedia: multimedia,
})Figured it out from this comment: alik0211/mtproto-core#148 (comment) |
|
For
Reference: https://core.telegram.org/method/messages.sendMultiMedia So this will fail with tg.InputSingleMedia{
Media: &tg.InputMediaUploadedPhoto{File: inputFile},
}The media has to be uploaded/associated first, then converted to an If you use the higher-level sender := message.NewSender(api).Resolve(peer)
_, err := sender.Album(ctx,
message.UploadedPhoto(file1, message.Text("first caption")),
message.UploadedPhoto(file2),
)Internally, If using the raw generated API, the flow should look like this: media := make([]tg.InputSingleMedia, 0, len(files))
for _, file := range files {
uploaded, err := api.MessagesUploadMedia(ctx, &tg.MessagesUploadMediaRequest{
Peer: peer,
Media: &tg.InputMediaUploadedPhoto{
File: file,
},
})
if err != nil {
return err
}
photoMedia, ok := uploaded.(*tg.MessageMediaPhoto)
if !ok {
return fmt.Errorf("unexpected media type %T", uploaded)
}
photo, ok := photoMedia.Photo.AsNotEmpty()
if !ok {
return fmt.Errorf("unexpected empty photo")
}
media = append(media, tg.InputSingleMedia{
Media: &tg.InputMediaPhoto{
ID: photo.AsInput(),
},
RandomID: rand.Int63(),
})
}
_, err := api.MessagesSendMultiMedia(ctx, &tg.MessagesSendMultiMediaRequest{
Peer: peer,
MultiMedia: media,
})No |
For
messages.sendMultiMedia, Telegram does not accept rawinputMediaUploaded*constructors directly inmulti_media. The official docs now state this explicitly:Reference: https://core.telegram.org/method/messages.sendMultiMedia
So this will fail with
MEDIA_INVALID:The media has to be uploaded/associated first, then converted to an
InputMediaPhotoorInputMediaDocumentand passed tomessages.sendMultiMedia.If you use the higher-level
telegram/message…