Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Public Libs
Elixir
Notification Dispatcher
Commits
5501a21c
Commit
5501a21c
authored
Oct 29, 2020
by
Miguel Basticioto
Browse files
chore: readme atualizado
parent
287cadf3
Changes
1
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
5501a21c
# 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
[
a
vailable in Hex
](
https://hex.pm/
docs/publish
)
, th
e
package can be installed
[
A
vailable in Hex
](
https://hex.pm/
packages/notification_dispatcher
)
, th
is
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
)
```
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment