Пример #1
0
async def chat_history_users(month: HistoryMonth = 1, current_user: User = Depends(auth.get_current_user)):

    """
    Fetches the list of user who has conversation with the agent
    """
    users, message = ChatHistory.fetch_chat_users(current_user.get_bot(), month)
    return {"data": {"users": users}, "message": message}
Пример #2
0
async def count_new_users(month: HistoryMonth = 1,
                          current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the number of new users of the bot
    """
    user_count, message = ChatHistory.new_users(current_user.get_bot(), month)
    return {"data": user_count, "message": message}
Пример #3
0
async def count_new_users_range(month: HistoryMonth = 6,
                                current_user: User = Depends(
                                    auth.get_current_user)):
    """
    Fetches the counts of new users of the bot for previous months
    """
    range_value = ChatHistory.new_users_range(current_user.get_bot(), month)
    return {"data": range_value}
Пример #4
0
async def flat_conversations(month: int = 3, current_user: User = Depends(auth.get_current_user_and_bot)):
    """
    Fetches the flattened conversation data of the bot for previous months
    """
    flat_data, message = ChatHistory.flatten_conversations(
        current_user.get_bot(), month
    )
    return {"data": flat_data, "message": message}
Пример #5
0
async def conversation_time(month: HistoryMonth = 1,
                            current_user: User = Depends(
                                auth.get_current_user)):
    """
    Fetches the duration of the chat that took place between the users and the agent"""
    conversation_time, message = ChatHistory.conversation_time(
        current_user.get_bot(), month)
    return {"data": conversation_time, "message": message}
Пример #6
0
async def visitor_hit_fallback(month: HistoryMonth = 1, current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the number of times the agent hit a fallback (ie. not able to answer) to user queries
    """
    visitor_hit_fallback, message = ChatHistory.visitor_hit_fallback(
        current_user.get_bot(), month
    )
    return {"data": visitor_hit_fallback, "message": message}
Пример #7
0
async def fallback_trend(month: HistoryMonth = 6, current_user: User = Depends(auth.get_current_user_and_bot)):
    """
    Fetches the fallback count of the bot for previous months
    """
    range_value, message = ChatHistory.fallback_count_range(
        current_user.get_bot(), month
    )
    return {"data": range_value, "message": message}
Пример #8
0
async def retention_trend(month: HistoryMonth = 6, current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the counts of user retention percentages of the bot for previous months
    """
    range_value, message = ChatHistory.user_retention_range(
        current_user.get_bot(), month
    )
    return {"data": range_value, "message": message}
Пример #9
0
async def chat_history(
    sender: Text, month: HistoryMonth = 1,current_user: User = Depends(auth.get_current_user)
):
    """
    Fetches the list of conversation with the agent by particular user
    """
    history, message = ChatHistory.fetch_chat_history(current_user.get_bot(), sender, month)
    return {"data": {"history": list(history)}, "message": message}
Пример #10
0
async def calculate_retention(month: HistoryMonth = 1, current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the user retention percentage of the bot
    """
    retention_count, message = ChatHistory.user_retention(
        current_user.get_bot(), month
    )
    return {"data": retention_count, "message": message}
Пример #11
0
async def complete_conversation_trend(month: HistoryMonth = 6, current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the counts of successful conversations of the bot for previous months
    """
    range_value, message = ChatHistory.successful_conversation_range(
        current_user.get_bot(), month
    )
    return {"data": range_value, "message": message}
Пример #12
0
async def complete_conversations(month: HistoryMonth = 1, current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the number of successful conversations of the bot, which had no fallback
    """
    conversation_count, message = ChatHistory.successful_conversations(
        current_user.get_bot(), month
    )
    return {"data": conversation_count, "message": message}
Пример #13
0
async def user_with_metrics(
        month: HistoryMonth = 1, current_user: User = Depends(auth.get_current_user)):
    """
    Fetches the list of user who has conversation with the agent with steps anf time
    """
    users, message = ChatHistory.user_with_metrics(
        current_user.get_bot(), month
    )
    return {"data": {"users": users}, "message": message}
Пример #14
0
async def count_engaged_users(request: ConversationFilter = ConversationFilter(), current_user: User = Depends(auth.get_current_user_and_bot)):

    """
    Fetches the number of engaged users of the bot
    """
    engaged_user_count, message = ChatHistory.engaged_users(
        current_user.get_bot(), request.month, request.engaged_users_threshold
    )
    return {"data": engaged_user_count, "message": message}
Пример #15
0
async def engaged_users_trend(month: HistoryMonth = 6, current_user: User = Depends(auth.get_current_user)):

    """
    Fetches the counts of engaged users of the bot for previous months
    """
    range_value, message = ChatHistory.engaged_users_range(
        current_user.get_bot(), month
    )
    return {"data": range_value, "message": message}
Пример #16
0
async def conversation_steps(month: HistoryMonth = 1,
                             current_user: User = Depends(
                                 auth.get_current_user)):
    """
     Fetches the number of conversation steps that took place in the chat between the users and the agent
     """
    conversation_steps, message = ChatHistory.conversation_steps(
        current_user.get_bot(), month)
    return {"data": conversation_steps, "message": message}
Пример #17
0
async def count_engaged_users(month: HistoryMonth = 1,
                              current_user: User = Depends(
                                  auth.get_current_user_and_bot)):
    """
    Fetches the number of engaged users of the bot
    """
    engaged_user_count, message = ChatHistory.engaged_users(
        current_user.get_bot(), month)
    return {"data": engaged_user_count, "message": message}
Пример #18
0
async def engaged_users_trend(request: ConversationFilter = ConversationFilter(), current_user: User = Depends(auth.get_current_user_and_bot)):

    """
    Fetches the counts of engaged users of the bot for previous months
    """
    range_value, message = ChatHistory.engaged_users_range(
        current_user.get_bot(), request.month, request.engaged_users_threshold
    )
    return {"data": range_value, "message": message}
Пример #19
0
    def test_visitor_hit_fallback_action_not_configured(
            self, mock_fallback_user_data, monkeypatch):
        def _mock_load_config(*args, **kwargs):
            return {"policies": [{"name": "RulePolicy"}]}

        monkeypatch.setattr(MongoProcessor, 'load_config', _mock_load_config)
        hit_fall_back, message = ChatHistory.visitor_hit_fallback(
            "5b029887-bed2-4bbb-aa25-bd12fda26244")
        assert hit_fall_back["fallback_count"] == 1
        assert hit_fall_back["total_count"] == 4
        assert message is None
Пример #20
0
 def test_visitor_hit_fallback_nlu_fallback_configured(
         self, mock_fallback_user_data):
     steps = [{
         "name": "nlu_fallback",
         "type": "INTENT"
     }, {
         "name": "utter_please_rephrase",
         "type": "BOT"
     }]
     rule = {'name': 'fallback_rule', 'steps': steps, 'type': 'RULE'}
     MongoProcessor().add_complex_story(
         rule, "5b029887-bed2-4bbb-aa25-bd12fda26244", 'test')
     hit_fall_back, message = ChatHistory.visitor_hit_fallback(
         "5b029887-bed2-4bbb-aa25-bd12fda26244")
     assert hit_fall_back["fallback_count"] == 2
     assert hit_fall_back["total_count"] == 4
     assert message is None
Пример #21
0
    def test_fetch_chat_history(self, monkeypatch):
        def events(*args, **kwargs):
            json_data = json.load(
                open("tests/testing_data/history/conversation.json"))
            return json_data['events'], None

        monkeypatch.setattr(ChatHistory, "fetch_user_history", events)

        history, message = ChatHistory.fetch_chat_history(
            sender="5e564fbcdcf0d5fad89e3acd", bot="tests")
        assert len(history) == 12
        assert history[0]["event"]
        assert history[0]["time"]
        assert history[0]["date"]
        assert history[0]["text"]
        assert history[0]["is_exists"] == False or history[0]["is_exists"]
        assert history[0]["intent"]
        assert history[0]["confidence"]
        assert message is None
Пример #22
0
 def test_fetch_chat_users_empty(self, mock_mongo_client_empty):
     users = ChatHistory.fetch_chat_users(bot="tests")
     assert len(users) == 2
Пример #23
0
 def test_fetch_chat_users_db_error(self, mock_mongo_processor):
     with pytest.raises(Exception):
         users = ChatHistory.fetch_chat_users(bot="tests")
         assert len(users) == 0
Пример #24
0
 def test_flatten_conversation_range(self, mock_mongo_client):
     f_count, message = ChatHistory.flatten_conversations("tests")
     assert f_count["conversation_data"] == []
     assert message is None
Пример #25
0
 def test_flatten_conversation_error(self, mock_mongo_processor):
     with pytest.raises(Exception):
         f_count, message = ChatHistory.flatten_conversations("tests")
         assert not f_count
         assert message is None
Пример #26
0
 def test_fallback_range(self, mock_mongo_client):
     f_count, message = ChatHistory.fallback_count_range("tests")
     assert f_count["fallback_counts"] == {}
     assert message is None
Пример #27
0
 def test_fallback_range_error(self, mock_mongo_processor):
     with pytest.raises(Exception):
         f_count, message = ChatHistory.fallback_count_range("tests")
         assert not f_count
         assert message is None
Пример #28
0
 def test_user_retention_range(self, mock_mongo_client):
     retention, message = ChatHistory.user_retention_range("tests")
     assert retention['retention_range'] == {}
     assert message is None
Пример #29
0
 def test_user_retention_range_error(self, mock_mongo_processor):
     with pytest.raises(Exception):
         retention, message = ChatHistory.user_retention_range("tests")
         assert not retention
         assert message is None
Пример #30
0
 def test_successful_conversation_range(self, mock_mongo_client):
     conversation_steps, message = ChatHistory.successful_conversation_range(
         "tests")
     assert conversation_steps["success_conversation_range"] == {}
     assert message is None