Skip to content

Instantly share code, notes, and snippets.

@barbaramartina
Created April 14, 2016 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barbaramartina/2bc5f8297a0ed378fa24acf4c3b5a5c9 to your computer and use it in GitHub Desktop.
Save barbaramartina/2bc5f8297a0ed378fa24acf4c3b5a5c9 to your computer and use it in GitHub Desktop.
GiveMeFoodBot: A humble bot for Telegram in Ruby
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