ChatBotPlugin Model

class smarter.apps.chatbot.models.ChatBotPlugin(*args, **kwargs)[source]

Bases: TimestampedModel

Represents the association between a ChatBot instance and its enabled plugins within the Smarter platform.

This model establishes a many-to-one relationship, where each plugin entry is linked to a specific ChatBot and references metadata describing the plugin. By maintaining this mapping, the platform can manage which plugins are available to each chatbot, enabling extensibility and customization of chatbot capabilities.

The ChatBotPlugin model supports use cases such as plugin activation, deactivation, and enumeration for individual chatbots. It is essential for scenarios where chatbots require additional functionality provided by external or internal plugins, such as integrations, enhanced processing, or custom behaviors.

Model Relationships

  • Each ChatBotPlugin is linked to one ChatBot instance.

  • Each ChatBotPlugin references one PluginMeta instance, which contains metadata about the plugin.

Usage Example

# Add a plugin to a chatbot
plugin_meta = PluginMeta.objects.get(name="weather")
chatbot_plugin = ChatBotPlugin.objects.create(chatbot=my_chatbot, plugin_meta=plugin_meta)

# List all plugins for a chatbot
plugins = ChatBotPlugin.objects.filter(chatbot=my_chatbot)

Notes

  • Plugin management and loading are handled via the PluginController and related infrastructure.

  • This model is intended for internal use to support dynamic extension of chatbot features.

  • Uniqueness is enforced for each (chatbot, plugin_meta) pair to prevent duplicate plugin assignments.

Parameters:

Relationship fields:

Parameters:
  • chatbot (ForeignKey to ChatBot) –

    Chatbot (related name: chatbotplugin)

    The ChatBot instance associated with this function. Example: ChatBot(id=1, name=”my-chatbot”)

  • plugin_meta (ForeignKey to PluginMeta) –

    Plugin meta (related name: chatbotplugin)

    The metadata for the plugin associated with the ChatBot.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

chatbot

ForeignKey to ChatBot

Chatbot (related name: chatbotplugin)

The ChatBot instance associated with this plugin.

Type:

Type

chatbot_id

Internal field, use chatbot instead.

created_at

DateTimeField

Created at

Timestamp indicating when the model instance was created. This field is automatically set to the current date and time when the instance is first created. It is indexed in the database for efficient querying.

Type:

Type

classmethod get_cached_objects(invalidate=False, chatbot=None)[source]

Retrieve a queryset of ChatBotPlugin instances associated with a ChatBot using caching.

Parameters:
  • invalidate (bool, optional) – Whether to invalidate the cache for this retrieval.

  • chatbot (ChatBot, optional) – The ChatBot instance for which to retrieve plugins.

Returns:

A queryset of ChatBotPlugin instances associated with the ChatBot.

Return type:

models.QuerySet[“ChatBotPlugin”]

id

BigAutoField

Primary key: ID

Type:

Type

classmethod load(chatbot, data)[source]

Load (aka import) a plugin from a data file in yaml or json format.

Parameters:
  • chatbot (ChatBot) – The ChatBot instance to associate with the plugin.

  • data – The plugin manifest data in yaml or json format.

Returns:

The created ChatBotPlugin instance.

Return type:

ChatBotPlugin

See Also:

objects = <django.db.models.Manager object>
property plugin: PluginBase | None

Returns the Plugin instance associated with this ChatBotPlugin.

Returns:

Plugin instance or None

Return type:

Optional[PluginBase]

plugin_meta

ForeignKey to PluginMeta

Plugin meta (related name: chatbotplugin)

The metadata for the plugin associated with the ChatBot.

Type:

Type

plugin_meta_id

Internal field, use plugin_meta instead.

classmethod plugins(chatbot)[source]

Returns a list of Plugin instances associated with the given ChatBot.

Parameters:

chatbot (ChatBot) – The ChatBot instance to retrieve plugins for.

Returns:

List of Plugin instances.

Return type:

List[PluginBase]

Raises:

SmarterValueError – If admin user for chatbot account is not found or if a plugin fails to load.

See Also:

  • smarter.apps.plugin.controller.PluginController

classmethod plugins_json(chatbot)[source]
Return type:

List[dict]

updated_at

DateTimeField

Updated at

Timestamp indicating when the model instance was last updated. This field is automatically updated to the current date and time whenever the instance is saved. It is indexed in the database for efficient querying.

Type:

Type