LoginSignup
2
2

More than 5 years have passed since last update.

CEKの俺的セットアップ

Last updated at Posted at 2018-07-17

はじめに

CEKに限らず、何かアプリを作り始める時はだいたい同じ作業をするのでメモにしておきます。
備忘録ってやつです。

ここで使ってるSDKは自作のやつなんですが、せっかくなので使い方書きました。
https://qiita.com/imajoriri/items/1b919b923246e69fe86e

環境

  • Node.js 8.10以上
  • Lambda使います。
  • API Gateway使います。

ディレクトリ作成

$ mkdir my-app
$ cd my-app
$ npm init

必要なものインストール

$ npm install --save love-clova clova-signature
$ curl -O https://clova-cek-requests.line.me/.well-known/signature-public-key.pem

初期設定

いくつかファイルを作成します。

node node_modules/love-clova/script/init-original.js

exports.handler内を以下に変更

index.js
exports.handler = async function(event, content){

  var headerSignature = event.headers.signaturecek || event.headers.SignatureCEK;
  var params = {
    keyPath: './signature-public-key.pem',
    applicationId: "applicationId",
    requestBody: event.requestParameters,
    headerSignature: headerSignature,
  }
  sig.verify(params);

  clova.extensionBuilders.addRequestHandlers(
    LaunchRequestHandler,
    SessionEndedRequestHandler,
    ClovaGuideIntentHandler,
  )
    .addErrorHandlers(errorHandler)
  return clova.extensionBuilders.invoke(event.requestParameters)
  //return clova.extensionBuilders.invoke(event)
}

API Gateway

マッピングテンプレートapplication/jsonを以下に変更

{
  "headers": {
#foreach( $key in $input.params().header.keySet() )
    "$key": "$input.params().header.get($key)"#if( $foreach.hasNext ),#end
#end
  },
  "requestParameters": $input.json('$')
}
2
2
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
2
2