Created
April 14, 2016 17:29
-
-
Save barbaramartina/2bc5f8297a0ed378fa24acf4c3b5a5c9 to your computer and use it in GitHub Desktop.
GiveMeFoodBot: A humble bot for Telegram in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'telegram/bot' | |
require 'google_places' | |
token = 'YOUR-TOKEN-FOR-BOT' | |
@googleClient = GooglePlaces::Client.new('YOUR-GOOGLE-PLACES-TOKEN') | |
Telegram::Bot::Client.run(token) do |bot| | |
bot.listen do |message| | |
if message.location | |
l = message.location | |
restaurants = @googleClient.spots(l.latitude, l.longitude, :types => ['restaurant','food'], :radius => 500) | |
for r in restaurants | |
bot.api.send_location(chat_id: message.chat.id, latitude: r.lat, longitude: r.lng) | |
end | |
end | |
case message.text | |
when '/food' | |
kb = [Telegram::Bot::Types::KeyboardButton.new(text: 'Show me your location', request_location: true)] | |
markup = Telegram::Bot::Types::ReplyKeyboardMarkup.new(keyboard: kb) | |
bot.api.send_message(chat_id: message.chat.id, text: 'Hey!', reply_markup: markup) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment