Host a Custom Skill as a Web Service
You can build a custom skill for Alexa by extending a servlet that accepts requests from and sends responses to the Alexa service in the cloud.
The servlet must meet certain requirements to handle requests sent by Alexa and adhere to the Alexa Skills Kit interface standards. For more information, see Host a Custom Skill as a Web Service in the Alexa Skills Kit technical documentation.
ASK SDK Servlet Support
The Alexa Skills Kit SDK (ASK SDK) for Java provides boilerplate code for request verification and timestamp verification through the ask-sdk-servlet-support package. This package provides the verification components and SkillServlet for skill invocation.
Installation
You can import the latest version of ask-sdk-servlet-support
by adding it as a maven dependency in your project's pom.xml
.
Skill servlet
The SkillServlet class registers the skill instance from the SkillBuilder
object, and provides a doPost
method which is responsible for deserialization of the incoming request, verification of the input request before invoking the skill, and serialization of the generated response.
Usage
public class HelloWorldSkillServlet extends SkillServlet {
@Override
public HelloWorldSkillServlet() {
super(getSkill());
}
@Override
private static Skill getSkill() {
return Skills.standard()
.addRequestHandlers(
new CancelandStopIntentHandler(),
new HelloWorldIntentHandler(),
new HelpIntentHandler(),
new LaunchRequestHandler(),
new SessionEndedRequestHandler())
// Add your skill id below
//.withSkillId("")
.build();
}
}
Sample code
The following sample code shows demonstrates the servlet class:
Last updated: Nov 28, 2023