angel_alexa 0.0.0 copy "angel_alexa: ^0.0.0" to clipboard
angel_alexa: ^0.0.0 copied to clipboard

Angel framework infrastructure for writing Amazon Alexa skills.

example/main.dart

import 'package:alexa_skill/alexa_skill.dart';
import 'package:angel_alexa/angel_alexa.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:logging/logging.dart';
import 'package:pretty_logging/pretty_logging.dart';

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

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

main() async {
  // Logging boilerplate.
  Logger.root
    ..level = Level.ALL
    ..onRecord.listen(prettyLog);

  // Create the application and HTTP adapter.
  var app = Angel(logger: Logger('angel_alexa')), http = AngelHttp(app);

  // We can use any Service<String, Map<String, dynamic>> to store
  // persistence data.
  //
  // For example, you might use this with a Redis store. Otherwise,
  // the default is just an in-memory store.
  var adapter = ServicePersistenceAdapter(MapService());

  // Create a skill object.
  var skill = AlexaSkill(persistenceAdapter: adapter)
    ..requestHandlers.add(HelloWorldHandler());

  // Mount the skill as a route.
  app.post('/', alexaSkill(skill));

  // Fallback to 404.
  app.fallback((req, res) => throw AngelHttpException.notFound());

  // Launch the server.
  await http.startServer('127.0.0.1', 3000);
  print('Listening at ${http.uri}');
}
0
likes
30
pub points
0%
popularity

Publisher

verified publisherangel-dart.dev

Angel framework infrastructure for writing Amazon Alexa skills.

Repository (GitHub)
View/report issues

License

LGPL-3.0 (LICENSE)

Dependencies

alexa_skill, angel_framework

More

Packages that depend on angel_alexa