Group Implicit Negative feedback by problem

To get the negative implicit feedback you can use the get-interaction-aggregates endpoint, grouping by type_of_problem

import requests

url = "https://backend.nebuly.com/api/external/get-interaction-aggregates"

payload = {
    "time_range": {
        "start": "2024-05-30",
        "end": "2024-05-01"
    },
    "filters": [],
    "limit": 10,
    "offset": 0,
    "group_by": {
        "kind": "type_of_problem"
    },
}
headers = {
    "Authorization": "Bearer <MyToken>",
    "Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers)

types_of_problem = [
    {
        "type of problem": data["group_name"],
        "interactions": data["n_interactions"],
        "users": data["n_users"]
    }
    for data in response.json()["data"]
]

In order to retrieve the interactions affected by a specific problem you can use the get-interactions endpoint:

type_of_problem = types_of_problem[0]
url = "https://backend.nebuly.com/api/external/get-interactions"

payload = {
    "time_range": {
        "start": "2024-05-30",
        "end": "2024-05-01"
    },
    "filters": [
        {
            "kind": "type_of_problem",
            "values": [type_of_problem]
        }
    ],
    "limit": 10,
    "offset": 0
}

interactions_response = requests.request("POST", url, json=payload, headers=headers)
interactions = [
    {
        "id": interaction.id,
        "user request": interacting.user_query
    }
    for interaction in interactions_response.json()["data"]
]

We can then add the details for each interaction (like the message explaining the problem in details) using the get-interaction-details endpoint.

interaction_id = interactions[0]["id"]
url = "https://backend.nebuly.com/api/external/export/interactions/detail/{interaction_id}"

details_response = requests.request("GET", url, headers=headers)

Group Implicit Negative feedback by intent

To group the implicit negative feedback by intent, we just need to get from the get-interaction-aggregates the intents, filtering them by negative_implicit_feedback.

import requests

url = "https://backend.nebuly.com/api/external/get-interaction-aggregates"

payload = {
    "time_range": {
        "start": "2024-05-30",
        "end": "2024-05-01"
    },
    "filters": [
        {
            "kind": "user_feedback",
            "values": ["negative_implicit_feedback"]
        }
    ],
    "limit": 10,
    "offset": 0,
    "group_by": {
        "kind": "user_intent"
    },
}
headers = {
    "Authorization": "Bearer <MyToken>",
    "Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers)

intents_with_negative_feedback = [
    {
        "intent": data["group_name"],
        "n_feedback": data["n_negative_implicit_user_feedback"],
        "users": data["n_users"]
    }
    for data in response.json()["data"]
]

You can then retrieve the negative interactions for an intent using the get-interactions endpoint and filtering by the intent and negative_implicit_feedback.

user_intent_with_negative_feedback = intents_with_negative_feedback[0]["intent"]
url = "https://backend.nebuly.com/api/external/get-interactions"

payload = {
    "time_range": {
        "start": "2024-05-30",
        "end": "2024-05-01"
    },
    "filters": [
        {
            "kind": "user_feedback",
            "values": ["negative_implicit_feedback"]
        },
        {
            "kind": "user_intent",
            "values": [user_intent_with_negative_feedback]
        }
    ],
    "limit": 10,
    "offset": 0
}

interaction_response = requests.request("POST", url, json=payload, headers=headers)
interactions_with_negative_feedback = [
    {
        "id": interaction.id,
        "user request": interacting.user_query
    }
    for interaction in interactions_response.json()["data"]
]