use of org.finos.symphony.toolkit.workflow.annotations.ChatVariable in project spring-bot by finos.
the class AbstractClassWorkflowResolver method canResolve.
@Override
public boolean canResolve(MethodParameter mp) {
ChatVariable chatVariable = mp.getParameterAnnotation(ChatVariable.class);
if (chatVariable != null) {
return false;
}
Type t = mp.getGenericParameterType();
if (isOptional(t)) {
t = getOptionalType(t);
}
if (t instanceof Class<?>) {
return canResolve((Class<?>) t);
}
return false;
}
use of org.finos.symphony.toolkit.workflow.annotations.ChatVariable in project spring-bot by finos.
the class ChatRequestChatHandlerMapping method createMappingRegistration.
@Override
protected MappingRegistration<ChatRequest> createMappingRegistration(ChatRequest mapping, ChatHandlerMethod handlerMethod) {
List<WildcardContent> wildcards = createWildcardContent(mapping, handlerMethod);
List<MessageMatcher> matchers = createMessageMatchers(mapping, wildcards);
return new MappingRegistration<ChatRequest>(mapping, handlerMethod) {
@Override
public ChatHandlerExecutor getExecutor(Action a) {
if (a instanceof SimpleMessageAction) {
if (!canBePerformedHere((SimpleMessageAction) a)) {
return null;
}
return matchesSimpleMessageAction((SimpleMessageAction) a);
}
if (a instanceof FormAction) {
if (Objects.nonNull(((FormAction) a).getData().get("form")) && ((FormAction) a).getData().get("form").getClass() != HelpPage.class) {
return null;
}
if (!canBePerformedHere((FormAction) a)) {
return null;
}
return matchesFormAction((FormAction) a);
}
return null;
}
private boolean canBePerformedHere(Action a) {
ChatRequest cb = getMapping();
return canBePerformed(a.getAddressable(), a.getUser(), cb);
}
private ChatHandlerExecutor matchesSimpleMessageAction(SimpleMessageAction a) {
return pathMatches(a.getMessage(), a);
}
private ChatHandlerExecutor matchesFormAction(FormAction a) {
return pathMatches(Message.of(Word.build(a.getAction())), a);
}
private ChatHandlerExecutor pathMatches(Message words, Action a) {
MappingRegistration<?> me = this;
ChatHandlerExecutor bestMatch = null;
for (MessageMatcher messageMatcher : matchers) {
Map<ChatVariable, Object> map = new HashMap<>();
if (messageMatcher.consume(words, map)) {
if ((bestMatch == null) || (bestMatch.getReplacements().size() < map.size())) {
bestMatch = new AbstractHandlerExecutor(wrf, rh, converters) {
@Override
public Map<ChatVariable, Object> getReplacements() {
return map;
}
@Override
public Action action() {
return a;
}
@Override
public ChatMapping<?> getOriginatingMapping() {
return me;
}
};
}
}
}
return bestMatch;
}
@Override
public boolean isButtonFor(Object o, WorkMode m) {
return false;
}
};
}
Aggregations