Media Groups

As you know, Telegram have the feature named Media Groups. Media groups have several differences with the common messages:

Specific of media groups in libraries

Row updates
In tgbotapi there is no any additional handling of media groups by default and in case you will use simple bot.getUpdates, you will get the list of row updates and media groups will be included in this list as separated messages with MediaGroupPartContent. In that case you may use convertWithMediaGroupUpdates to be able to work with media groups as will be described below

In case you are using standard long polling (one of alternatives is telegramBotWithBehaviourAndLongPolling) or webhooks updates will be converted uner the hood and as a result, you will take media groups as a content in one message:

telegramBotWithBehaviourAndLongPolling(
  "token"
) {
  onVisualGallery { // it: CommonMessage<MediaGroupContent<VisualMediaGroupPartContent>>
    it.content // MediaGroupContent<VisualMediaGroupPartContent>
    it.content.group // List<MediaGroupCollectionContent.PartWrapper<VisualMediaGroupPartContent>>
    it.content.group.forEach { // it: MediaGroupCollectionContent.PartWrapper<VisualMediaGroupPartContent>
      it.messageId // source message id for current media group part
      it.sourceMessage // source message for current media group part
      it.content // VisualMediaGroupPartContent
      println(it.content) // will print current content part info
    }
  }
}

KDocs:

In two words, in difference with row Telegram Bot API, you will take media groups in one message instead of messages list.


Revision #1
Created 8 November 2022 20:00:43 by InsanusMokrassar
Updated 9 November 2022 05:20:48 by InsanusMokrassar