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

Handling live location updates #89

Closed iSapozhnik closed 4 years ago

iSapozhnik commented 4 years ago

Hey there! I'm note really sure what is the best way to handle live location updates, can somebody help me here?

So what I'm trying to achieve is following: when the user shares his live location I want my bot to do something every time when the location changes. When I just start sharing my live location, first event I can handle by doing

router[.location] = { context in ... }

But when the new location comes I get Unsupported content type. Is there is another way to catch this events except router.unsupportedContentType = { context in } handler?

Thanks in advance.

iSapozhnik commented 4 years ago

@cipi1965 Hey! So here is the JSON when update location event occurs:

{
  "update_id" : 708184783,
  "edited_message" : {
    "chat" : {
      "username" : "iSapozhnik",
      "id" : 38057730,
      "last_name" : "Sapozhnik",
      "type" : "private",
      "first_name" : "Ivan"
    },
    "date" : 1575935185,
    "message_id" : 106,
    "edit_date" : 1575935280,
    "location" : {
      "longitude" : 11.614706999999999,
      "latitude" : 48.138272999999998
    },
    "from" : {
      "username" : "iSapozhnik",
      "id" : 38057730,
      "last_name" : "Sapozhnik",
      "language_code" : "en",
      "is_bot" : false,
      "first_name" : "Ivan"
    }
  }
}

At the moment when I just starting live location sharing I get this:

▿ {
  "update_id" : 708184781,
  "message" : {
    "chat" : {
      "username" : "iSapozhnik",
      "id" : 38057730,
      "last_name" : "Sapozhnik",
      "type" : "private",
      "first_name" : "Ivan"
    },
    "date" : 1575935185,
    "message_id" : 106,
    "location" : {
      "longitude" : 11.614713999999999,
      "latitude" : 48.138297000000001
    },
    "from" : {
      "username" : "iSapozhnik",
      "id" : 38057730,
      "last_name" : "Sapozhnik",
      "language_code" : "en",
      "is_bot" : false,
      "first_name" : "Ivan"
    }
  }
}
cipi1965 commented 4 years ago

@iSapozhnik ok i see, i think i know why it does not work, location type in router consider only message and not edited_message. Tomorrow i will give a look

iSapozhnik commented 4 years ago

@cipi1965 Thanks!