https://discord.gg/botpress logo
Can I define global or workflow-level functions th...
# 💻developers
v
Hi again everybody! Question: Can I define global or workflow-level functions that can be called from cards to avoid code duplication? I'm using Botpress Cloud. Something similar to module.exports perhaps?
w
i found two ways: - use workflow as suggested by @most-computer-46020 here https://discord.com/channels/1108396290624213082/1121494527727902891/1280619293461057647 but i don't find how to use it in an execute code card (call a workflow and read the output variable) - use a workflow (that you can call in a node, before your execute code card) containing a node with one or more execute code card that assign to a workflow or session variable your functions.
code example:
Copy code
ts
/**
 * fxLogWarn log a warn into console, example of function saved in a session variable
 */
// Set the variable only if it does not exist
if (typeof session.fxLogWarn !== 'function') {
  const fx = (title: string, content: any) => {
    console.warn(title, content)
  }
  
  session.fxLogWarn = fx
}
i don't know if there is a method to import, in an execute code card, a custom library
4 Views