Ejemplo n.º 1
0
def update_intent(id):
    """
    Update a story from the provided json
    :return:
    """
    json_data = loads(request.get_data())
    intent = Intent.objects.get(id=ObjectId(id))
    intent = update_document(intent, json_data)
    intent.save()
    return 'success', 200
Ejemplo n.º 2
0
def create_intent():
    """
    Create a story from the provided json
    :param json:
    :return:
    """
    content = request.get_json(silent=True)

    intent = Intent()
    intent.name = content.get("name")
    intent.intentId = content.get("intentId")
    intent.speechResponse = content.get("speechResponse")
    intent.trainingData = []

    if content.get("apiTrigger") is True:
        intent.apiTrigger = True
        api_details = ApiDetails()
        isJson = content.get("apiDetails").get("isJson")
        api_details.isJson = isJson
        if isJson:
            api_details.jsonData = content.get("apiDetails").get("jsonData")

        api_details.url = content.get("apiDetails").get("url")
        api_details.headers = content.get("apiDetails").get("headers")
        api_details.requestType = content.get("apiDetails").get("requestType")
        intent.apiDetails = api_details
    else:
        intent.apiTrigger = False

    if content.get("parameters"):
        for param in content.get("parameters"):
            parameter = Parameter()
            update_document(parameter, param)
            intent.parameters.append(parameter)
    try:
        story_id = intent.save()
    except Exception as e:
        return build_response.build_json({"error": str(e)})

    return build_response.build_json({
        "_id": str(story_id.id)
    })
Ejemplo n.º 3
0
def update_entity(id):
    """
    Update a story from the provided json
    :param id:
    :return:
    """
    json_data = loads(request.get_data())
    entity = Entity.objects.get(id=ObjectId(id))
    entity = update_document(entity, json_data)
    entity.save()
    return build_response.sent_ok()
Ejemplo n.º 4
0
def update_entity(id):
    """
    Update a story from the provided json
    :param intent_id:
    :param json:
    :return:
    """
    json_data = loads(request.get_data())
    entity = Entity.objects.get(id=ObjectId(id))
    entity = update_document(entity, json_data)
    entity.save()
    return 'success', 200
Ejemplo n.º 5
0
def import_json(json_file):
    json_data = json_file.read()
    # intents = Intent.objects.from_json(json_data)
    intents = loads(json_data)

    creates_intents = []
    for intent in intents:
        new_intent = Intent()
        new_intent = update_document(new_intent, intent)
        new_intent.save()
        creates_intents.append(new_intent)
    return creates_intents
Ejemplo n.º 6
0
def update_entity(id):
    """
    Update a story from the provided json
    :param intent_id:
    :param json:
    :return:
    """
    json_data = loads(request.get_data())
    entity = Entity.objects.get(id=ObjectId(id))
    entity = update_document(entity, json_data)
    entity.save()
    return 'success', 200
Ejemplo n.º 7
0
def update_user(id):
    """
    Update a story from the provided json
    :param intent_id:
    :param json:
    :return:
    """
    json_data = loads(request.get_data().decode('utf-8'))
    user = User.objects.get(id=ObjectId(id))
    user = update_document(user, json_data)
    user_id.save()
    return 'success', 200
Ejemplo n.º 8
0
def import_json(json_file, botId):
    print("in json_file")
    json_data = json_file.read()
    print(json_data)
    # intents = Intent.objects.from_json(json_data)
    import json
    intents = json.loads(json_data)

    creates_intents = []
    for intent in intents:
        new_intent = Intent()
        new_intent = update_document(new_intent, intent)
        new_intent.save()
        creates_intents.append(new_intent)
    return creates_intents