use of org.finos.symphony.toolkit.workflow.content.User in project spring-bot by finos.
the class InRoomAddressingChecker method filter.
public Action filter(Action a) {
if (a.getAddressable() instanceof User) {
// direct message to bot
return a;
}
if (a instanceof SimpleMessageAction) {
SimpleMessageAction sma = (SimpleMessageAction) a;
Optional<User> firstUserMention = sma.getMessage().getNth(User.class, 0);
if ((firstUserMention.isPresent()) && (theBot.matches(firstUserMention.get()))) {
// bot is mentioned, so return the action, stripping out the bot mention
Message changedMessage = (Message) ((SimpleMessageAction) a).getMessage().removeAtStart(firstUserMention.get());
return new SimpleMessageAction(a.getAddressable(), a.getUser(), changedMessage, sma.getData());
}
Optional<Word> firstWord = sma.getMessage().getNth(Word.class, 0);
if (allowSlash && firstWord.isPresent() && firstWord.get().getText().startsWith("/")) {
// we don't actually remove the slash - words will match anyway.
return a;
}
return null;
} else {
// forms, everything else - let them through
return a;
}
}
use of org.finos.symphony.toolkit.workflow.content.User in project spring-bot by finos.
the class ElementsHandler method accept.
@SuppressWarnings("unchecked")
@Override
public void accept(V4Event t) {
try {
V4SymphonyElementsAction action = t.getPayload().getSymphonyElementsAction();
if (action != null) {
Map<String, Object> formValues = (Map<String, Object>) action.getFormValues();
String verb = (String) formValues.get("action");
String formId = action.getFormId();
Object currentForm;
if (hasFormData(formValues)) {
currentForm = formConverter.convert(formValues, formId);
} else {
currentForm = null;
}
EntityJson data = retrieveData(action.getFormMessageId());
Addressable rr = ruBuilder.loadRoomById(action.getStream().getStreamId());
User u = ruBuilder.loadUserById(t.getInitiator().getUser().getUserId());
// if we're not in a room, address the user directly.
rr = rr == null ? u : rr;
Errors e = ErrorHelp.createErrorHolder();
if (validated(currentForm, e)) {
FormAction ea = new FormAction(rr, u, currentForm, verb, data);
try {
Action.CURRENT_ACTION.set(ea);
for (ActionConsumer c : elementsConsumers) {
try {
c.accept(ea);
} catch (Exception ee) {
LOG.error("Failed to handle consumer " + c, ee);
}
}
} finally {
Action.CURRENT_ACTION.set(Action.NULL_ACTION);
}
} else {
WorkResponse fr = new WorkResponse(rr, currentForm, WorkMode.EDIT, ButtonList.of(new Button(verb, Button.Type.ACTION, "Retry")), convertErrorsToMap(e));
rh.accept(fr);
}
}
} catch (Exception e) {
LOG.error("Couldn't handle event " + t, e);
}
}
use of org.finos.symphony.toolkit.workflow.content.User in project spring-bot by finos.
the class ToDoController method complete.
@ChatRequest(value = "complete {items} {by}", description = "Complete items, e.g. \"/complete 1 3 5 @Suresh Rupnar\"")
public ToDoList complete(@ChatVariable("items") List<Word> words, @ChatVariable("by") Optional<User> by, User a, Optional<ToDoList> toDo) {
ToDoList out = toDo.orElse(new ToDoList());
User u = by.orElse(a);
changeStatus(out, words, u, Status.COMPLETE);
return out;
}
use of org.finos.symphony.toolkit.workflow.content.User in project spring-bot by finos.
the class ToDoController method assign.
@ChatRequest(value = "assign {items} {by}", description = "Assign items, e.g. \"/assign 1 3 5 @Suresh Rupnar\"")
public ToDoList assign(@ChatVariable("items") List<Word> words, @ChatVariable("by") Optional<User> by, User a, Optional<ToDoList> toDo) {
ToDoList out = toDo.orElse(new ToDoList());
User u = by.orElse(a);
changeStatus(out, words, u, Status.OPEN);
return out;
}
use of org.finos.symphony.toolkit.workflow.content.User in project spring-bot by finos.
the class PollController method poll.
@ChatButton(buttonText = "start", showWhen = WorkMode.EDIT, value = PollCreateForm.class)
public List<WorkResponse> poll(PollCreateForm cf, Chat r, User a) {
int[] i = { 0 };
List<String> options = Arrays.asList(cf.option1, cf.option2, cf.option3, cf.option4, cf.option5, cf.option6).stream().filter(s -> StringUtils.hasText(s)).collect(Collectors.toList());
ButtonList buttons = new ButtonList(options.stream().map(s -> new Button(PollController.class, "poll" + (i[0]++), Type.ACTION, s)).collect(Collectors.toList()));
HashTag id = new HashTag(UUID.randomUUID().toString());
Poll p = new Poll(options);
p.setPoller(a);
p.setQuestion(cf.getQuestion());
p.setOptions(options);
p.setId(id);
List<User> users = rooms.getChatMembers(r);
List<WorkResponse> out = users.stream().filter(u -> !isMe(u)).map(u -> createResponseForUser(cf, options, id, buttons, u)).collect(Collectors.toList());
out.add(new WorkResponse(r, p, WorkMode.VIEW));
doScheduling(p, cf, r);
return out;
}
Aggregations