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

Add fanciness: forms #5

Open
GochoMugo opened this issue Jan 3, 2017 · 10 comments
Open

Add fanciness: forms #5

GochoMugo opened this issue Jan 3, 2017 · 10 comments

Comments

@GochoMugo
Copy link
Owner

Forms can allow a more complex chain of queries between the bot and the user, without requiring the programmer to define explicitly the interactions between them.

The original inspiration for this feature was from https://dev.albertocoscia.me/nodeogram/quickstart.html#forms.

While it is possible to implement this entirely in tgfancy, I believe it will be better to have a more generic solution, i.e. a form engine, that can be used across multiple platforms, other than just Telegram, using "adapters'.

A favorable API can be adapted from Inquirer.js.

The expected code would look something like: (this is hypothetical!)

// npm-installed module
const FormSet = require('forms');
const TgformAdapter = require('forms-telegram');
const ConsoleformAdapter = require('forms-console');


// module variables
const formset = new FormSet();
const tgformAdapter = new TgformAdapter(bot);
const consoleformAdapter = new ConsoleformAdapter();


// adding the adapters
formset.addAdapter('telegram', tgformAdapter);
formset.addAdapter('console', consoleformAdapter);


// adding a form, used for building a user's profile i.e name, age, etc.
formset.addForm('profile', [
    // name
    {
        name: "name",
        message: "What is your name?",
        validate(answer) { /* ... validate ... */ },
        when(answers) { /* ... do we ask ... */ },
    },
    // ... more questions ...
]);


// let's ask for the details from the user, on the command '/start'
bot.onText(/^\/start$/, function(msg, match) {
    formset.send('profile', 'telegram', function(error, answers) {
        // ... handle error ...
        // 'answers' is an object with the user's answers
        console.log(answers);
    });
});

tgfancy would offer a formset by default, for more implicit solutions!

@kamikazechaser
Copy link

bump

@fuzsh
Copy link

fuzsh commented Mar 1, 2017

Cannot find module 'forms-telegram'
how can i resolve it?

@kamikazechaser
Copy link

@FaRzad-845 It's just at theory. Work is in progress to make it a reality! 😃

@fuzsh
Copy link

fuzsh commented Mar 1, 2017

@kamikazechaser

what can we do now days ?

when i use two bot.on ....
like this i run into trouble ....
`
bot.on('message', function (msg) {
var chatId = msg.chat.id;
var text ="write your comment";
bot.sendMessage(chatId, text);

bot.on('message', function (msg) {
var chatId = msg.chat.id;
var text = "thanks for your comment";
bot.sendMessage(chatId, text);
});
});
`

do you have any idea for two bot.on listener toghether?

@kamikazechaser
Copy link

Possibly use async await.

@fuzsh
Copy link

fuzsh commented Mar 2, 2017

@kamikazechaser
Excuse me ... Can you give me a example of this ... ( Async await and two or three bot.on method )
my node version is 6.9

@ro31337
Copy link
Contributor

ro31337 commented Mar 7, 2017

Where the state is supposed to be stored? Memory?

@GochoMugo
Copy link
Owner Author

We shall allow multiple stores to be used. Think of it the same way express-session works, with multiple pluggable session stores. We will probably provide a memory store by default, but they will all share the same interface.

@GochoMugo
Copy link
Owner Author

I have worked on a PoC for the query engine. Please proceed to https://github.com/forfuturellc/mau for more information. In particular, see the example provided and see how it would work with your bot code!

@MCSH
Copy link

MCSH commented Jul 8, 2017

I have recently published a package I personally use for managing the context of the dialog between the user and the bot. You can find it here, maybe with a little modification it could be useful here as well.

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

No branches or pull requests

5 participants