Search in sources :

Example 1 with User

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;
    }
}
Also used : User(org.finos.symphony.toolkit.workflow.content.User) Word(org.finos.symphony.toolkit.workflow.content.Word) Message(org.finos.symphony.toolkit.workflow.content.Message) SimpleMessageAction(org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)

Example 2 with User

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);
    }
}
Also used : EntityJson(org.finos.symphony.toolkit.json.EntityJson) User(org.finos.symphony.toolkit.workflow.content.User) ActionConsumer(org.finos.symphony.toolkit.workflow.actions.consumers.ActionConsumer) Errors(org.springframework.validation.Errors) Button(org.finos.symphony.toolkit.workflow.form.Button) V4SymphonyElementsAction(com.symphony.api.model.V4SymphonyElementsAction) FormAction(org.finos.symphony.toolkit.workflow.actions.FormAction) Addressable(org.finos.symphony.toolkit.workflow.content.Addressable) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) Map(java.util.Map) ErrorMap(org.finos.symphony.toolkit.workflow.form.ErrorMap)

Example 3 with User

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;
}
Also used : User(org.finos.symphony.toolkit.workflow.content.User) ChatRequest(org.finos.symphony.toolkit.workflow.annotations.ChatRequest)

Example 4 with User

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;
}
Also used : User(org.finos.symphony.toolkit.workflow.content.User) ChatRequest(org.finos.symphony.toolkit.workflow.annotations.ChatRequest)

Example 5 with User

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;
}
Also used : Arrays(java.util.Arrays) ButtonList(org.finos.symphony.toolkit.workflow.form.ButtonList) User(org.finos.symphony.toolkit.workflow.content.User) SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) WorkMode(org.finos.symphony.toolkit.workflow.annotations.WorkMode) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) ArrayList(java.util.ArrayList) ResponseHandlers(org.finos.symphony.toolkit.workflow.response.handlers.ResponseHandlers) Conversations(org.finos.symphony.toolkit.workflow.conversations.Conversations) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton) ErrorMap(org.finos.symphony.toolkit.workflow.form.ErrorMap) Type(org.finos.symphony.toolkit.workflow.form.Button.Type) TaskScheduler(org.springframework.scheduling.TaskScheduler) Chat(org.finos.symphony.toolkit.workflow.content.Chat) UUID(java.util.UUID) Button(org.finos.symphony.toolkit.workflow.form.Button) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) History(org.finos.symphony.toolkit.workflow.history.History) List(java.util.List) ChatRequest(org.finos.symphony.toolkit.workflow.annotations.ChatRequest) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ChatResponseBody(org.finos.symphony.toolkit.workflow.annotations.ChatResponseBody) StringUtils(org.springframework.util.StringUtils) User(org.finos.symphony.toolkit.workflow.content.User) HashTag(org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton) Button(org.finos.symphony.toolkit.workflow.form.Button) WorkResponse(org.finos.symphony.toolkit.workflow.response.WorkResponse) ButtonList(org.finos.symphony.toolkit.workflow.form.ButtonList) ChatButton(org.finos.symphony.toolkit.workflow.annotations.ChatButton)

Aggregations

User (org.finos.symphony.toolkit.workflow.content.User)11 SimpleMessageAction (org.finos.symphony.toolkit.workflow.actions.SimpleMessageAction)5 EntityJson (org.finos.symphony.toolkit.json.EntityJson)4 Addressable (org.finos.symphony.toolkit.workflow.content.Addressable)4 Chat (org.finos.symphony.toolkit.workflow.content.Chat)4 Message (org.finos.symphony.toolkit.workflow.content.Message)4 SymphonyRoom (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyRoom)4 SymphonyUser (org.finos.symphony.toolkit.workflow.sources.symphony.content.SymphonyUser)4 FormAction (org.finos.symphony.toolkit.workflow.actions.FormAction)3 WorkResponse (org.finos.symphony.toolkit.workflow.response.WorkResponse)3 HashTag (org.finos.symphony.toolkit.workflow.sources.symphony.content.HashTag)3 SymphonyIdentity (com.symphony.api.id.SymphonyIdentity)2 MembershipList (com.symphony.api.model.MembershipList)2 StreamAttributes (com.symphony.api.model.StreamAttributes)2 StreamList (com.symphony.api.model.StreamList)2 StreamType (com.symphony.api.model.StreamType)2 V3RoomAttributes (com.symphony.api.model.V3RoomAttributes)2 V3RoomDetail (com.symphony.api.model.V3RoomDetail)2 V3RoomSearchResults (com.symphony.api.model.V3RoomSearchResults)2 ArrayList (java.util.ArrayList)2