Custom Module - Declaring shared functions in actions


Hi Guys!
I’m developing a custom module.

I declared several actions that works fine, but i need declare shared functions. For example ‘TrackSomethingInAnySite()’ to reuse from diferents actions.

How Can I declare this? I created a folder outside of ‘actions’ folder, but this is not copied in ‘out’ folder in the build, then an error is shown beacuse the ‘functions’ folder is not found.

If I declare this functions within actions folder, an error ‘illegal operation on a directory’ is shown.

What is the better way to do it? Am I doing something wrong?

Thanks in advance!


Hi @lmoralejo

If you put a dot (.) in front of the js-file (i.e. “.yourSharedFunctionsNodeModule.js”) it is ignored during loading of single actions, but can be required in your custom actions.

module.exports = {
    yourFunction: function(...){....}
const { yourFunction } = require ('.yourSharedFunctionsNodeModule.js')

No warranty that this code works, it’s just to show the idea…
You can also required dependencies delivered with botpress but also your own npm packages when you install them inside a node_modules folder inside the actions folder…

Official Docs regarding custom code


1 Like

Thanks @crixx! I’ll try!