Cross wizard contexts despite working on different threads

I have a problem with assistant api.
The fact is that I made a working chatbot that answers user questions via chat.
The problem is that if in a chat (1) he writes to me, hello this is my name “e.g. Steve”, and in another chat with a totally different thread,
They tell me, treat me by my name, he responds as if I were “Steve.”
It is as if the contexts intersect, it is not so obvious but it happens how I can solve it. This is my code.


const scrapeCourseDetails = require("./scrapeCourseDetails");
const getThemes = require("./getThemes");
const searchCourses = require("./searchCourses");
const relatedCourse = require("./relatedCourse");
const priceCourse = require("./priceCourse");
const flagUserAsCallRequired = require("./flagUserAsCallRequired");
const flagKanbanInterest = require("./flagKanbanInterest");
const flagKanbanDiscussion = require("./flagKanbanDiscussion");
const flagKanbanDesicion = require("./flagKanbanDecision");
const conversionCurrency = require("./conversionCurrency");
const requiresIntervention = require("./requiresIntervention");
const toolsConfig = require("./toolsConfig");

const openai = new OpenAI({
  apiKey: process.env.APIOPENAI,
});

async function getAssistantResponse(userQuestion, thread, phoneNumber) {
  global.scrapeCourseDetails = scrapeCourseDetails;
  global.getThemes = getThemes;
  global.searchCourses = searchCourses;
  global.relatedCourse = relatedCourse;
  global.priceCourse = priceCourse;
  global.flagUserAsCallRequired = flagUserAsCallRequired;
  global.flagKanbanInterest = flagKanbanInterest;
  global.flagKanbanDiscussion = flagKanbanDiscussion;
  global.flagKanbanDesicion = flagKanbanDesicion;
  global.conversionCurrency = conversionCurrency;
  global.requiresIntervention = requiresIntervention;

  await openai.beta.threads.messages.create(thread, {
    role: "user",
    content: userQuestion,
  });

  const run = await openai.beta.threads.runs.create(thread, {
    assistant_id: "id del asistente",
  });

  let runStatus = await openai.beta.threads.runs.retrieve(thread, run.id);

  console.log("ID ASISTENTE" + assistant.id);

  while (runStatus.status !== "completed") {
    await new Promise((resolve) => setTimeout(resolve, 2000));
    runStatus = await openai.beta.threads.runs.retrieve(thread, run.id);

    while (runStatus.status === "in_progress") {
      console.log("Esperando respuesta");
      await new Promise((resolve) => setTimeout(resolve, 2000));
      runStatus = await openai.beta.threads.runs.retrieve(thread, run.id);
    }

    if (runStatus.status === "requires_action") {
      console.log(
        "Funcion requerida: " +
          JSON.stringify(
            runStatus.required_action.submit_tool_outputs.tool_calls[0].function
              .name
          )
      );

      const toolCalls =
        runStatus.required_action.submit_tool_outputs.tool_calls;
      const toolOutputs = [];

      for (const toolCall of toolCalls) {
        const functionName = toolCall.function.name;

        const args = JSON.parse(toolCall.function.arguments);
        // Si la funcion es flagKanbanInterest, se le pasa el phoneNumber
        if (
          functionName === "flagKanbanInterest" ||
          "flagKanbanDiscussion" ||
          "flagUserAsCallRequired" ||
          "requiresIntervention"
        ) {
          args.phoneNumber = phoneNumber;
        }

        const output = await global[functionName].apply(null, [args]);

        toolOutputs.push({
          tool_call_id: toolCall.id,
          output: output,
        });
      }

      await openai.beta.threads.runs.submitToolOutputs(thread, run.id, {
        tool_outputs: toolOutputs,
      });
      continue;
    }
  }

  const messages = await openai.beta.threads.messages.list(thread);
  const lastMessageForRun = messages.data
    .filter(
      (message) => message.run_id === run.id && message.role === "assistant"
    )
    .pop();

  return lastMessageForRun.content[0].text.value;
}

async function bot(question, thread, phoneNumber) {
  try {
    const userQuestion = question;
    const response = await getAssistantResponse(
      userQuestion,
      thread,
      phoneNumber
    );
    return {
      response: response,
      availableBot: true,
    };
  } catch (error) {
    console.error(error);
  }
}
// prueba bot
module.exports = bot;