docstr: Updates a chatbot by name, creating one if it doesn't exist
docstr_tok: ["Updates","a","chatbot","by","name",",","creating","one","if","it","does","n't","exist"]
code: def put(self, project_name, chatbot_name):
      """Updates a chatbot by name, creating one if it doesn't exist"""
  
      # Check for required parameters.
      if "chatbot" not in request.json:
          return http_error(
              HTTPStatus.BAD_REQUEST,
              "Missing parameter",
              'Must provide "chatbot" parameter in POST body',
          )
      chatbot_controller = ChatBotController()
  
      try:
          existing_chatbot = chatbot_controller.get_chatbot(
              chatbot_name, project_name=project_name
          )
      except ValueError:
          # Project needs to exist.
          return http_error(
              HTTPStatus.NOT_FOUND,
              "Project not found",
              f"Project with name {project_name} does not exist",
          )
  
      chatbot = request.json["chatbot"]
      name = chatbot.get("name", None)
      agent_name = chatbot.get("agent_name", None)
      model_name = chatbot.get("model_name", None)
      database_id = chatbot.get("database_id", None)
      is_running = chatbot.get("is_running", None)
      params = chatbot.get("params", None)
  
      # Model needs to exist.
      if model_name is not None:
          session_controller = SessionController()
          (
              model_name_no_version,
              version,
          ) = Predictor.get_name_and_version(model_name)
          try:
              session_controller.model_controller.get_model(
                  model_name_no_version,
                  version=version,
                  project_name=project_name,
              )
          except PredictorRecordNotFound:
              return http_error(
                  HTTPStatus.NOT_FOUND,
                  "Model not found",
                  f"Model with name {model_name} not found",
              )
  
      # Agent needs to exist.
      if agent_name is not None:
          agents_controller = AgentsController()
          agent = agents_controller.get_agent(agent_name, project_name)
          if agent is None:
              return http_error(
                  HTTPStatus.NOT_FOUND,
                  "Agent not found",
                  f"Agent with name {agent_name} not found",
              )
  
      # Chatbot must not exist with new name.
      if name is not None and name != chatbot_name:
          chatbot_with_new_name = chatbot_controller.get_chatbot(
              name, project_name=project_name
          )
          if chatbot_with_new_name is not None:
              return http_error(
                  HTTPStatus.CONFLICT,
                  "Chatbot already exists",
                  f"Chatbot with name {name} already exists. Please choose a different one.",
              )
  
      if existing_chatbot is None:
          # Create
          return create_chatbot(project_name, name, chatbot)
  
      if "db_params" in chatbot and "db_engine" in chatbot:
          session_controller = SessionController()
  
          db_name = chatbot["name"] + "_db"
  
          # try to drop
          existing_db = session_controller.integration_controller.get(
              db_name
          )
          if existing_db:
              # drop
              session_controller.integration_controller.delete(db_name)
  
          database_id = session_controller.integration_controller.add(
              db_name, chatbot["db_engine"], chatbot["db_params"]
          )
      # Update
      updated_chatbot = chatbot_controller.update_chatbot(
          chatbot_name,
          project_name=project_name,
          name=name,
          model_name=model_name,
          agent_name=agent_name,
          database_id=database_id,
          is_running=is_running,
          params=params,
      )
      return updated_chatbot.as_dict()
  
file_path: mindsdb/mindsdb/api/http/namespaces/chatbots.py
imports: from http import HTTPStatus
  from flask import request
  from flask_restx import Resource
  from mindsdb.api.http.namespaces.configs.projects import ns_conf
  from mindsdb.api.executor.controllers.session_controller import SessionController
  from mindsdb.api.http.utils import http_error
  from mindsdb.interfaces.agents.agents_controller import AgentsController
  from mindsdb.interfaces.chatbot.chatbot_controller import ChatBotController
  from mindsdb.interfaces.model.functions import PredictorRecordNotFound
  from mindsdb.interfaces.storage.db import Predictor
label_desc: Use image node_id 2 for calling the ChatBotResource obj's underlying member method code with example usage: obj.put(project_name, chatbot_name) and returns: updated_chatbot, http_error, create_chatbot, http_error, http_error, http_error, http_error