Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
chatbot_helper-telegram
Advanced tools
ChatbotHelper::Telegram
helps you build awesome Telegram chatbots without bothering much about the documentation, the message structure or other details. It is a wrapper around the Telegram Bot API.
Add this line to your application's Gemfile:
gem 'chatbot_helper-telegram'
And then execute:
$ bundle
Or install it yourself as:
$ gem install chatbot_helper-telegram
Then require it and you are good to go:
require 'chatbot_helper/telegram'
As of now, you are responsible for getting messages or other objects from the Telegram Bot API with your favorite HTTP library. We consider adding all Bot API methods to this library in one of the next versions. Please open an issue if you think that's a good idea.
An example with typhoeus:
require 'typhoeus'
require 'chatbot_helper/telegram'
require 'json'
# Your environment must have set the `TELEGRAM_TOKEN` key to your telegram api
# token. See https://core.telegram.org/bots#3-how-do-i-create-a-bot for more
# information.
telegram_token = ENV['TELEGRAM_TOKEN']
url = "https://api.telegram.org/bot#{telegram_token}/sendMessage"
# We create a message
message = {
chat_id: 123456,
text: "This is an example message sent by my telegram bot"
}
request = Typhoeus::Request.new(
url,
method: :post,
body: JSON.generate(message),
headers: { 'Content-Type' => 'application/json' }
)
request.run
body = request.response.body
# We create a Message object from the response body
message = ChatbotHelper::Telegram::Message.new(string: body)
# Now you can access all properties of the message object
puts message.date
puts message.from.first_name
# Yay!
The real power of this library is the update and command parsing.
Say, for example, you have set up webhooks and you want to parse the updates retrieved from these webhook requests. This is a sinatra example but you can easily convert it to Rails code.
require 'sinatra'
require 'chatbot_helper/telegram'
require 'json'
post "/#{ENV['TELEGRAM_TOKEN']}/?" do
request.body.rewind
payload_body = request.body.read
# Create an instance of Update from the request body...
update = ChatbotHelper::Telegram::Update.new(string: payload_body)
# Return a message based on the given command
message = {}
if update.message
# Access the chat id through the given message
message[:chat_id] = update.message.chat.id
case update.message.text
when '/start'
text = "Hello and welcome to my awesome bot #{update.chat.first_name}!"
message[:text] = text
when '/saysomething'
text = "Why should I talk with you, #{update.chat.first_name}? Give me "\
"a reason!"
message[:text] = text
end
# Return the message which should be sent
return halt 200, { 'Content-Type' => 'application/json' }, JSON.generate(message)
end
# Fallback, return nothing
return halt 200, { 'Content-Type' => 'application/json' }, '{}'
end
You can work with nearly all Telegram Bot API available types.
One exception are the Inline mode
types which has currently just partial support and will be fully available in the next version.
If you need help or have a feature request feel free and open an issue.
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/Ybrin/chatbot_helper-telegram.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that chatbot_helper-telegram 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.