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

feat: Integrate 'capture_only_intended' flag for silent execution in … #832

Merged
merged 1 commit into from
Aug 31, 2023

Conversation

gerrcass
Copy link
Contributor

@gerrcass gerrcass commented Aug 29, 2023

…'addAnswer' function

Que tipo de Pull Request es?

  • [ x] Mejoras
  • Bug
  • Docs / tests

Descripción

Se agrega un flag "capture_only_intended" en la función "addAnswer" para evitar la emisión de mensajes al usuario cuando se busca simplemente capturar su respuesta..

Forma parte de este proyecto.

@leifermendez
Copy link
Member

Hola @gerrcass puedes compartirme el ejemplo por aquí de como usarlo.

@@ -379,8 +379,10 @@ class CoreClass {
const { answer } = ctxMessage
logger.log(`[sendProviderAndSave]: `, ctxMessage)
if (answer && answer.length && answer !== '__call_action__') {
await this.providerClass.sendMessage(numberOrId, answer, ctxMessage)
logger.log(`[providerClass.sendMessage]: `, ctxMessage)
if (answer !== '__capture_only_intended__') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

para evitar typos por parte de los usuarios es más prudencial usar una key al estilo ONLYCAPTURE en lugar de una larga y con muchas subrayas "_" y algunas de ellas dobles

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tienes razón, de hecho comenté que la funcionalidad de utilizar 'capture' en 'addAnswer' sin enviar un mensaje al usuario, podría ser más conveniente implementarlo mediante el envío de 'null' en lugar de una cadena. Otra opción sería que 'addAction' admita 'capture' directamente... aunque el doble underscore es intensional para que quien lo use tenga que escribir algo largo y sin typos.

@gerrcass
Copy link
Contributor Author

@leifermendez yo lo estoy usando de la siguiente manera.

const { addKeyword, EVENTS } = require("@bot-whatsapp/bot");

const flowWelcomeWithStore = (globalState) =>
  addKeyword(EVENTS.WELCOME)
    .addAction(async (ctx, { flowDynamic, provider }) => {
      console.log("... Starting Lead Machine 🚀");

      const leadData = {
        phone: ctx.from,
        name: ctx.pushName,
        flowDynamic,
        provider,
        ctx,
      };
      await globalState.initLeadMachine(leadData);
    })
    .addAnswer(
      "__capture_only_intended__",
      { capture: true },
      async (ctx, { fallBack }) => {
        const leadMechine = await globalState.getLeadMachineInstance(ctx.from);

        const userInput = ctx.body.trim();
        leadMechine.send("USER_INPUT", { userInput });

        await fallBack();
        return;
      }
    );

module.exports = flowWelcomeWithStore;

@leifermendez leifermendez changed the base branch from main to dev August 31, 2023 10:12
@leifermendez leifermendez merged commit e2043a7 into codigoencasa:dev Aug 31, 2023
1 check passed
@leifermendez
Copy link
Member

@leifermendez yo lo estoy usando de la siguiente manera.

const { addKeyword, EVENTS } = require("@bot-whatsapp/bot");

const flowWelcomeWithStore = (globalState) =>
  addKeyword(EVENTS.WELCOME)
    .addAction(async (ctx, { flowDynamic, provider }) => {
      console.log("... Starting Lead Machine 🚀");

      const leadData = {
        phone: ctx.from,
        name: ctx.pushName,
        flowDynamic,
        provider,
        ctx,
      };
      await globalState.initLeadMachine(leadData);
    })
    .addAnswer(
      "__capture_only_intended__",
      { capture: true },
      async (ctx, { fallBack }) => {
        const leadMechine = await globalState.getLeadMachineInstance(ctx.from);

        const userInput = ctx.body.trim();
        leadMechine.send("USER_INPUT", { userInput });

        await fallBack();
        return;
      }
    );

module.exports = flowWelcomeWithStore;

Veo queue usas una especia de gestor de estado esta interesante, solo tambien decir que la lib tiene un manejador de estado puedes ver la implementacion aqui https://github.com/codigoencasa/bot-whatsapp/blob/main/__test__/1.1.6-case.test.js "state"

@gerrcass
Copy link
Contributor Author

@leifermendez Sí, creo que ese manejor es un feature en la nueva versión por que no la había visto antes, voy a ver cómo refactorizar eso. Gracias Leifer..

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

Successfully merging this pull request may close these issues.

3 participants