use of org.traccar.notification.NotificationMessage in project traccar by tananaev.
the class NotificatorFirebase method sendSync.
@Override
public void sendSync(long userId, Event event, Position position) {
final User user = Context.getPermissionsManager().getUser(userId);
if (user.getAttributes().containsKey("notificationTokens")) {
NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short");
Notification notification = new Notification();
notification.title = shortMessage.getSubject();
notification.body = shortMessage.getBody();
notification.sound = "default";
Message message = new Message();
message.tokens = user.getString("notificationTokens").split("[, ]");
message.notification = notification;
Context.getClient().target(url).request().header("Authorization", "key=" + key).async().post(Entity.json(message), new InvocationCallback<Object>() {
@Override
public void completed(Object o) {
}
@Override
public void failed(Throwable throwable) {
LOGGER.warn("Firebase notification error", throwable);
}
});
}
}
use of org.traccar.notification.NotificationMessage in project traccar by tananaev.
the class NotificatorSms method sendAsync.
@Override
public void sendAsync(long userId, Event event, Position position) {
final User user = Context.getPermissionsManager().getUser(userId);
if (user.getPhone() != null) {
NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short");
Main.getInjector().getInstance(StatisticsManager.class).registerSms();
Context.getSmsManager().sendMessageAsync(user.getPhone(), shortMessage.getBody(), false);
}
}
use of org.traccar.notification.NotificationMessage in project traccar by tananaev.
the class NotificatorMail method sendSync.
@Override
public void sendSync(long userId, Event event, Position position) throws MessageException {
try {
NotificationMessage fullMessage = NotificationFormatter.formatMessage(userId, event, position, "full");
Context.getMailManager().sendMessage(userId, fullMessage.getSubject(), fullMessage.getBody());
} catch (MessagingException e) {
throw new MessageException(e);
}
}
use of org.traccar.notification.NotificationMessage in project traccar by tananaev.
the class NotificatorPushover method sendSync.
@Override
public void sendSync(long userId, Event event, Position position) {
final User user = Context.getPermissionsManager().getUser(userId);
String device = "";
if (user.getAttributes().containsKey("notificator.pushover.device")) {
device = user.getString("notificator.pushover.device").replaceAll(" *, *", ",");
}
if (token == null) {
LOGGER.warn("Pushover token not found");
return;
}
if (this.user == null) {
LOGGER.warn("Pushover user not found");
return;
}
NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short");
Message message = new Message();
message.token = token;
message.user = this.user;
message.device = device;
message.title = shortMessage.getSubject();
message.message = shortMessage.getBody();
Context.getClient().target(url).request().async().post(Entity.json(message), new InvocationCallback<Object>() {
@Override
public void completed(Object o) {
}
@Override
public void failed(Throwable throwable) {
LOGGER.warn("Pushover API error", throwable);
}
});
}
use of org.traccar.notification.NotificationMessage in project traccar by tananaev.
the class NotificatorSms method sendSync.
@Override
public void sendSync(long userId, Event event, Position position) throws MessageException, InterruptedException {
final User user = Context.getPermissionsManager().getUser(userId);
if (user.getPhone() != null) {
NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short");
Main.getInjector().getInstance(StatisticsManager.class).registerSms();
Context.getSmsManager().sendMessageSync(user.getPhone(), shortMessage.getBody(), false);
}
}
Aggregations