use of org.finos.symphony.toolkit.workflow.annotations.ChatButton in project spring-bot by finos.
the class ButtonsResponseHandler method initExposedHandlerMappings.
@SuppressWarnings("unchecked")
protected void initExposedHandlerMappings() {
if (exposedHandlerMappings == null) {
ResolvableType g = ResolvableType.forClassWithGenerics(ChatHandlerMapping.class, ChatButton.class);
exposedHandlerMappings = Arrays.stream(applicationContext.getBeanNamesForType(g)).map(n -> (ChatHandlerMapping<ChatButton>) applicationContext.getBean(n)).collect(Collectors.toList());
}
}
use of org.finos.symphony.toolkit.workflow.annotations.ChatButton in project spring-bot by finos.
the class ClaimController method add.
@ChatButton(value = NewClaim.class, buttonText = "add")
public List<Response> add(NewClaim sc, User u, Addressable from) {
OpenedClaim c = new OpenedClaim();
c.amount = sc.amount;
c.author = u;
c.description = sc.description;
c.status = Status.OPEN;
Chat approvalRoom = conversations.getExistingChat("Claim Approval Room");
return Arrays.asList(new WorkResponse(approvalRoom, c, WorkMode.VIEW), new MessageResponse(from, Message.of("Your claim has been sent to the Approval Room for processing")));
}
use of org.finos.symphony.toolkit.workflow.annotations.ChatButton 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;
}
use of org.finos.symphony.toolkit.workflow.annotations.ChatButton in project spring-bot by finos.
the class ButtonsResponseHandler method accept.
@Override
public void accept(Response t) {
if (t instanceof WorkResponse) {
Object o = ((WorkResponse) t).getFormObject();
WorkMode wm = ((WorkResponse) t).getMode();
ButtonList obl = (ButtonList) ((WorkResponse) t).getData().get(ButtonList.KEY);
if ((obl != null) && (obl.getContents().size() > 0)) {
return;
}
obl = new ButtonList();
((WorkResponse) t).getData().put(ButtonList.KEY, obl);
final ButtonList bl = obl;
initExposedHandlerMappings();
exposedHandlerMappings.stream().flatMap(hm -> hm.getAllHandlers(t.getAddress(), null).stream()).filter(cm -> exposedMatchesObject(cm.getMapping(), o)).filter(cm -> cm.isButtonFor(o, wm)).forEach(cm -> {
ChatButton e = cm.getMapping();
String value = cm.getUniqueName();
String text = e.buttonText();
text = StringUtils.hasText(text) ? text : formatFieldName(cm.getHandlerMethod().getMethod().getName());
bl.add(new Button(value, Type.ACTION, text));
});
Collections.sort((List<Button>) bl.getContents());
}
}
Aggregations