since v12.13
A UserNotificationOperationBuilder can be used to build a UI notification for a user.
Some examples of methods to create a notification for a user would look like this:
import java.time.Duration;
import com.novomind.ecom.api.iagent.action.AgentActionHandler;
import com.novomind.ecom.api.iagent.model.User;
import com.novomind.ecom.api.iagent.operation.notification.UserNotificationOperationBuilder;
import com.novomind.ecom.api.iagent.operation.notification.UserNotificationOperationResult;
@Inject
protected AgentActionHandler agentActionHandler;
public UserNotificationOperationResult notifyAgent(User user, String title, String text) {
try {
UserNotificationOperationBuilder.Growl builder = agentActionHandler.getUserNotificationOperationBuilder(user).growl();
return builder.title(title)
.text(text)
.type(UserNotificationOperationBuilder.Type.INFO)
.duration(Duration.ofMillis(5000L)
.build().execute();
} catch (WrongArgumentException e) {
// WrongArgumentException if the user is not valid (e.g. is not an agent)
} catch (ValidationException e) {
// ValidationException if one of the provided attributes are not valid (e.g. null values)
} catch (OperationFailedException e) {
// OperationFailedException if the operation failed (e.g. user is not logged on as an agent)
}
return null;
}
public UserNotificationOperationResult alertAgent(User user, String text) {
try {
UserNotificationOperationBuilder.Alert builder = agentActionHandler.getUserNotificationOperationBuilder(user).alert();
return builder.text(text)
.duration(Duration.ofMillis(5000L)
.build().execute();
} catch (WrongArgumentException e) {
// WrongArgumentException if the user is not valid (e.g. is not an agent)
} catch (ValidationException e) {
// ValidationException if one of the provided attributes are not valid (e.g. null values)
} catch (OperationFailedException e) {
// OperationFailedException if the operation failed (e.g. user is not logged on as an agent)
}
return null;
}