ba0f3 / telebot.nim

Async Telegram Bot API Client implement in @Nim-Lang
MIT License
165 stars 24 forks source link

Location must be float #11

Closed juancarlospaco closed 6 years ago

juancarlospaco commented 6 years ago

Location works Ok, but its longitude and latitude must be float, at least rounded floats.

import telebot, asyncdispatch, options

const API_KEY = ""

proc geoHandler(bot: TeleBot): CommandCallback =
  proc cb(e: Command) {.async.} =
    let message = newLocation(e.message.chat.id, longitude=42.9, latitude=42.9)
    discard await bot.send(message)
  result = cb

let bot = newTeleBot(API_KEY)
bot.onCommand("geo", geoHandler(bot))
bot.poll(666)

Produces the error:

nim_telegram_bot.nim(234, 22) template/generic instantiation from here
nim_telegram_bot.nim(145, 23) template/generic instantiation from here
nim_telegram_bot.nim(150, 31) Error: type mismatch: got <longitude: float64, latitude: float64>
but expected one of: 
proc newLocation(chatId: int; latitude: int; longitude: int): LocationObject

expression: newLocation(longitude = 42.9, latitude = 42.9)

Change:

let message = newLocation(e.message.chat.id, longitude=42.9, latitude=42.9)

To:

let message = newLocation(e.message.chat.id, longitude=42, latitude=42)

And it works.

https://core.telegram.org/bots/api#location

0.9 on Latitude or Longitude is a lot of terrain.

Seems kinda easy to fix since change type from int to float. Feel free to use the example code.

Thanks for the epic work on this framework :grey_exclamation: :smiley_cat:

juancarlospaco commented 6 years ago

Yay!, thanks pal :grey_exclamation: :tada::cat::+1: