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.
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
fn main() -> Result<(), Box
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
fn handlehello(req: &Request) -> Result
fn handlecancel(req: &Request) -> Result
fn myhandler(req: Request, _ctx: Context) -> Result
fn main() -> Result<(), Box
Ok(())
} ```
Besides the simplifed Response constructors Response::simple
and Response::end
(to end a session), the SDK supports a Response builder:
rust
let img = Image {
small_image_url: Some(String::from("https://example.com/baaz.png")),
large_image_url: Some(String::from("https://example.com/baazLarge.png"))
};
let mut res = Response::new(false) // should not end session
.card(Card::standard("foo", "bar", img))
.speech(Speech::plain("hello"));
res.add_attribute("attr", "value");
Alexa skills support attributes, which can be used to carry simple state in a session. To set an attribute in the response, use add_attribute
on the response, to read a previously set attribute on a subsequent request, use attribute_value
on the request.
[TODO: example]