Skip to content

oaxlin/Net-Amazon-Alexa-Dispatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NAME

Net::Amazon::Alexa::Dispatch

VERSION

version 0.001

SYNOPSIS

use Net::Amazon::Alexa::Dispatch;

my $alexa = Net::Amazon::Alexa::Dispatch->new({
    skillName=>'YourSkillName',
    configFile=>'/home/oaxlin/config_alexa.json',
    dispatch=>[
        'Net::Amazon::Alexa::SomePlugin',
        'Net::Amazon::Alexa::AnotherPlugin'
    ],
  });
$alexa->run_method($json);

DESCRIPTION

A Perl module which provides a simple and lightweight interface to the Amazon Alexa Skills Kit

NAME

Net::Amazon::Alexa::Dispatch - Perl extensions for creating an Alexa skill

METHODS

A list of methods available

new

Create a new instance of Disptach.

All options can be passed into the new directly, or loaded from the "configFile"

    configFile

    OPTIONAL - The path to a perl evalable config file.

    skillName

    The name you wish to give this Alexa skill. Used when displaying documentation.

    Defaults to "Alexa Skill" if nothing is configured.

    dispatch [array]

    Any additional plugins you wish to dispatch to. If you do not include any plugins then this module will only be able to perform Hello requests.

    Plugins added during "new" will be processed before any in a config file.

    If multiple plugins share the same method calls, the one listed first will be used.

    Please note all plugins must use the same token for authentication

run_method

Parses the Amazon data and routes it to the appropriate module/method.

    $json

    Raw json data from Amazon.

intent_prefix

Simply returns the intent_prefix value used by this module The default is "alexa_intent_"

Without intent_prefix all methods in a module will be exposed. Setting this value will expose only methods that begin with the prefix

skill_name

Simply returns the value configured in Config->skillName

Defaults to "Alexa Skill" if nothing is configured.

alexa_authenticate_params ( $param )

Used by the dispatcher to grant access.

If authentication is successful this method should return the token.

If authentication fails, this method return undef or die.

    $param

    A hash containing the name/value pairs of all data submitted with the alexa skill request.

    Values provided by Amazon include response_type redirect_uri state client_id

    Values expected by Net::Amazon::Alexa::Dispatch Password

    You can use any additional paramaters as needed. So long as they do not conflict with the names above.

alexa_authenticate_json ( $json )

Used by the dispatcher to grant access.

If authentication is successful this method should return a true value.

If authentication fails, this method return undef or die.

    $json

    Raw json data from Amazon.

alexa_intent_HelloIntent( $args, $json )

A sample intent action that an Alexa skill can perform.

    $json

    Raw json data from Amazon.

The return value should be the text that you wish Alexa to say in response to the skill request.

alexa_intent_HelloIntent__meta

Basic meta information about your skill. This will be used by the automatic documentation to make it easier for others to create their own skills using your plugin

slots_to_hash

Takes in the Alexa $json data and returns a simple hash with key/value pairs

If your JSON looks something like this

{
  "request": {
    "type": "IntentRequest",
    "intent": {
      "name": "HelloIntent",
      "slots": {
        "bravia_location": {
          "name": "bravia_location",
          "value": "upstairs"
        }
      }
    }
  }
}

Then $self->slots_to_hash($json) will return a hash containing

{
  "bravia_location" => "upstairs",
}

msg_to_hash

Parses the message and turns it into a hash suitable to be JSONified for Alexa

    $ret

    Raw response, coulde be one of

    1) Already existing well formatted Alexa HASH response
    
    2) Simple text
    
    3) Throw object, with alexa_safe=>1 set

    Be careful to not send die text to this method as they look just like simple text. A good way to "escape" die messages is to return them like this

    return { error => $@ } if $@;
    $default

    This text will be used if the value of $ret does not fit the above criteria

    If no default is provided then 'Skill returned invalid response data' will be used

AUTHOR

Jason Terry <[email protected]>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Jason Terry.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

About

Perl extensions for creating an Alexa skill

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages