Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: only handlers with same named or unqualified #252

Merged
merged 1 commit into from
Apr 15, 2020

Conversation

sdelamo
Copy link
Contributor

@sdelamo sdelamo commented Apr 15, 2020

see: #236

Given an application with two skills configured.

alexa:
  skills:
    helloworld: 
      skill-id: 'xxx'   
    hellomoon: 
      skill-id: 'xxx'   

We may have a LaunchRequest handler for helloworld:

@Named("helloworld")
@Singleton
public class LaunchRequestHandler implements RequestHandler {

    @Override
    public boolean canHandle(HandlerInput input) {
        return input.matches(Predicates.requestType(LaunchRequest.class));
    }

    @Override
    public Optional<Response> handle(HandlerInput input) {
        String speechText = "Welcome to Hello World";
        return input.getResponseBuilder()
                .withSpeech(speechText)
                .build();
    }
}

And a different LaunchRequest handler for hellomoon:

@Named("hellomoon")
@Singleton
public class LaunchRequestHandler implements RequestHandler {

    @Override
    public boolean canHandle(HandlerInput input) {
        return input.matches(Predicates.requestType(LaunchRequest.class));
    }

    @Override
    public Optional<Response> handle(HandlerInput input) {
        String speechText = "Welcome to Hello Moon";
        return input.getResponseBuilder()
                .withSpeech(speechText)
                .build();
    }
}

However, we may want to share the same session handler to end the session:

@Singleton
public class SessionEndedRequestHandler implements RequestHandler {

    @Override
    public boolean canHandle(HandlerInput input) {
        return input.matches(requestType(SessionEndedRequest.class));
    }

    @Override
    public Optional<Response> handle(HandlerInput input) {
        // any cleanup logic goes here
        return input.getResponseBuilder().build();
    }
}

if a RequestHandler bean is not qualified with name, I consider it applies to every Alexa Skill.
If a RequestHandler is qualfied with a name, it applies only to the Alexa Skill matching that name.

We don't have a method in ApplicationContext such as applicationContext.getBeansOfTypeNotQualifiedBy(RequestHandler.class, Qualifiers.byName(name))); so this code is a bit more hairy.

@graemerocher graemerocher merged commit 7161092 into master Apr 15, 2020
@sdelamo sdelamo deleted the handlers-qualified branch April 15, 2020 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants