Coder Social home page Coder Social logo

ntfm's Issues

how to abort the flow?

flow.register(
  userId,
  data => {
    // how can I abort and clear user flow here and not go to next action?
  },
  data => {
  }
);

unable to process third action

It is found that it is unable to run the third action, test cases are created below.

    it("registers and executes a series of actions, with proper executeCall data and previousResult correctly stored", done => {

        const passedData1 = {};
        const returnedData1 = {};
        const passedData2 = {};
        const returnedData2 = {};
        const passedData3 = {};

        flow.register(id,
            data => {
                expect(passedData1).toBe(data.executeCallData);
                return returnedData1;
            },
            data => {
                expect(passedData2).toBe(data.executeCallData);
                expect(returnedData1).toBe(data.previousResult);
                done();
            },
            data => {
                expect(passedData3).toBe(data.executeCallData);
                expect(returnedData2).toBe(data.previousResult);
                done();
            }
        );

        flow.execute(id, passedData1);
        flow.execute(id, passedData2);
        flow.execute(id, passedData3);
    });
    it("registers and executes a series of async actions, with proper executeCall data and previousResult correctly stored", done => {

        const passedData1 = {};
        const returnedData1 = {};
        const passedData2 = {};
        const returnedData2 = {};
        const passedData3 = {};

        flow.register(id,
            async data => {
                expect(passedData1).toBe(data.executeCallData);
                await delay(300);
                return returnedData1;
            },
            async data => {
                expect(passedData2).toBe(data.executeCallData);
                expect(returnedData1).toBe(data.previousResult);
                await delay(300);
                done();
            },
            async data => {
                expect(passedData3).toBe(data.executeCallData);
                expect(returnedData2).toBe(data.previousResult);
                await delay(300);
                done();
            });

        flow.execute(id, passedData1);
        flow.execute(id, passedData2);
        flow.execute(id, passedData3);
    });

cannot process text contains "/"

I use the following code to perform a broadcast. However, if I input broadcast message with "/", for example "please type /help for help.", the broadcast message will not be prompted.
I found that when the input contains "/", the message will be treated as command. At this point, I don't know what is the cause and don't know how can I fix that.

Do anyone can help? Thanks a lot!

'use strict';
const { bot, flow } = require('../bot');
const db = require('../db');
const util = require('../util');

bot.onText(/^\/broadcast$/, msg => {
  const chatId = msg.from.id;

  // flow guard
  if(!flow.hasInQueue(chatId)) {
    const isAdminUser = db.isAdminUser(chatId);
    if(!isAdminUser) {
      return;
    }

    bot.sendMessage(chatId, 'Please input broadcast message');

    // after 180 second, the operation will be forcibly cleared
    const timer = setTimeout(flow.clear.bind(flow), 180000, chatId);

    flow.register(
      chatId,
      async data => {
        const msg = data.executeCallData;

        util.notifyRoles(chatId, ['admin', 'poweruser'], '🔔BROADCAST MESSAGE🔔\n🔔PLEASE DO NOT REPLY🔔\n' + msg.text, true, false);

        bot.sendMessage(chatId, 'done');

        clearTimeout(timer);
      },
    );
  } else {
    bot.sendMessage(chatId, 'Unable to execute this command. First complete the previous operation or type /clear.');
  }
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.