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
How to have seperate files for seperate sets of dialogs? #1457
Comments
you could create a separate file per category. You can load as many dialogs as you'd like and you can even create them dynamically. There are any number of ways to do this. It's difficult to say what's the "best" way. |
One simple way to do this is have a seperate file for your bots. Lets say for example you want to put this dialog into a separate file bot.dialog('/cars',function(session){session.send('test')}); Create a new file called cars.js and create a module for this dialog as following module.exports = function(bot) { Now in the original file you can use this by requiring it and passing the bot object as an argument require('./cars.js')(bot); |
@GanadiniAkshay Thanks that really helped a lot. //initializes all the prompts in car and in car.js // I declare all the prompts here like this which I used earlier to initialize the prompts // I export this function which will call the respective dialog internally But your method seems much more promising because its much less code and I think I can call the module.exports = function(bot) { |
I'd say you're on the right path. If you look at the libraries example you might get some inspiration. You don't need to actually use libraries but you'll notice how we put the library in a separate file and expose a |
This is an old post but I am having trouble doing the same in my typescript bot. Anyone who could help with that? |
@flinkr in case if you are still having that issue (it's been a while) - you can have something like this: car.ts
original file:
|
Hi guys! Thanks for your explanations and examples (currently working on separation of dialogs into separate files too).
P.s. Sorry if dumb question - only learning JS. Thanks in advance |
A, it appeared to be very simple:
And the main file, which imports it:
|
I have 20 bot.dialogs which are related to "Car" and another 20 bot.dialogs which are related to "Bike".
And there are a lot more categories.
So now you see where this is going. I dont want to have a large single js file. I want to split them into multiple files.
What is the best way to do it?
The text was updated successfully, but these errors were encountered: