Naltox / telegram-node-bot

Node module for creating Telegram bots.
MIT License
724 stars 143 forks source link

Forms are not working #79

Closed farruxx closed 8 years ago

farruxx commented 8 years ago

Callback in $.runForm calling with undefined values { name: undefined, age: undefined }

amsonline commented 8 years ago

I have this issue, too.

amsonline commented 8 years ago

@farruxx The documentation is really faulty. By checking the source code, I found out that you have to pass the value as second parameter of callback, so: callback(true) should be callback(true, message.text) It's interesting that nothing is wrote in the documentation.

Naltox commented 8 years ago

@farruxx Thanks! Fixed docs

cnavigato commented 8 years ago

//I believe that the callback(false,message.text) need to be set also? Otherwise $.runForm doesn't work as advertised? Also IsNumeric and toInt didn't work for me.

class FormController extends TelegramBaseController { handle($) { const form = { name: { q: 'Send me your name', error: 'sorry, wrong input', validator: (message, callback) => { if(message.text) { console.log('q: '+ message.text); callback(true, message.text) //you must pass the result also return } callback(false,message.text) } }, age: { q: 'Send me your age', error: 'sorry, wrong input', validator: (message, callback) => { if(message.text && Number(message.text)) { console.log('age: '+ message.text); callback(true, Number(message.tmessage.textext)) return }

                callback(false, **message.text**)
            }
        }
    };
    $.runForm(form, (result) => {
        console.log('form results: '+ result)
    });
}

}

cnavigato commented 8 years ago

Do we need to run jQuery to conform to this module? jQuery.isNumeric( value )