enebularでalexaスキル その5

# 概要
enebularで、alexaスキルのwebhookを返してみた。
herokuに、デプロイしてみた。

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/1948806f-fbd9-1d5d-3fa7-e9cbfecb5a3b.png)

# node-redフロー

```
[{"id":"f0a907cc.af4218","type":"http in","z":"da568283.b34a7","name":"","url":"/","method":"post","upload":false,"swaggerDoc":"","x":190,"y":140,"wires":[["2a34f775.7fda08"]]},{"id":"60c8bf12.1068b","type":"function","z":"da568283.b34a7","name":"LaunchRequestセリフ","func":"msg.payload =\n{\n  \"version\": \"1.0\",\n  \"sessionAttributes\": {\n    \"count\": 1\n  },\n  \"response\": {\n    \"outputSpeech\": {\n      \"type\": \"PlainText\",\n      \"text\": \"今日は新しいことを学ぶチャンスが訪れるでしょう。 それをやり通せば可能性は無限です。\"\n    },\n    \"card\": {\n      \"type\": \"Simple\",\n      \"title\": \"カードです\",\n      \"content\": \"今日は新しいことを学ぶチャンスが訪れるでしょう。 それをやり通せば可能性は無限です。\"\n    },\n    \"reprompt\": {\n      \"outputSpeech\": {\n        \"type\": \"PlainText\",\n        \"text\": \"他にも質問はありますか？\"\n      }\n    },\n    \"shouldEndSession\": false\n  }\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":720,"y":120,"wires":[["d06f833d.ef44f"]]},{"id":"2a34f775.7fda08","type":"switch","z":"da568283.b34a7","name":"request.type 判定","property":"payload.request.type","propertyType":"msg","rules":[{"t":"eq","v":"LaunchRequest","vt":"str"},{"t":"eq","v":"IntentRequest","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":390,"y":120,"wires":[["60c8bf12.1068b"],["b506dc12.af435","f37951a4.334fe"]]},{"id":"bff6f124.63f98","type":"function","z":"da568283.b34a7","name":"n回目です。やたら元気です。と返答","func":"//sessionからcountを取得\n\nvar count = msg.payload.session.attributes.count;\nvar next = count + 1;\n\nmsg.payload =\n{\n  \"version\": \"1.0\",\n  \"sessionAttributes\": {\n    \"count\": `${next}` \n  },\n  \"response\": {\n    \"outputSpeech\": {\n      \"type\": \"PlainText\",\n      \"text\": `${count}`+\" 回目です。やたら、元気です。\"\n    },\n    \"card\": {\n      \"type\": \"Simple\",\n      \"title\": \"カードここに書く\",\n      \"content\": \"今日は新しいことを学ぶチャンスが訪れるでしょう。 それをやり通せば可能性は無限です。\"\n    },\n    \"reprompt\": {\n      \"outputSpeech\": {\n        \"type\": \"PlainText\",\n        \"text\": \"他にも質問はありますか？\"\n      }\n    },\n    \"shouldEndSession\": false\n  }\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":870,"y":380,"wires":[["d06f833d.ef44f"]]},{"id":"5392e475.0a3bdc","type":"switch","z":"da568283.b34a7","name":"slots.Genki 判定","property":"payload.request.intent.slots.GenkiSlot[\"value\"]","propertyType":"msg","rules":[{"t":"null"},{"t":"eq","v":"元気","vt":"str"},{"t":"nnull"}],"checkall":"false","repair":false,"outputs":3,"x":300,"y":380,"wires":[["5027294e.0b13a8"],["37dd5035.09bca"],["df772075.93764"]]},{"id":"5027294e.0b13a8","type":"function","z":"da568283.b34a7","name":"「発言がぬるぽでした」","func":"// GenkIntentに入ったが、GenkiSlot=null\n// 「ぬるぽです」と返す\nmsg.payload =\n{\n  \"version\": \"1.0\",\n  \"sessionAttributes\": {\n    \"count\": 1\n  },\n  \"response\": {\n    \"outputSpeech\": {\n      \"type\": \"PlainText\",\n      \"text\": \"発言がぬるぽでした。もういちどおねがいします。\"\n    },\n    \"card\": {\n      \"type\": \"Simple\",\n      \"title\": \"GenkIntentに入ったけど、GenkiSlot=nullですぜって表示される\",\n      \"content\": \"発言がぬるぽでした。もういちどおねがいします。\"\n    },\n    \"reprompt\": {\n      \"outputSpeech\": {\n        \"type\": \"PlainText\",\n        \"text\": \"他にも質問はありますか？\"\n      }\n    },\n    \"shouldEndSession\": false\n  }\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":830,"y":260,"wires":[["d06f833d.ef44f"]]},{"id":"b506dc12.af435","type":"switch","z":"da568283.b34a7","name":"slots有無","property":"payload.request.intent.slots.GenkiSlot","propertyType":"msg","rules":[{"t":"null"},{"t":"nnull"}],"checkall":"false","repair":false,"outputs":2,"x":280,"y":280,"wires":[["5027294e.0b13a8","f37951a4.334fe"],["5392e475.0a3bdc"]]},{"id":"d06f833d.ef44f","type":"http response","z":"da568283.b34a7","name":"","statusCode":"","headers":{},"x":1110,"y":220,"wires":[]},{"id":"37dd5035.09bca","type":"switch","z":"da568283.b34a7","name":"session attributes count判定","property":"payload.session.attributes.count","propertyType":"msg","rules":[{"t":"null"},{"t":"gte","v":"1","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":540,"y":380,"wires":[["16b775ba.d9dbaa"],["bff6f124.63f98","f37951a4.334fe"]]},{"id":"16b775ba.d9dbaa","type":"function","z":"da568283.b34a7","name":"1回目、元気です！返答（ここには来ない）","func":"//countセッション引き回し\n\nvar count = 1;\nvar next = count + 1;\nconsole.log(count)\nmsg.payload =\n{\n  \"version\": \"1.0\",\n  \"sessionAttributes\": {\n    \"count\": '${next}'\n  },\n  \"response\": {\n    \"outputSpeech\": {\n      \"type\": \"PlainText\",\n      \"text\": \"${count} 回目です。はい、元気です。\"\n    },\n    \"card\": {\n      \"type\": \"Simple\",\n      \"title\": \"ホロスコープ\",\n      \"content\": \"今日は新しいことを学ぶチャンスが訪れるでしょう。 それをやり通せば可能性は無限です。\"\n    },\n    \"reprompt\": {\n      \"outputSpeech\": {\n        \"type\": \"PlainText\",\n        \"text\": \"他にも質問はありますか？\"\n      }\n    },\n    \"shouldEndSession\": false\n  }\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":890,"y":320,"wires":[["d06f833d.ef44f"]]},{"id":"f37951a4.334fe","type":"debug","z":"da568283.b34a7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1130,"y":140,"wires":[]},{"id":"df772075.93764","type":"function","z":"da568283.b34a7","name":"「元気以外はききとれません」","func":"// GenkIntentに入ったが、GenkiSlot=「元気」以外の場合、\n// 「元気以外はききとれません」と返す\nmsg.payload =\n{\n \"version\": \"1.0\",\n \"sessionAttributes\": {\n \"count\": 1\n },\n \"response\": {\n \"outputSpeech\": {\n \"type\": \"PlainText\",\n \"text\": \"元気以外はききとれません。もういちどおねがいします。\"\n },\n \"card\": {\n \"type\": \"Simple\",\n \"title\": \"GenkIntentに入ったけど、GenkiSlot=「元気」以外ですぜって表示される\",\n \"content\": \"元気以外はききとれません。もういちどおねがいします。\"\n },\n \"reprompt\": {\n \"outputSpeech\": {\n \"type\": \"PlainText\",\n \"text\": \"他にも質問はありますか？\"\n }\n },\n \"shouldEndSession\": false\n }\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":850,"y":440,"wires":[["d06f833d.ef44f"]]}]
```


以上。