Search in sources :

Example 1 with NotificationMessage

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);
            }
        });
    }
}
Also used : User(org.traccar.model.User) NotificationMessage(org.traccar.notification.NotificationMessage) NotificationMessage(org.traccar.notification.NotificationMessage)

Example 2 with NotificationMessage

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);
    }
}
Also used : User(org.traccar.model.User) StatisticsManager(org.traccar.database.StatisticsManager) NotificationMessage(org.traccar.notification.NotificationMessage)

Example 3 with NotificationMessage

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);
    }
}
Also used : NotificationMessage(org.traccar.notification.NotificationMessage) MessagingException(javax.mail.MessagingException) MessageException(org.traccar.notification.MessageException)

Example 4 with NotificationMessage

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);
        }
    });
}
Also used : User(org.traccar.model.User) NotificationMessage(org.traccar.notification.NotificationMessage) NotificationMessage(org.traccar.notification.NotificationMessage)

Example 5 with NotificationMessage

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);
    }
}
Also used : User(org.traccar.model.User) StatisticsManager(org.traccar.database.StatisticsManager) NotificationMessage(org.traccar.notification.NotificationMessage)

Aggregations

NotificationMessage (org.traccar.notification.NotificationMessage)7 User (org.traccar.model.User)6 StatisticsManager (org.traccar.database.StatisticsManager)2 PermitAll (javax.annotation.security.PermitAll)1 MessagingException (javax.mail.MessagingException)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 VelocityContext (org.apache.velocity.VelocityContext)1 MessageException (org.traccar.notification.MessageException)1