
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
A tiny but easy-to-use wrapper of Telegram Bot API.
gem install tgbot
Tgbot.run TOKEN, proxy: 'http://127.0.0.1:1080' do
@name = get_me&.result&.first_name
on 'start' do
reply "#@name, at your service."
end
end
# or
bot = Tgbot.new TOKEN, proxy: 'http://127.0.0.1:1080'
bot.on('start'){ reply "#{get_me&.result&.first_name}, at your service." }
bot.run # will block current thread
Tgbot.run token, **options do (block) end
Start a long polling bot.
argument | type | notes | example |
---|---|---|---|
token | String | ask BotFather for one | '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11' |
option | type | notes | example |
---|---|---|---|
proxy | String | http only | '127.0.0.1:1080' |
and in that (block)
:
Just call the native bot api. e.g. getMe()
send_message(chat_id: 123, text: 'hello')
.
Returns an OpenStruct of the replied object. Basically struct{ok=true,result=...}
.
self.debug = true | false (default)
Show debug info (every message, matched command).
start do (do sth when it is connected) end
start do
puts "\e[33m#{get_me&.result&.first_name}\e[32m, at your service."
end
finish do (do sth when Ctrl+C) end
finish do
puts "おやすみなさい"
end
on pattern=nil, **options do |match_data, update, task| (block) end
Match pattern and do something.
argument | type | notes | example |
---|---|---|---|
pattern | nil | match all (including inline query etc.) | on do ... end |
- | String | Regexp | match all text1 | /^r(\d*)d(\d*)(?:\+(\d*))?/ |
1: for convenience, the bot's @username
is trimmed for easilier matching.
e.g. "hey bot, /r3d6@mybot+1 lol" => #<MatchData "/r3d6+1" 1:"3" 2:"6" 3:"1">
.
option | type | notes | example |
---|---|---|---|
name | String | just give it a name | 'roll!' |
before_all | true | set to run before other on s matching the same message | true |
after_all | true | set to run after other on s matching the same message2you can't set both before_all and after_all on one command | true |
2: order is * -> before2 -> before1 -> other -> after1 -> after2 -> *
.
and in that (block)
:
debug message
Puts that message to STDERR when it is in debug mode.
reply *things, **options
Reply to the matched message.
argument | type | notes | example |
---|---|---|---|
thing | String | can .to_s | will use parse_mode: Markdown | 'hello world' |
- | IO | will use sendPhoto if it is a photo, etc. | File.new("a.png") |
option | type | notes | example |
---|---|---|---|
media | false | set to false to force sendDocument | '127.0.0.1:1080' |
style | :none | :at | nil (default) | reply style3 | :at |
parse_mode, etc. | depends | see sendMessage | - |
reply style3:
:none
: don't add reply info, so the sender won't receive a prompting.:at
: use [inline mention of a user](tg://user?id=123456789)
in replied message.nil
(default): include reply_to_message_id
in replied message object.interrupt!
done!
Stop processing this message (if there be further blocks matching it). see before_all
after_all
.
retry! n=1
Enqueue this message again for at most n
times.
PRs/issues are welcome.
FAQs
Unknown package
We found that tgbot demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.