Services Layer (services)

This package contains the business logic of the application, acting as an intermediary between the web routes and the backend data/AI layers.

Authentication Service

class kusibot.services.auth_service.AuthService[source]

Service class for handling user authentication and registration.

user_repository

Repository for user data access.

Type:

UserRepository

possible_login(identifier, password)[source]

Logs in a user with the given identifier and password.

Parameters:
  • identifier (str) – The username or email of the user.

  • password (str) – The password of the user.

Returns:

The authenticated user object if login is successful, otherwise None.

Return type:

User

register(username, email, password, is_professional=False)[source]

Registers a new user in KusiBot.

Parameters:
  • username (str) – The username of the new user.

  • email (str) – The email of the new user.

  • password (str) – The password of the new user.

  • is_professional (bool) – Whether the user is a professional user or not.

Chatbot Service

class kusibot.services.chatbot_service.ChatbotService[source]

Service class for handling chatbot interactions.

conv_repo

Repository for conversation data access.

Type:

ConversationRepository

msg_repo

Repository for message data access.

Type:

MessageRepository

assessment_repo

Repository for assessment data access.

Type:

AssessmentRepository

user_agents

A dictionary to store and manage a unique Manager Agent instance for each active user session, mapping user_id to agent instance.

Type:

dict

_clear_user_agent(user_id)[source]

Clears the chatbot manager for the user, effectively resetting their state.

Parameters:

user_id – ID of the user to clear the chatbot manager for.

_get_or_create_chatbot_manager(user_id)[source]

Gets or creates a ChatbotManagerAgent for the user to handle chatbot interactions keeping user-specific state and conversation management.

Parameters:

user_id – ID of the user to get or create the chatbot manager for.

Returns:

The chatbot manager for the user.

Return type:

ChatbotManagerAgent

create_or_get_conversation(user_id)[source]

Creates a new conversation for the authenticated user or gets the current conversation.

Parameters:

user_id – ID of the current user to retrieve or create the conversation from.

Returns:

Array of JSON messages for the new/current conversation.

Return type:

messages

end_conversation(user_id)[source]

Ends the current conversation and clear the user agent for the authenticated user.

Parameters:

user_id – ID of the current user to end the conversation for.

Returns:

True if the conversation was successfully ended, False otherwise.

Return type:

bool

get_response(user_input, user_id)[source]

Generates a response from the chatbot.

Parameters:
  • user_input – The message sent by the user.

  • user_id – ID of the user making the request.

Returns:

The chatbot’s response to the user’s input.

Return type:

response

Dashboard Service

class kusibot.services.dashboard_service.DashboardService[source]

Service class for handling dashboards interactions.

user_repo

Repository for user data access.

Type:

UserRepository

conv_repo

Repository for conversation data access.

Type:

ConversationRepository

msg_repo

Repository for message data access.

Type:

MessageRepository

assessment_repo

Repository for assessment data access.

Type:

AssessmentRepository

assesment_question_repo

Repository for assessment question data access.

Type:

AssessmentQuestionRepository

get_assessments_for_user(user_id)[source]

Retrieves assessments and their questions for a given user.

Parameters:

user_id – The ID of the user for whom to retrieve assessments.

Returns:

A dictionary containing the assessments and their questions.

Return type:

dict

get_chat_users()[source]

Retrieves a list of non-professional users for the dashboard.

Returns:

A list of dictionaries containing user IDs and usernames.

Return type:

list

get_conversation_messages(conversation_id)[source]

Retrieves the messages of a specific conversation by its ID.

Parameters:

conversation_id – The ID of the conversation to retrieve.

Returns:

A dictionary containing the conversation messages.

Return type:

dict

get_conversations_for_user(user_id)[source]

Retrieves the conversation history for a given user.

Parameters:

user_id – The ID of the user for whom to retrieve the conversation.

Returns:

A dictionary containing the conversation history with the needed details.

Return type:

dict