Clova Extension Kit SDK for Python¶
This is a python library to simplify the use of the Clova Extensions Kit (CEK). If you want to create your own service, you first need to create your own Extension. https://clova-developers.line.me/
Quick start¶
- Create a
cek.clova.Clova
instance.
import os
from cek import Clova
# application_id is used to verify requests.
application_id = os.environ.get("APPLICATION_ID")
# Set debug_mode=True if you are testing your extension. If True, this disables request verification
clova = Clova(application_id=application_id, default_language="ja", debug_mode=False)
- Define request handlers for CEK (on LaunchRequest, IntentRequest, etc).
@clova.handle.launch
def launch_request_handler(clova_request):
return clova.response("こんにちは世界。スキルを起動します")
@clova.handle.default
def default_handler(clova_request):
return clova.response("もう一度お願いします")
- Setup a web API endpoint. Use
cek.clova.Clova.route()
to route requests.
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/app', methods=['POST'])
def my_service():
resp = clova.route(request.data, request.headers)
resp = jsonify(resp)
# make sure we have correct Content-Type that CEK expects
resp.headers['Content-Type'] = 'application/json;charset-UTF-8'
return resp
- Save as
app.py
and run app
FLASK_APP=app.py flask run
For a detailed example, see clova-cek-sdk-python-sample example extension. See also the API documentation to know how to use the SDK.
References
Meta information