Skip to content

Instantly share code, notes, and snippets.

@n0bisuke
Created September 16, 2018 07:13
Show Gist options
  • Save n0bisuke/3755c3faaf1ad0fe621af8eaffb9b63f to your computer and use it in GitHub Desktop.
Save n0bisuke/3755c3faaf1ad0fe621af8eaffb9b63f to your computer and use it in GitHub Desktop.
# coding: utf-8
from flask import Flask, request, jsonify
import cek
import logging
app = Flask(__name__)
# Create a separate logger for this application
logger = logging.getLogger('my_clova_extension')
clova = cek.Clova(
application_id="MY EXTENSION ID",
default_language="ja",
debug_mode=True)
@app.route('/clova', methods=['POST'])
def my_service():
# Forward the request to the Clova Request Handler
# Just pass in the binary request body and the request header
# as a dictionary
body_dict = clova.route(body=request.data, header=request.headers)
response = jsonify(body_dict)
# make sure we have correct Content-Type that CEK expects
response.headers['Content-Type'] = 'application/json;charset-UTF-8'
return response
@clova.handle.launch
def launch_request_handler(clova_request):
# You can answer in different languages within one response
welcome_japanese = cek.Message(message="調子どうだい?", language="ja")
response = clova.response([
welcome_japanese
])
return response
# WifeStatusIntentの発火箇所
@clova.handle.intent("WifeStatusIntent")
def wife_status_handler(clova_request):
print("ワイフインテント")
slot = clova_request.slot_value("status")
message_japanese = cek.Message(message="もう一回言って下さい", language="ja")
if u"気分" in slot:
message_japanese = cek.Message(message="奥さんの気分はいい感じです", language="ja")
elif u"欲しい物" in slot:
message_japanese = cek.Message(message="奥さんは旅行に行きたがっています", language="ja")
response = clova.response([message_japanese])
return response
@clova.handle.end
def end_handler(clova_request):
# Session ended, this handler can be used to clean up
logger.info("Session ended.")
# In case not all intents have been implemented
# the handler falls back to the default handler
@clova.handle.default
def default_handler(request):
return clova.response("Sorry I don't understand! Could you please repeat?")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment