Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛] Bug cuando se usa addAction #865

Closed
KichanCrazy opened this issue Sep 27, 2023 · 10 comments
Closed

[🐛] Bug cuando se usa addAction #865

KichanCrazy opened this issue Sep 27, 2023 · 10 comments
Labels

Comments

@KichanCrazy
Copy link

KichanCrazy commented Sep 27, 2023

¿Que versión estas usando?

v2

¿Sobre que afecta?

Flujo de palabras (Flow)

Describe tu problema

Al usar varios AddAction (2 o mas) entra en un bucle infinito al usar flowDynamic enviando decenas de mensajes en menos de 5 segundos hasta que se apague el proceso de node.

Reproducir error

No response

Información Adicional

Ejemplo de codigo:

let respuesta
const flujoTest = addKeyword("holahola!")
.addAction( async( ctx, { flowDynamic }) => {
  flowDynamic(`Hola! primer flow dynamic. respondeme algo`)
})
.addAction( { capture: true}, async( ctx, { flowDynamic }) => {
  respuesta = ctx.body
  flowDynamic(`Esto me respondieste ${respuesta}`)
})
.addAction( async( ctx, { flowDynamic }) => {
  flowDynamic(`Hola! segundo flow dynamic. respondeme algo`)
})
.addAction( { capture: true}, async( ctx, { flowDynamic }) => {
  respuesta = ctx.body
  flowDynamic(`Esto me respondieste ${respuesta}`)
})

Ejemplo visual en whatsapp:
image

El ejemplo del código es solo para demostrar el bug, parecería obvio que en el ejemplo se puede evitar el bug haciendo uso de addAnswer pero en el uso normal de ese flujo los mensajes son traídos desde una API dependiendo del state del usuario por lo tanto addAction es el método a utilizar en este caso.

@KichanCrazy KichanCrazy added the bug Something isn't working label Sep 27, 2023
@KichanCrazy KichanCrazy changed the title [🐛] Bug cuando se n [🐛] Bug cuando se usa addAction Sep 27, 2023
@Gregoriotecnico
Copy link
Contributor

alguna solucion a esto?

@leifermendez
Copy link
Member

Estoy trabjando en esto ;)

@Gregoriotecnico
Copy link
Contributor

Yo he comentado esas dos lineas del bundle.bot y ya oarece que no me entre en bucle el tema del flow dynamic. Nose si os servirá de ayuda...

image

@leifermendez
Copy link
Member

leifermendez commented Sep 29, 2023 via email

@Gregoriotecnico
Copy link
Contributor

image

@leifermendez
Copy link
Member

@Gregoriotecnico @KichanCrazy pueden probar esta version npm install @bot-whatsapp/bot@0.0.174-alpha.0 he puesto tu ejemplo y ya me funcion : https://github.com/codigoencasa/bot-whatsapp/blob/dev/__test__/0.2.0-case.test.js

@leifermendez
Copy link
Member

Solucionado en la siguiente version 0.1.33

@savasadar
Copy link

savasadar commented Oct 4, 2023

Hello @leifermendez,
addAction used consecutively do not work. I have to prepare message with data from db and I am using buttons also so I have to use addAction for customize the answer message, but flow not continue after first addAction.

const flowBuy = addKeyword(["buy", "BUY"])
    .addAction(async (ctx, { flowDynamic }) => {
        // preparing buttons...
        await flowDynamic([{ body: "SELECT WALLET", buttons: buttons }])
    })
    .addAction({ capture: true }, async (ctx, { flowDynamic }) => {
        console.log(ctx.body) // fired
        return flowDynamic([{ body: "BUY WITH", buttons: [{ body: "ETH" }, { body: "USDC" }] }])
    })
    .addAction({ capture: true }, async (ctx, { flowDynamic }) => {
        console.log(ctx.body) // not fired
        return flowDynamic([{ body: "BUY AMOUNT", buttons: [{ body: "0.1" }, { body: "0.5" }, { body: "CUSTOM" }] }])
    })

How can I prepare the message as async without using addAction?

Edit: I think, issue is not about addAction. It is about with flowDynamic. if I use flowDynamic more than 5 flow is not continue. How can I solve this?

leifermendez added a commit that referenced this issue Nov 17, 2023
@leifermendez
Copy link
Member

Hello @leifermendez, addAction used consecutively do not work. I have to prepare message with data from db and I am using buttons also so I have to use addAction for customize the answer message, but flow not continue after first addAction.

const flowBuy = addKeyword(["buy", "BUY"])
    .addAction(async (ctx, { flowDynamic }) => {
        // preparing buttons...
        await flowDynamic([{ body: "SELECT WALLET", buttons: buttons }])
    })
    .addAction({ capture: true }, async (ctx, { flowDynamic }) => {
        console.log(ctx.body) // fired
        return flowDynamic([{ body: "BUY WITH", buttons: [{ body: "ETH" }, { body: "USDC" }] }])
    })
    .addAction({ capture: true }, async (ctx, { flowDynamic }) => {
        console.log(ctx.body) // not fired
        return flowDynamic([{ body: "BUY AMOUNT", buttons: [{ body: "0.1" }, { body: "0.5" }, { body: "CUSTOM" }] }])
    })

How can I prepare the message as async without using addAction?

Edit: I think, issue is not about addAction. It is about with flowDynamic. if I use flowDynamic more than 5 flow is not continue. How can I solve this?

Can you try with the last version 0.1.34 https://github.com/codigoencasa/bot-whatsapp/blob/2fe6bd569791f3481183bc9000145f9f48b07673/__test__/0.0.2-case.test.js#L119

Copy link
Contributor

¿Alguna novedad sobre esta ISSUE?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants