11
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

アレクサスキルの吾輩のテンプレート

Last updated at Posted at 2017-12-10

われのスキルを作る時に使うテンプレート

インテントスキーマ

{
  "intents": [
    {
      "slots": [
        {
          "name": "Me",
          "type": "YourName"
        }
      ],
      "intent": "StrongestIntent"
    },
    {
      "intent": "AMAZON.HelpIntent"
    },
    {
      "intent": "AMAZON.StopIntent"
    },
    {
      "intent": "AMAZON.CancelIntent"
    }
  ]
}

Lambda側

"use strict";
const Alexa = require('alexa-sdk');

// ステートの定義
const state = {
  sampleState: '_sample'
};

//まずはここが呼ばれる
exports.handler = function(event, context, callback) {
  var alexa = Alexa.handler(event, context);
  //dynamodbを使うなら下をコメントアウト
  //alexa.dynamoDBTableName = 'SampleSkillTable'; //使用するテーブル名に変更
  // alexa.appId = process.env.APP_ID;

  alexa.registerHandlers(handlers, sampleHandler); //使用するハンドラーを書き込む。
  alexa.execute();
};
var handlers = {
  // スキル起動名だけで起動されたときに呼ばれる
  'LaunchRequest': function () {
    var message = "起動名だけでこのスキルを開いたときに呼ばれる";
    this.emit(":tell", message);
  },
  // ヘルプとか言われたときに発動。スキルの説明を言わせる。必須
  'AMAZON.HelpIntent': function () {
    var message = "このスキルの説明";
    this.emit(':ask', message);
  },
  // 自分で定義したインテント
  "SampleIntent": function() {
    this.handler.state = state.EmotionState;
    this.emitWithState("EmotionIntent");
  },"AMAZON.StopIntent": function() {
    this.emit(":tell", "ストップなどと言われた時");
  },"AMAZON.CancelIntent": function() {
    this.emit(":tell", "キャンセルなどと言われた時");
  },
  'Unhandled': function() {
    this.emit(':ask', reprompt, reprompt);
  },
  "SessionEndedRequest": function(){
    // ユーザーが「終了して」と、言った時
    // ユーザーが何も応答しなかった時
  }
};

// ステートを定義 
var sampleHandler = Alexa.CreateStateHandler(state.EmotionState, {
  "SampleIntent": function(){
    // dynamoDBを使用していたらステートの情報も保存されてしまうので削除
    this.handler.state = "";
    this.attributes['STATE'] = undefined;
  },
  // 今いるステートでは呼べないが、インテントスキーマには書いてあるインテントが呼ばれたとき
  'Unhandled': function() {
    this.emit(':ask', reprompt, reprompt);
  },"AMAZON.StopIntent": function() {
    this.emit(":tell", "ストップなどと言われた時");
  },"AMAZON.CancelIntent": function() {
    this.emit(":tell", "キャンセルなどと言われた時");
  }
});
11
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?