tjtanjin / react-chatbotify

A modern React library for creating a flexible and extensible chatbot.
https://react-chatbotify.com
MIT License
148 stars 68 forks source link

[Bug] chatDisabled on block not working. #92

Closed clluiz closed 1 month ago

clluiz commented 1 month ago

Bug Description The property chatDisabled does not override the value defined in the chat options.

Steps To Reproduce

That's my chat setup:

<ChatBot
      flow={flow}
      options={{
        tooltip: {
          mode: "NEVER",
        },
        chatInput: {
          disabled: true,
          enabledPlaceholderText: "Escreva sua pergunta aqui",
        },
        notification: {
          disabled: true,
        },
        audio: {
          disabled: true,
        },
        chatHistory: {
          disabled: true,
        },
        emoji: {
          disabled: true,
        },
        theme: {
          primaryColor: "#A5A5FF",
          secondaryColor: "#A5A5FF",
        },
        header: {
          avatar: dora,
          title: "Dora",
        },
        chatButton: {
          icon: dora,
        },
        userBubbleStyle: {
          backgroundColor: "#FFA43A",
        },
        botBubble: {
          avatar: dora,
        },
        fileAttachment: {
          disabled: false,
        },
      }}
    />

My flow:

import axios from "axios"

async function perguntar(texto: string): Promise<string> {
  try {
    const resposta = await axios.get(
      `http://localhost:8084/api/v0/generate_sql?question=${texto}`,
    )
    const idSql = resposta.data.id
    const {
      data: { df },
    } = await axios.get(`http://localhost:8084/api/v0/run_sql?id=${idSql}`)
    console.log(df)
    const {
      data: { text },
    } = await axios.get(
      `http://localhost:8084/api/v0/generate_summary?id=${idSql}`,
    )
    return text
  } catch (error) {
    return JSON.stringify(error)
  }
}

export const flow = {
  start: {
    message: "Olá eu sou a Dora! \n Estou aqui para te auxiliar e te ajudar",
    transition: { duration: 1000 },
    path: "show_options",
  },
  show_options: {
    message: "Você pode saber mais sobre os seguintes assuntos",
    options: ["Score das oportunidades", "Desempenho dos vendedores"],
    path: (params) => {
      return params.userInput
    },
  },
  "Score das oportunidades": {
    message: "Você escolheu falar do Score da oportunidades",
    options: [
      "Qual o score médio das oportunidades abertas cadastradas para a empresa YouX Group?",
    ],
    path: (params) => {
      return params.userInput
    },
  },
  "Qual o score médio das oportunidades abertas cadastradas para a empresa YouX Group?":
    {
      message: async (params) => {
        const r = await perguntar(
          "Qual o score médio das oportunidades abertas cadastradas para a empresa YouX Group?",
        )
        return r
      },
      transition: { duration: 1000 },
      path: "show_options",
    },
  "Desempenho dos vendedores": {
    message: "Você escolheu falar do desempenho dos vendedores",
    transition: { duration: 1000 },
    path: "escolher_vendedores"
  },
  "escolher_vendedores": {
    message: "Digite o nome do vendedor",
    chatDisabled: false,
  },
  end: {
    message: (params) => `I see you are ${params.userInput}!`,
    chatDisabled: true,
  },
}

Expected behavior

According to the docs the chatDisabled option in a block must override the chatInput option. However the text field is still disabled.

Desktop (please complete the following information):

tjtanjin commented 1 month ago

Hey @clluiz, thank you for raising this up. The following behavior was confirmed:

It's a one line fix, but hasn't been surfaced until now 🥹Bumping to v2.0.0-beta.4 will get you the fix 😊