Skip to content

Instantly share code, notes, and snippets.

@bibendi
Last active September 16, 2020 22:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bibendi/47354184dd053026cc5b to your computer and use it in GitHub Desktop.
Save bibendi/47354184dd053026cc5b to your computer and use it in GitHub Desktop.
Ruby CLI tool for sending notifications to Telegram
#!/usr/bin/env ruby
require 'optparse'
options = {}
opt_parser = OptionParser.new do |opt|
opt.banner = 'Usage: tgnotify [OPTIONS] text'
opt.separator ''
opt.separator 'CLI tool for sending notifications to Telegram'
opt.separator 'version: 0.1.0'
opt.separator '(c) Mihail Merkushin, 2016'
opt.separator ''
opt.separator 'deps: gem install telegram-bot-ruby'
opt.separator ''
opt.separator 'Options'
opt.on('-h', '--help', 'help') do
puts opt_parser
exit
end
opt.on('-t', '--token TOKEN', 'bot auth token') do |value|
options[:token] = value
end
opt.on('-c', '--chat-id CHAT_ID', 'chat id') do |value|
options[:chat_id] = value
end
end
opt_parser.parse!
require 'telegram/bot'
Telegram::Bot::Client.run(options.fetch(:token)) do |bot|
bot.api.send_message(
chat_id: Integer(options.fetch(:chat_id)),
text: ARGV[0]
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment