Rust Request/Response for Amazon Alexa Skills

About

Implements Amazon Alexa Skill request/response structs following the Alexa skill specifications, including Serde JSON serialization/deserialization with some helpers to extract data from requests and format responses.

These structs can be used as the request and response using the Rust AWS Lambda runtime to implement the skill.

Usage

Simplest possible Alexa "Hello, World" skill:

```rust extern crate lambdaruntime as lambda; extern crate alexasdk;

use lambda::{lambda, Context, error::HandlerError}; use alexa_sdk::{Request,Response}; use std::error::Error;

fn myhandler(req: Request, ctx: Context) -> Result { Ok(Response::newsimple("hello", "hello world")) }

fn main() -> Result<(), Box> { lambda!(my_handler);

Ok(())

} ```

A more complete skill, handling multiple locales and a slot:

```rust extern crate lambdaruntime as lambda; extern crate alexasdk;

use lambda::{lambda, Context, error::HandlerError}; use alexasdk::{Request,Response}; use alexasdk::request::{IntentType, Locale}; use std::error::Error;

fn handlehelp(req: &Request) -> Result { Ok(Response::new_simple("hello", "to say hello, tell me: say hello to someone")) }

fn handlehello(req: &Request) -> Result { let res = match req.locale() { Locale::AustralianEnglish => Response::newsimple("hello", "G'day mate"), Locale::German => Response::newsimple("hello", "Hallo Welt"), Locale::Japanese => Response::newsimple("hello", "こんにちは世界"), _ => if let Some(ref s) = req.slotvalue("name") { Response::newsimple("hello", (String::from("hello ") + s).asstr()) } else { Response::newsimple("hello", "hello world") }, }; Ok(res) }

fn handlecancel(req: &Request) -> Result { Ok(Response::end()) }

fn myhandler(req: Request, _ctx: Context) -> Result { match req.intent() { IntentType::Help => handlehelp(&req), IntentType::User() => handlehello(&req), _ => handle_cancel (&req) } }

fn main() -> Result<(), Box> { lambda!(my_handler);

Ok(())

} ```