ActiveNotifier
Notify message through webhooks.
Installation
Add this line to your application's Gemfile:
gem 'active_notifier'
And then execute:
$ bundle
Or install it yourself as:
$ gem install active_notifier
Usage
Basic
ActiveNotifer.config.channel_tokens = { default: "xxx" }
ActiveNotifier.exec(:default)
# This will notifier message, use options:
# token: config.channel_tokens[:default],
# template: "#{config.template_home}/default.*.erb"
ActiveNotifier.exec(:default, template: "orders/create")
# Use specific template file but not get by channel
# This will notifier message, use options:
# token: config.channel_tokens[:default],
# template: "#{config.template_home}/orders/create.*.erb"
ActiveNotifier.exec(:default, token: "special_token", data: { title: "Title", message: "Message" })
# Use specific token but not get by channel
# This will notifier message, use options:
# token: "special_token",
# template: "#{config.template_home}/default.*.erb"
# And the Hash data will inject to template, and get a dynamic message after parse template
Use custom template
Set token and template home for Rails application
ActiveNotifier.configure do |config|
config.channel_tokens = { default: "xxx" }
config.template_home = Rails.root.join("app", "views", "active_notifier")
end
Set the default message template
app/views/active_notifier/default.markdown.erb
## #{data[:title]}
> #{data[:message]}
Notify message
ActiveNotifier.exec(:default, data: { title: "Title", message: "Message" }) # => Notifer OK
Send message with dynamic type
Message type will dynamic set according by valid template files, when we
set a template named order.text.erb
ActiveNotifier.configure do |config|
config.channel_tokens = { order: "xxx" }
config.template_home = Rails.root.join("app", "views", "active_notifier")
app/views/active_notifier/order.text.erb
title: #{data[:title]}
message: #{data[:message]}
When there is only text type template for order, it will be OK the notify message without set type option
ActiveNotifier.exec(:default, data: { title: "Title", message: "Message" }) # => Notifer message OK
Also, even though there are multiple types templates, like both order.text.erb and order.markdown.erb
are exist, we still can make it OK which no need for type option, just
set the priority type
app/views/active_notifier/order.text.erb
title: #{data[:title]}
message: #{data[:message]}
app/views/active_notifier/order.markdown.erb
## #{data[:title]}
> #{data[:message]}
# default priority_type is :markdown
ActiveNotifer.config.priority_type = :text
# Now this will choose text by default
ActiveNotifier.exec(:default, data: { title: "Title", message: "Message" }) # => Notifer message OK by text type template
Set a short constant to notify(Rails initializer will set this by default)
ActiveNotifer.config.const_name = :Notifier
Notifer.exec(...)
Other
See complete abilities of ActiveNotifier, please follow Spec files
Development
After checking out the repo, run bin/setup to install dependencies. 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.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/pinewong/active_notifier. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Code of Conduct
Everyone interacting in the ActiveNotifier project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.