rapierorg / telegram-bot-swift

Telegram Bot SDK for Swift (unofficial)
https://github.com/rapierorg/telegram-bot-swift/wiki
Apache License 2.0
375 stars 63 forks source link

Photos are not accessible #41

Closed omidgolparvar closed 6 years ago

omidgolparvar commented 6 years ago

I use following code to get user profile images

router["myPics"] = { context in
    guard let user = context.message?.from else { return false }

    context.bot.getUserProfilePhotosAsync(user_id: user.id, offset: 0, limit: 1) { photos, error in
        print("Photos: \(photos!)")
        print("Photos.Photos.Count: \(photos!.photos.count)")
        print("Photos.Photos: \(photos!.photos)")
        print("Photos.Photos[0]: \(photos!.photos[0])")
        context.respondAsync(":)")
    }
    return true
}

and this is output:

Photos: {
  "photos" : [
    [
      {
        "height" : 160,
        "width" : 160,
        "file_id" : "AgADBAADRKoxG0VZ7AIJ74PFh3c3BEQVvRkABKHMS66iBW_Taw0EAAEC",
        "file_size" : 2966
      },
      {
        "height" : 320,
        "width" : 320,
        "file_id" : "AgADBAADRKoxG0VZ7AIJ74PFh3c3BEQVvRkABDTzf4E6wKqBbA0EAAEC",
        "file_size" : 7288
      },
      {
        "height" : 640,
        "width" : 640,
        "file_id" : "AgADBAADRKoxG0VZ7AIJ74PFh3c3BEQVvRkABE-Dwdi65qtHbQ0EAAEC",
        "file_size" : 14108
      }
    ]
  ],
  "total_count" : 59
}
Photos.Photos.Count: 1
Photos.Photos: [[]]    <====
Photos.Photos[0]: []   <====

photos is array of EMPTY array!

zmeyc commented 6 years ago

Probably a bug in generator. (API/generate_wrappers.rb) It generates these classes from textual API description. As a workaround, json member can be used to access underlying JSON directly.

zmeyc commented 6 years ago

This has been fixed in dev branch (not tagged yet): https://github.com/zmeyc/telegram-bot-swift/commit/9bdb7aed9cb1b96698bf2f719f6f06f5dd46b217 Thank you for reporting!