alexa_skill 0.0.2

alexa_skill

Pub build status

Unofficial Dart library for building Alexa skills as Web services.

Again, this is not an Amazon product.

Usage #

The main functionality of this library is providing JSON models and constants that correspond to all of the standard request and response types for Alexa. In addition, there is a high-level API built on this foundation that closely resembles the official Java SDK.

See example/example.dart for an example Hello world server that you can run directly, using package:shelf.

TODO: More docs here

High Level Usage #

The high-level API closely follows the official Java SDK, and provides:

  • Request handler classes and infrastructure
  • Session/request/persistent storage infrastructure
  • A package:shelf adapter

Below is a contrived example, using RequestHandler classes and the AlexaSkill wraper class:

class HelloWorldHandler extends AlexaLaunchRequestHandler {
  @override
  bool canHandleTyped(
          AlexaHandlerInput handlerInput, AlexaLaunchRequest request) =>
      true;

  @override
  AlexaResponseEnvelope handleTyped(
      AlexaHandlerInput handlerInput, AlexaLaunchRequest request) {
    return handlerInput.responseBuilder
        .withSpeech('Hello, world!')
        .withShouldEndSession(true)
        .response;
  }
}

main() async {
  var skill = AlexaSkill()..requestHandlers.add(HelloWorldHandler());
  await shelf_io.serve(alexaSkillHandler(skill), '127.0.0.1', 3000);
  print('Listening at http://127.0.0.1:3000');
}

Low Level Usage #

Below is a contrived example:

var bodyAsMap = await parseRequestJson();
var requestEnvelope = alexaRequestEnvelopeSerializer.decode(bodyAsMap);
var responseEnvelope = AlexaResponseEnvelope();

if (requestEnvelope.requestType == AlexaRequestType.launchRequest) {
  // Send a basic text response.
  responseEnvelope.response = AlexaResponse(
    outputSpeech: AlexaOutputSpeech(
      type: AlexaOutputSpeechType.plainText,
      text: 'Hello, world!',
    ),
  );
} else if (requestEnvelope.requestType !=
    AlexaRequestType.sessionEndedRequest) {
  // Do something...
}

request.response
  ..headers.contentType = ContentType.json
  ..write(json.encode(responseEnvelope));

0.0.2 #

  • Export src/attributes.dart.
  • Enforce requestType in typed request handlers.

0.0.1 #

  • Added more constants
  • Began high-level API, a port from the Java SDK.
  • Added shelf API

0.0.0 #

  • Initial version

example/example.dart

/// This is an example skill that responds to  a LaunchRequest
/// with `Hello, world!`.
///
/// You'll need to set up the skill in the Alexa Developer Console,
/// and somehow get a server running (for example, via `ngrok.io`),
/// but once that's done, it should just work.
library alexa_skill.example;

import 'package:alexa_skill/alexa_skill.dart';
import 'package:alexa_skill/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;

class HelloWorldHandler extends AlexaLaunchRequestHandler {
  @override
  bool canHandleTyped(
          AlexaHandlerInput handlerInput, AlexaLaunchRequest request) =>
      true;

  @override
  AlexaResponseEnvelope handleTyped(
      AlexaHandlerInput handlerInput, AlexaLaunchRequest request) {
    return handlerInput.responseBuilder
        .withSpeech('Hello, world!')
        .withShouldEndSession(true)
        .response;
  }
}

main() async {
  var skill = AlexaSkill()..requestHandlers.add(HelloWorldHandler());
  await shelf_io.serve(alexaSkillHandler(skill), '127.0.0.1', 3000);
  print('Listening at http://127.0.0.1:3000');
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  alexa_skill: ^0.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:alexa_skill/alexa_skill.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
4
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (asn1lib).

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
angel_serialize ^2.0.0 2.2.3+3
asn1lib ^0.5.11 0.5.15 0.6.0
charcode ^1.0.0 1.1.3
crypto ^2.0.0 2.1.4
http >=0.11.0 <0.13.0 0.12.0+4
path ^1.0.0 1.6.4
shelf ^0.7.5 0.7.5
string_scanner ^1.0.0 1.0.5
x509csr ^1.0.0 1.0.2
Transitive dependencies
angel_model 1.0.3
async 2.4.0
collection 1.14.12
convert 2.1.1
http_parser 3.1.3
meta 1.1.8
pointycastle 1.0.2
quiver_hashcode 2.0.0
source_span 1.6.0
stack_trace 1.9.3
stream_channel 2.0.0
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
angel_serialize_generator ^2.0.0
build_runner ^1.0.0
pedantic ^1.0.0 1.9.0
test ^1.0.0