def chat(): """Converse with a bot""" try: input = json.loads(request.values['input']) bot = request.values['bot'] channel = request.values['channel'] bot_config = None if app.config['DEBUG']: bot_config = json.loads(request.values.get('bot_config', '{}')) convo_id = request.values.get('conversation_id', None) response = converse(channel, bot, convo_id, input, bot_config=bot_config) return jsonr(response) except Exception as e: # TODO: classify and return error types/codes # TODO: log errors, store partially completed convo/tx objects with status? dbg(traceback.format_exc()) error(str(e)) response = {'status': 'error', 'response': 'Something went wrong.'} if app.config['DEBUG']: response['error'] = traceback.format_exc() return jsonr(response)
def fulfillment_with_question(): """Example fulfillment with a question response""" data = request.json dbg('called') dbg(data) response = { 'status': 'success', 'interaction': { 'type': 'question', 'messages': [ 'I couldnt find anyone to help. Would you like to try MyIntent instead?' ], 'intent_actions': { CommonIntents.Yes: { 'name': 'TriggerIntent', 'params': { 'intent_name': 'MyIntent' } }, CommonIntents.No: Actions.EndConversation } } } return jsonr(response)
def fulfillment(): """Example fulfillment""" data = request.json dbg('called') dbg(data) response = {'status': 'success', 'interaction': None} return jsonr(response)
def fulfillment_with_interaction(): """Example fulfillment with a interaction response""" data = request.json dbg('called') dbg(data) response = { 'status': 'success', 'interaction': 'Great job, you finished this!' } return jsonr(response)
def fulfillment_with_error_status(): """Example fulfillment with an error response""" data = request.json dbg('called') dbg(data) response = { 'status': 'error', 'interaction': None, 'status_reason': 'Fulfillment failed' } return jsonr(response)
def fulfillment_with_action(): """Example fulfillment with an action response""" data = request.json dbg('called') dbg(data) response = { 'status': 'success', 'interaction': 'Great job, you are done.', 'action': Actions.EndConversation } return jsonr(response)