Alexa Skill kit -Lambda函数 - 无法验证SpeechletRequest(java)

时间:2016-06-10 07:38:08

标签: alexa alexa-skills-kit alexa-voice-service alexa-skill

我试图基于https://github.com/amzn/alexa-skills-kit-java创建一个HelloWorld技能但是当我测试lambda函数时它显示了这个错误

{
  "errorMessage":"com.amazon.speech.speechlet.SpeechletRequestHandlerException: Could not validate SpeechletRequest null using verifier ApplicationIdSpeechletRequestVerifier, rejecting request",

  "errorType": "java.lang.RuntimeException",

  "stackTrace": [    "com.amazon.speech.speechlet.lambda.SpeechletRequestStreamHandler.handleRequest(SpeechletRequestStreamHandler.java:101)",
 "helloworld.HelloWorldSpeechletRequestStreamHandler.handleRequest(HelloWorldSpeechletRequestStreamHandler.java:43)"

 ],

  "cause": {

    "errorMessage": "Could not validate SpeechletRequest null using 
verifier ApplicationIdSpeechletRequestVerifier, rejecting request",
    "errorType": "com.amazon.speech.speechlet.SpeechletRequestHandlerException",

    "stackTrace": [
      "com.amazon.speech.speechlet.SpeechletRequestHandler.handleSpeechletCall(SpeechletRequestHandler.java:73)",
      "com.amazon.speech.speechlet.lambda.SpeechletRequestStreamHandler.handleRequest(SpeechletRequestStreamHandler.java:98)",
      "helloworld.HelloWorldSpeechletRequestStreamHandler.handleRequest(HelloWorldSpeechletRequestStreamHandler.java:43)"
    ]
  }
}

这是我的Java文件

public final class HelloWorldSpeechletRequestStreamHandler extends SpeechletRequestStreamHandler {
    private static final Set<String> supportedApplicationIds = new HashSet<String>();
    static {
        /*
         * This Id can be found on https://developer.amazon.com/edw/home.html#/ "Edit" the relevant
         * Alexa Skill and put the relevant Application Ids in this Set.
         */
        supportedApplicationIds.add("amzn1.echo-sdk-ams.app.[amzn1.echo-sdk-ams.app.56bcdaf9-97fc-47f9-9918-43cb6a90d9f5]");
    }


    public HelloWorldSpeechletRequestStreamHandler() {
        super(new HelloWorldSpeechlet(), supportedApplicationIds);
    }
}

我错过了什么?

4 个答案:

答案 0 :(得分:10)

支持的应用程序ID中包含错误的ID。该id必须是Alexa Skills应用程序的ID,可以在Skill Information页面上找到。看起来应该是这样的:

supportedApplicationIds.add("amzn1.ask.skill.c236d019-7d2a-5c96-a02f-ef8ab6f8e023");

我知道演示有[在这里放置地址]但是你真的替换了整个事情。

答案 1 :(得分:8)

对我来说,我遇到了这个异常,因为我试图在Actions选项卡下运行我的lambda函数而没有正确的测试事件JSON。如果单击“操作”选项卡,然后单击“配置测试事件”,则应该以JSON形式提供可以解释的函数输入。经过深思熟虑后,我发现你可以通过开发人员控制台获得这个JSON,你可以在那里掌握所有技能配置。在左侧单击“测试”选项卡,然后转到“服务模拟器”部分。有一个文本框显示“输入话语”,您可以在其中输入语音命令到您的功能,例如'Alexa告诉[yourApp]说你好'。单击“询问[yourApp]”按钮,左侧框将生成一个Lambda请求JSON,右侧输出。然后只需将左侧的JSON复制并粘贴到lambda控制台的测试事件中,然后就可以了。

答案 2 :(得分:1)

我尝试创建https://github.com/amzn/alexa-skills-kit-java中包含的地址技能,但我遇到了相同类型的错误。

事实证明问题出在add_action('wp_ajax_my_load_more_function', 'my_load_more_function'); add_action('wp_ajax_nopriv_my_load_more_function', 'my_load_more_function'); function my_load_more_function() { $query = new WP_Query( [ 'posts_per_page' => $_POST["posts_per_page"], 'orderby'=>'title', 'order'=>'ASC', 'paged' => get_query_var('paged', $_POST["paged"]) ] ); if ($query->have_posts()) { $i = 0; $j = 0; while ($query->have_posts()) { $query->the_post(); if ( $i % 5 === 0 ) { // Large post: on the first iteration and every 7th post after... ?> <div class="row"> <article <?php post_class( 'col-sm-12 col-md-12' ); ?>> <div class="large-front-container"> <?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?> </div> <div class="front-page-date"><?php echo str_replace('mins', 'minutes', human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'); ?></div> <h2><a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p> <div class="front-page-post-info"> <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> <?php get_template_part( 'front-shop-the-post' ); ?> <?php get_template_part( 'share-buttons' ); ?> <div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div> </div> </article> </div> <?php } else { // Small posts ?> <?php if($j % 2 === 0) echo '<div class="row">'; ?> <article <?php post_class( 'col-sm-6 col-md-6' ); ?>> <?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?> <div class="front-page-date"><?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></div> <h2><a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p> <div class="front-page-post-info"> <a class="moretext" href="<?php the_permalink(); ?>">Read more</a> <?php get_template_part( 'front-shop-the-post' ); ?> <?php get_template_part( 'share-buttons' ); ?> <div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div> </div> </article> <?php $j++; if($j % 2 === 0) echo '</div>'; ?> <?php } $i++; } wp_reset_query(); }else{ return 0; } exit; } 并在静态{}块中创建了DeviceAddressSpeechletRequestStreamHandler的实例。

当我移动Set<String> supportedApplicationIds来声明类的属性时,它开始工作。

答案 3 :(得分:0)

我会将static代码放到您创建的扩展SpeechletLambda的类上。我相信,这是评估发生的地方,并在加载此类并执行其静态代码之前得到解决。

或者,您可以关闭验证。如果有人知道您的开发环境足以调用您的私有lambda函数,那么他们可能知道足以欺骗您的应用程序ID。因此验证它没有太多的安全价值。有关将其关闭的示例,请参阅here