Ejemplo n.º 1
0
def main():
    logger.error('Request: %r', request.json)

    response = {
        'version': request.json['version'],
        'session': request.json['session'],
    }
    json_body = request.json

    user_id = json_body['session']['user_id']
    session_obj = session.get(user_id)
    dm_obj = dm.DialogManager(session_obj)

    message = json_body['request']['command'].strip()
    if not message:
        message = json_body['request']['original_utterance']

    dmresponse = dm_obj.handle_message(message)
    response['response'] = {
        'text': dmresponse.text,
        'end_session': dmresponse.end_session,
    }
    if dmresponse.tts is not None:
        response['response']['tts'] = dmresponse.tts

    logger.error('Response: %r', response)
    return json.dumps(response)
Ejemplo n.º 2
0
# coding: utf-8

from __future__ import unicode_literals

from seabattle import dialog_manager as dm, game as gm
from seabattle import session

import mock

user_id = 'user1'
session_obj = session.get(user_id)


def say(message):
    return dm.DialogManager(session_obj).handle_message(message).text


def newgame(opponent):
    return dm.MESSAGE_TEMPLATES['newgame'] % {'opponent': opponent}


def shot(shot):
    return dm.MESSAGE_TEMPLATES['shot'] % {'shot': shot}


def miss(shot):
    return dm.MESSAGE_TEMPLATES['miss'] % {'shot': shot}


def kill():
    return dm.MESSAGE_TEMPLATES['kill']
Ejemplo n.º 3
0
def bot_handler(bot, update):
    session_obj = session.get(update.message.chat_id)
    dm_obj = dm.DialogManager(session_obj)
    dmresponse = dm_obj.handle_message(update.message.text)
    bot.send_message(chat_id=update.message.chat_id, text=dmresponse.text)