Commit 5b349673 authored by Miguel Basticioto's avatar Miguel Basticioto
Browse files

feat: notification service

parent 3df0c882
defmodule NotificationDispatcher.Service.NotificationService do
@moduledoc """
This module has every function responsible for sending the different types of email on the application
"""
alias NotificationDispatcher.Context.NotificationsContext
def send_notification(user_id, to, type, params, language, device_id \\ nil) do
notification = NotificationsContext.get_by_type_and_language(type, language)
notification = if notification == nil do
NotificationsContext.get_by_type(type)
else
notification
end
if notification != nil do
offsets = Poison.decode!(notification.dispatch_offsets)
Enum.each(
offsets,
fn offset ->
time_now = NaiveDateTime.local_now
time_now = Timex.shift(time_now, minutes: offset)
content = Poison.encode!(
%{
user_id: user_id,
title: notification.title,
message: notification.message,
email: to,
device_id: device_id,
fcm_token: to,
locale: language,
channel: notification.channel,
params: params,
dispatched_at: time_now,
type: type
}
)
NotificationDispatcher.Sender.send_message("notification_exchange", content, offset)
end
)
else
:template_not_found_error
end
end
end
......@@ -22,7 +22,9 @@ defmodule NotificationDispatcher.MixProject do
defp deps do
[
{:ecto_sql, "~> 3.1"},
{:amqp, "~> 1.6.0"}
{:amqp, "~> 1.6.0"},
{:poison, "~> 3.1"},
{:timex, "~> 3.5"},
]
end
end
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