from sanic import Blueprint
from sanic.exceptions import abort
from sanic.response import json
from sanic_openapi import doc

from dazu.registry import Registry

dialog = Blueprint("dialog", url_prefix="/dialog")


@dialog.post("/")
def dialogDefault(request):
    requestData = request.json
    return process_dialog(requestData)


@dialog.post("/<adapter_name:path>")
def dialogAdopted(request, adapter_name):
    requestData = request.json
    return process_dialog(requestData, adapter_name)


def process_dialog(requestData, adapter_name=None):
    from dazu.server import Server

    adapter = Registry.getAdapter(Server.config, adapter_name)

    if not adapter:
        abort(404, "Invalid adapter")

    if not adapter.validate_data(requestData):
        abort(400, "Invalid input")

    messageIn = adapter.input(requestData)
    messageOut = Server.engine.respond(messageIn)
    responseData = adapter.output(messageOut)
    return json(responseData)

afbcf788c5124a6f688b965546390f94f537b32f
<mask token>


@dialog.post('/')
def dialogDefault(request):
    requestData = request.json
    return process_dialog(requestData)


@dialog.post('/<adapter_name:path>')
def dialogAdopted(request, adapter_name):
    requestData = request.json
    return process_dialog(requestData, adapter_name)


<mask token>

<mask token>


@dialog.post('/')
def dialogDefault(request):
    requestData = request.json
    return process_dialog(requestData)


@dialog.post('/<adapter_name:path>')
def dialogAdopted(request, adapter_name):
    requestData = request.json
    return process_dialog(requestData, adapter_name)


def process_dialog(requestData, adapter_name=None):
    from dazu.server import Server
    adapter = Registry.getAdapter(Server.config, adapter_name)
    if not adapter:
        abort(404, 'Invalid adapter')
    if not adapter.validate_data(requestData):
        abort(400, 'Invalid input')
    messageIn = adapter.input(requestData)
    messageOut = Server.engine.respond(messageIn)
    responseData = adapter.output(messageOut)
    return json(responseData)

<mask token>
dialog = Blueprint('dialog', url_prefix='/dialog')


@dialog.post('/')
def dialogDefault(request):
    requestData = request.json
    return process_dialog(requestData)


@dialog.post('/<adapter_name:path>')
def dialogAdopted(request, adapter_name):
    requestData = request.json
    return process_dialog(requestData, adapter_name)


def process_dialog(requestData, adapter_name=None):
    from dazu.server import Server
    adapter = Registry.getAdapter(Server.config, adapter_name)
    if not adapter:
        abort(404, 'Invalid adapter')
    if not adapter.validate_data(requestData):
        abort(400, 'Invalid input')
    messageIn = adapter.input(requestData)
    messageOut = Server.engine.respond(messageIn)
    responseData = adapter.output(messageOut)
    return json(responseData)

from sanic import Blueprint
from sanic.exceptions import abort
from sanic.response import json
from sanic_openapi import doc
from dazu.registry import Registry
dialog = Blueprint('dialog', url_prefix='/dialog')


@dialog.post('/')
def dialogDefault(request):
    requestData = request.json
    return process_dialog(requestData)


@dialog.post('/<adapter_name:path>')
def dialogAdopted(request, adapter_name):
    requestData = request.json
    return process_dialog(requestData, adapter_name)


def process_dialog(requestData, adapter_name=None):
    from dazu.server import Server
    adapter = Registry.getAdapter(Server.config, adapter_name)
    if not adapter:
        abort(404, 'Invalid adapter')
    if not adapter.validate_data(requestData):
        abort(400, 'Invalid input')
    messageIn = adapter.input(requestData)
    messageOut = Server.engine.respond(messageIn)
    responseData = adapter.output(messageOut)
    return json(responseData)

from sanic import Blueprint
from sanic.exceptions import abort
from sanic.response import json
from sanic_openapi import doc

from dazu.registry import Registry

dialog = Blueprint("dialog", url_prefix="/dialog")


@dialog.post("/")
def dialogDefault(request):
    requestData = request.json
    return process_dialog(requestData)


@dialog.post("/<adapter_name:path>")
def dialogAdopted(request, adapter_name):
    requestData = request.json
    return process_dialog(requestData, adapter_name)


def process_dialog(requestData, adapter_name=None):
    from dazu.server import Server

    adapter = Registry.getAdapter(Server.config, adapter_name)

    if not adapter:
        abort(404, "Invalid adapter")

    if not adapter.validate_data(requestData):
        abort(400, "Invalid input")

    messageIn = adapter.input(requestData)
    messageOut = Server.engine.respond(messageIn)
    responseData = adapter.output(messageOut)
    return json(responseData)
