2016-11-11 8 views
4

ラムダを使用せずにカスタムAlexaスキルを作成しようとしています。そのため、AWS EC2インスタンスにSpring起動アプリケーションをデプロイし、SSL証明書を設定し、Postmanを使用して起動することでサービスが機能することをテストしました。Spring Boot httpsエンドポイントでカスタムAlexaスキルを作成できますか?

次に、「https」エンドポイントとしてAlexaスキルを設定しました。私がdeveloper.amazon.comでテストフォームを使用したとき、私は単純に戻ります:

リモートエンドポイントを呼び出せなかったか、返された応答が無効でした。

私はポストマンと直接サービスを呼び出すと、私が手:

{ 
 
    "version": "1.0", 
 
    "response": { 
 
    "outputSpeech": { 
 
     "type": "PlainText", 
 
     "id": null, 
 
     "text": "Hello, World. I am a Spring Boot custom skill." 
 
    }, 
 
    "card": { 
 
     "type": "Simple", 
 
     "title": "HelloWorld", 
 
     "content": "Hello, World. I am a Spring Boot custom skill." 
 
    }, 
 
    "reprompt": null, 
 
    "shouldEndSession": true 
 
    }, 
 
    "sessionAttributes": null 
 
}

私のコントローラは、AlexaのスキルセットのSDKを使用しています。ここにコードがあります:

@RestController 
public class AlexaController { 

    @RequestMapping(value="/alexa", 
     method=RequestMethod.POST, 
     produces=MediaType.APPLICATION_JSON_VALUE) 
    public ResponseEntity<SpeechletResponseEnvelope> alexa(Model model) { 

     String speechText = "Hello, World. I am a Spring Boot custom skill."; 

     SimpleCard card = new SimpleCard(); 
     card.setTitle("HelloWorld"); 
     card.setContent(speechText); 

     PlainTextOutputSpeech speech = new PlainTextOutputSpeech(); 
     speech.setText(speechText); 


     SpeechletResponse response = SpeechletResponse.newTellResponse(speech, card); 


     SpeechletResponseEnvelope envelope = new SpeechletResponseEnvelope(); 
     envelope.setResponse(response); 
     envelope.setVersion("1.0"); 
     envelope.setSessionAttributes(null); 

     return new ResponseEntity<SpeechletResponseEnvelope>(envelope, HttpStatus.OK); 
    } 
} 

答えて

9

私は上記を廃止し、代わりにSpringのServletRegistrationBeanクラスを使用してカスタムサーブレットを登録しました。

@Configuration 
public class AlexaConfig { 

    @Autowired 
    private MyCustomSpeechlet mySpeechlet; 

    @Bean 
    public ServletRegistrationBean registerServlet() { 

     SpeechletServlet speechletServlet = new SpeechletServlet(); 
     speechletServlet.setSpeechlet(mySpeechlet); 

     ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(speechletServlet, "/alexa"); 
     return servletRegistrationBean;  
    } 
} 

私のカスタムサーブレットは、AlexaスキルキットクラスSpeechletを拡張しています。

魅力的な作品です!

+0

これは素晴らしいです。 GitHubや他の場所でサンプルプロジェクトを持っていますか?私はSPRINGには新しく、これまでのところ私はSpring Bootを愛していました。 Alexaのソリューションは、私にとって素晴らしい出発点になります。 また、IntelliJまたはEclipseを使用しましたか?これを達成するために外部ライブラリが必要でしたか? –

+0

こんにちはラフ、これはうまくいく、あなたは正しい。 speechletResponse.newAskResponseは、springbootアプリケーションでプロンプトが待機しないため動作しません。あなたも同じ問題に直面しましたか?解決できましたか?あなたがそれを働かせることができるかどうか私に知らせてください。 – gubs

+0

@KrishnanSriramここでは、春のブートを使った例があります。また、gradle.buildの依存関係も表示されます:https://github.com/qaware/iot-hessen-amazon-echo/ – timguy

関連する問題