From 9d8b1845c4f3652ceb01cb69ff21fa32c785c983 Mon Sep 17 00:00:00 2001 From: Nick Schwaderer Date: Fri, 10 Aug 2018 15:53:59 +0100 Subject: [PATCH 1/2] Include location data sent to Bot This PR includes locations sharing from the user to the bot. The workflow is when clicking 'Send my current location' a new message is sent to the bot with latitude and longitude accessed via `my_message.location`. To get the coordinates in an array, this can be accessed via `my_message.location.full`. Original api discussion [here](https://core.telegram.org/bots/api#location). This PR does *not* implement sharing of live locations, which are [implemented in a wholly different manner](https://telegram.org/blog/live-locations) by nesting the information within `edited_message`. To include live locations we would also need to bring in the `edited_message` functionality. I will be approaching this with my next PR. --- lib/telegram_bot.rb | 1 + lib/telegram_bot/location.rb | 11 +++++++++++ lib/telegram_bot/message.rb | 1 + 3 files changed, 13 insertions(+) create mode 100644 lib/telegram_bot/location.rb diff --git a/lib/telegram_bot.rb b/lib/telegram_bot.rb index 6e9b937..ccf4723 100644 --- a/lib/telegram_bot.rb +++ b/lib/telegram_bot.rb @@ -18,6 +18,7 @@ require "telegram_bot/api_response" require "telegram_bot/bot" require "telegram_bot/client" +require "telegram_bot/location" module TelegramBot diff --git a/lib/telegram_bot/location.rb b/lib/telegram_bot/location.rb new file mode 100644 index 0000000..d537e1e --- /dev/null +++ b/lib/telegram_bot/location.rb @@ -0,0 +1,11 @@ +module TelegramBot + class Location + include Virtus.model + attribute :latitude, Float + attribute :longitude, Float + + def full + [latitude, longitude] + end + end +end diff --git a/lib/telegram_bot/message.rb b/lib/telegram_bot/message.rb index 078edd6..b34bd42 100644 --- a/lib/telegram_bot/message.rb +++ b/lib/telegram_bot/message.rb @@ -10,6 +10,7 @@ class Message attribute :date, DateTime attribute :chat, Channel attribute :reply_to_message, Message + attribute :location, Location def reply(&block) reply = OutMessage.new(chat: chat) From a70cc453a8918bd987dad8a4bc16bd01b9e89ff7 Mon Sep 17 00:00:00 2001 From: Nick Schwaderer Date: Sat, 1 Sep 2018 13:36:24 +0100 Subject: [PATCH 2/2] Reorder requirements for message to access location --- lib/telegram_bot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/telegram_bot.rb b/lib/telegram_bot.rb index ccf4723..7cb169e 100644 --- a/lib/telegram_bot.rb +++ b/lib/telegram_bot.rb @@ -8,6 +8,7 @@ require "telegram_bot/user" require "telegram_bot/group_chat" require "telegram_bot/channel" +require "telegram_bot/location" require "telegram_bot/message" require "telegram_bot/keyboard" require "telegram_bot/reply_keyboard_hide" @@ -18,7 +19,6 @@ require "telegram_bot/api_response" require "telegram_bot/bot" require "telegram_bot/client" -require "telegram_bot/location" module TelegramBot