History

D-Bus interfaces that defines and powers our commands.

HISTORY_NOT_AVAILABLE_MESSAGE = 'Looks like no history was found. Try asking something first!'

Default message in case a history chat is not available.

class HistoryInterface(implementation)[source]

The DBus interface of a history

Constructor of the class

Parameters:

implementation (DaemonContext) – The implementation context to be used in an interface.

ClearAllHistory(user_id)[source]

Clear the user history.

Return type:

None

Parameters:

user_id (Str) – The identifier of the user.

ClearHistory(user_id, from_chat)[source]

Clear the user history.

Return type:

None

Parameters:

user_id (Str) – The identifier of the user.

GetFilteredConversation(user_id, filter, from_chat)[source]

Get last conversation from history.

Return type:

Dict[str, Variant]

Parameters:
  • user_id (Str) – The identifier of the user.

  • filter (str) – The filter

  • from_chat (Str) – Chat name identifier

Returns:

Structure of history entries.

Return type:

Structure

GetFirstConversation(user_id, from_chat)[source]

Get first conversation from history.

Return type:

Dict[str, Variant]

Parameters:
  • user_id (Str) – The identifier of the user.

  • from_chat (Str) – Chat name identifier

Returns:

A single history entry in a dbus structure format.

Return type:

Structure

GetHistory(user_id)[source]

Get all conversations from history.

Return type:

Dict[str, Variant]

Parameters:

user_id (Str) – The identifier of the user.

Returns:

The history entries in a dbus structure format.

Return type:

Structure

GetLastConversation(user_id, from_chat)[source]

Get last conversation from history.

Return type:

Dict[str, Variant]

Parameters:
  • user_id (Str) – The identifier of the user.

  • from_chat (Str) – Chat name identifier

Raises:
  • HistoryNotEnabledError – If history is not enabled.

  • HistoryNotAvailableError – If no history is available for the user.

Returns:

A single history entyr in a dbus structure format.

Return type:

Structure

WriteHistory(chat_id, user_id, question, response)[source]

Write a new entry to the user history.

Return type:

None

Parameters:
  • chat_id (Str) – The identifier of the chat session.

  • user_id (Str) – The identifier of the user.

  • question (Str) – The question asked by the user.

  • response (Str) – The response given to the user.

_abc_impl = <_abc._abc_data object>
_verify_caller_authorization(sender, requested_user_id)[source]

Verify that the caller is authorized to access the requested user’s data.

Return type:

None

Parameters:
  • sender – The D-Bus sender.

  • requested_user_id (str) – The user ID being requested in the method call.

Raises:

PermissionError – If the caller’s user ID doesn’t match the requested user ID.

_filter_history_with_keyword(entries, keyword)[source]

Filter the history entries based on keyword.

Return type:

list[InteractionModel]

Parameters:
  • entries (list[HistoryModel]) – The list of entries returned from the database

  • keyword (str) – The keyword to filter.

Returns:

Filtered results.

Return type:

list[InteractionModel]

_parse_interactions(histories)[source]

Parse the history interactions in a common format for all methods

Return type:

HistoryList

Parameters:

histories (list[HistoryModel]) – Histories fetched from the database.

Returns:

An instance of HistoryEntry with all necessary information.

Return type:

HistoryEntry