Commit 5501a21c authored by Miguel Basticioto's avatar Miguel Basticioto
Browse files

chore: readme atualizado

parent 287cadf3
# NotificationDispatcher
**TODO: Add description**
This lib is used to send notification events to a rabbitmq queue server. It contains methods
to create the necessary database structures, for example the notification_messages table or
the devices table to store the tokens necessary for push notification.
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
[Available in Hex](https://hex.pm/packages/notification_dispatcher), this package can be installed
by adding `notification_dispatcher` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:notification_dispatcher, "~> 0.1.0"}
{:notification_dispatcher, "~> 0.1.3"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/notification_dispatcher](https://hexdocs.pm/notification_dispatcher).
Create the following config on your project:
```elixir
config :notification_dispatcher,
rabbitmq_host: "localhost",
rabbitmq_username: "guest",
rabbitmq_password: "guest",
repo: MyApp.Repo
```
To store your notification_messages templates you need a migration that calls the following method:
```elixir
import NotificationDispatcher.Migration
def change do
create_notification_messages()
end
```
If your project requires push notifications by using firebase you need to crate a migration
that calls the following method:
```elixir
import NotificationDispatcher.Migration
def change do
create_notification_messages()
end
```
You can use the following method to register notification templates on your database:
```elixir
alias NotificationDispatcher.Controller.NotificationMessageController
NotificationMessageController.create(
%{
"title" => "title",
"message" => "message",
"notification_type" => 0,
"channel" => 0,
"locale" => "en",
"dispatch_offsets" => "[0]"
}
)
```
This method can return:
```elixir
{:ok, notification_message, json}
```
or
```elixir
{:error, changeset}
```
You can use the following method to create user_devices if your project requires it:
```elixir
alias NotificationDispatcher.Context.NotificationContext
NotificationContext.create_device(
%{
"device_token" => "firebase_token_of_user",
"os" => "android"
},
user_id
)
```
If you have the necessity you can also get all devices by user by using the following method:
```elixir
alias NotificationDispatcher.Context.NotificationContext
NotificationContext.get_devices(user_ids)
```
To send a notification event to the rabbitmq queue you can call the following method:
```elixir
alias NotificationDispatcher.Service.NotificationService
NotificationService.send_notification(
user_id,
device_token_or_email,
notification_type,
params,
language,
device_id
)
```
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment