codigoencasa / builderbot

🤖 Crear Chatbot WhatsApp en minutos. Únete a este proyecto OpenSource
https://www.builderbot.app
MIT License
2.44k stars 833 forks source link

[🐛]Something wrong about addAction #1103

Closed marcellodpAS closed 1 month ago

marcellodpAS commented 1 month ago

¿Que versión estas usando?

v2

¿Sobre que afecta?

Flujo de palabras (Flow)

Describe tu problema

const welcomeFlow = addKeyword<Provider, Database>(["ciao"])
  .addAnswer(
    '🙌 Ciao e benvenuto nel chatbot per le prenotazioni'
  )
  .addAction(async (ctx, { flowDynamic, gotoFlow, state }): Promise<void> => {
    const customersData = await getAllCustomerData();
    const singleCustomerData = customersData.filter((customer) => {
      return Number(customer.attributes.phone) === Number(ctx.from);
    });

    if (singleCustomerData.length) {
      await state.update({ singleCustomerData: singleCustomerData[0] });
      return gotoFlow(flowB);
    }
    return await flowDynamic(
      'Non risulti ancora regitrato\n\nContatta l'istituto'
    );
  });

const flowB = addKeyword("")
  .addAnswer(
    [
      'Cosa vuoi fare',
      '1 - Effettua Prenotazione',
      '2 - Controllo Prenotazioni',
      '3 - Elimina Prenotazioni',
    ],
    { capture: true }
  )
  .addAction(async (ctx, { state, flowDynamic }) => {
    const singleCustomerData = await state.get("singleCustomerData");

    console.log(singleCustomerData);
    if (!singleCustomerData) {
      await flowDynamic("Si è verificato un errore nel processo.");
    }
    await flowDynamic([
      'Ciao ${ctx.name}',
     'Hai ${singleCustomerData[0].attributes.credit} crediti',
      "Cosa vuoi fare?\n1 - Prenotare Lezioni\n2 - Controllare Prenotazioni\n3 - Cancellare Prenotazione",
    ]);
  });

seems that addAction is not working at all. i have no console log or response from the bot. i don't understand where is the error.

using BaylesProvider

image

image

Reproducir error

No response

Información Adicional

No response

marcellodpAS commented 1 month ago

Got it.

Need to add the flow in the flow array on the main function

const main = async () => {
****  const adapterFlow = createFlow([welcomeFlow, flow, flowB, yourFlowName]); ****

  const adapterProvider = createProvider(Provider);
  const adapterDB = new Database();