Last active
September 16, 2020 22:36
-
-
Save bibendi/47354184dd053026cc5b to your computer and use it in GitHub Desktop.
Ruby CLI tool for sending notifications to Telegram
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
#!/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