Beispiel #1
0
 @Override
 protected void onEvent(EventTemplate event) {
   if (event instanceof MessageEvent) {
     MessageEvent mail = (MessageEvent) event;
     try {
       send(mail.getFrom(), mail.getTo(), null, mail.getText());
     } catch (MessagingException ex) {
       this.notifyCriticalError(
           "Error while sending email to " + mail.getTo() + ": " + ex.getMessage());
     }
   }
 }
Beispiel #2
0
  @Override
  protected void onCommand(Command c) throws IOException, UnableToExecuteException {
    // receives a command for notifying a user.
    for (String username : c.getProperty("notify.users").split(",")) {
      // user has to be a Person envobject, as we're using his property behavior

      for (EnvObjectLogic person : getApi().things().findByName(username)) {
        if (person instanceof GenericPerson) {
          MessageEvent mess = new MessageEvent(null, c.getProperty("push.message"));
          mess.setType("notify.user." + username);

          // insert command properties
          for (Entry<Object, Object> prop : c.getProperties().entrySet()) {
            mess.addProperty("reason." + prop.getKey().toString(), prop.getValue().toString());
          }

          // enriches event and sent it to the user's message channel
          PropertiesBehaviorLogic props =
              (PropertiesBehaviorLogic) person.getBehavior("properties");
          for (String prop : props.getPojo().getPropertiesName()) {
            mess.addProperty("user." + prop, props.getPojo().getProperty(prop));
          }

          mess.addProperty("user.activity", person.getBehavior("activity").getValueAsString());
          mess.addProperty("user.present", person.getBehavior("present").getValueAsString());

          notifyEvent(mess);
        }
      }
    }
    // after that, we use reactions to define notification rules
    // like: if user (receives a message AND) is online  -> speak the message loud
    // or:   if user (receives a message AND) is offline -> send him a notification through his
    // preferred provider
  }