示例#1
0
文件: main.py 项目: safkass/diagbot
def check_appointment(req):
    """Returns a string containing text with a response to the user
    with the diagbot or a prompt for more information

    Takes user's query and returns checks database for doctors appointment
    """
    parameters = req['queryResult']['parameters']

    print('Dialogflow Parameters:')
    print(json.dumps(parameters, indent=4))

    # validate request parameters, return an error if there are issues
    error, diagbot_params = validate_params(req)
    if error:
        log.error(error)
        return error

    # create a diagbot object which retrieves the diagbot from a external API
    try:
        diagbot = Diagbot(diagbot_params)
    # return an error if there is an error getting the diagbot
    except (ValueError, IOError) as error:
        log.error(error)
        return error

    response = diagbot.check_appointment()

    return {'fulfillmentText': response}
示例#2
0
文件: main.py 项目: safkass/diagbot
def yesSamePreference(req):
    """Returns a string containing text with a response to the user
    with a indication if the outfit provided is appropriate for the
    current weather or a prompt for more information

    Takes a city, outfit and (optional) dates
    uses the template responses found in Diagbot_reply.py as templates
    and the outfits listed in weather_entities.py
    """

    # validate request parameters, return an error if there are issues
    error, diagbot_params = validate_params(req)
    if error:
        log.error(error)
        return error

    # create a diagbot object which retrieves the diagbot from a external API
    try:
        diagbot = Diagbot(diagbot_params)
    # return an error if there is an error getting the diagbot
    except (ValueError, IOError) as error:
        log.error(error)
        return error

    return {'fulfillmentText': diagbot.yes_same_preference()}
示例#3
0
文件: main.py 项目: safkass/diagbot
def new_appointment(req):
    """Returns a string containing a human-readable response to the user
    with the available slots or a prompt for more information

    Takes time, date parameters and check for available slots
    """

    # validate request parameters, return an error if there are issues
    error, diagbot_params = validate_params(req)
    if error:
        log.error(error)
        return error


    # create a diagbot object which retrieves the diagbot from a external API
    try:
        diagbot = Diagbot(diagbot_params)
    # return an error if there is an error getting the diagbot
    except (ValueError, IOError) as error:
        log.error(error)
        return error

    # get the response
    obj = diagbot.new_appointment()
    print('appointment response object')
    print(obj)

    quick_reply = {}

    if obj['context'] == CONFIRM_APPOINTMENT_FOLLOWUP:
        outputContext = req['queryResult']['outputContexts']
    elif obj['context'] == CREATE_APPOINTMENT_FOLLOWUP:
        outputContext = [{
            'name': '{}/contexts/createappointment-followup'.format(req['session']),
            'lifespanCount': 1
        }]
        quick_reply = {
            "telegram": {
                "replies": [
                    [{
                        "text": 'Yeah, Sure!',
                        "callback_data": 'yes',
                    }],
                    [{
                        "text": 'No!',
                        "callback_data": 'no',
                    }]
                ],
                "choices": [],
                "symptoms": [],
            }
        }
    else:
        outputContext = req['queryResult']['outputContexts']

    return {
        "outputContexts": outputContext,
        "fulfillmentText": obj['fulfillmentText'],
        "payload": quick_reply
    }
示例#4
0
文件: main.py 项目: safkass/diagbot
def diagnose(req):
    """Returns a string containing text with a response to the user
    with a indication of user's predicted condition or a prompt to answer questions for more information

    Takes an age, gender, primary symptom and (optional) body part.
    """

    parameters = req

    # validate request parameters, return an error if there are issues
    error, diagbot_params = validate_params(parameters)
    if error:
        log.error(error)
        return error


    # create a diagbot object which retrieves the diagbot from a external API
    try:
        diagbot = Diagbot(diagbot_params)
    # return an error if there is an error getting the diagbot
    except (ValueError, IOError) as error:
        log.error(error)
        return error

    obj = diagbot.diagnose()

    log.log(obj)

    outputContext = req['queryResult']['outputContexts']
    #     [{
    #     'name': '{}/contexts/{}'.format(req['session'], obj['context']),
    #     'lifespanCount': 5
    # }]

    replies = []
    if 'choices' in obj:
        for choice in obj['choices']:
            replies.append([{
                "text": choice['name'],
                "callback_data": choice['name'].lower(),
            }])

        return {
            "outputContexts": outputContext,
            "fulfillmentText": obj['fulfillmentText'],
            "payload": {
                "telegram": {
                    "replies": replies,
                    "choices": obj['choices'],
                    "symptoms": obj['symptoms'],
                    # "req": obj['req']
                }
            },
        }
    else:
        return {
            "outputContexts": outputContext,
            "fulfillmentText": obj['fulfillmentText'],
        }
示例#5
0
文件: main.py 项目: safkass/diagbot
def noSamePreference(req):
    """Returns a string containing text with a response to the user
    with a indication if temperature provided is consisting with the
    current weather or a prompt for more information

    Takes a city, temperature and (optional) dates.  Temperature ranges for
    hot, cold, chilly and warm can be configured in config.py
    uses the template responses found in Diagbot_reply.py as templates
    """

    parameters = req

    # validate request parameters, return an error if there are issues
    error, diagbot_params = validate_params(parameters)
    if error:
        log.error(error)
        return error


    # create a diagbot object which retrieves the diagbot from a external API
    try:
        diagbot = Diagbot(diagbot_params)
    # return an error if there is an error getting the diagbot
    except (ValueError, IOError) as error:
        log.error(error)
        return error

    obj = diagbot.no_same_preference()

    if obj['parameters']:
        res = {
                "followupEventInput": {
                    "name": "createAppointment",
                    "parameters": {
                        "phoneNumber": obj['parameters']['phone'],
                        "fullname": obj['parameters']['name']
                    },
                    "languageCode": "en-US",
                },
            }

    return res
示例#6
0
文件: main.py 项目: safkass/diagbot
def confirm_appointment(req):
    """Returns a string containing text with a response to the user
    with a confirmation of user's appointment
    """

    # validate request parameters, return an error if there are issues
    error, diagbot_params = validate_params(req['queryResult']['outputContexts'][0], True, req)
    if error:
        log.error(error)
        return error

    # create a diagbot object which retrieves the diagbot from a external API
    try:
        diagbot = Diagbot(diagbot_params)
    # return an error if there is an error getting the diagbot
    except (ValueError, IOError) as error:
        log.error(error)
        return error

    return {
        'fulfillmentText': diagbot.confirm_appointment(),
        # "payload": quick_reply
    }