Python

Custom your flow with Python script

Description

What it does: This allows you to run Python scripts inside your workflow, giving your chatbot the ability to process data, perform calculations, and even customize responses.

When to use it?

  • Complex Data Transformations: Perform custom data manipulations or calculations that aren't directly available in other nodes.

  • Integrate with Custom APIs & Services: Connect to APIs or services that don't have dedicated Diaflow nodes yet using Python's vast library ecosystem.

  • Advanced Logic & Decision Making: Implement intricate decision-making processes or custom algorithms within your workflows using Python code.

  • Extend Diaflow Functionality: Effectively create your own mini-nodes by encapsulating custom Python scripts within a reusable Diaflow node.

Component settings

Parameter Name
Description

Method

Options: - Manual Script - Python File

Code editor

Input your code editor when choose method = Manual Script

Upload File

Upload File Python when choose method = Python File

Referencing Data from Previous Nodes

To access the output of a previous node inside your Python script, use the template syntax:

{{nodeName.output}}

  • nodeName: The system name (ID) of the node you want to reference (e.g. weather-0, http-1, etc.).

  • .output: Refers to the full output object from that node.

Example usage:

def run(): return {{weather-0.output}}

return run()

This script will pass the entire output from the node named weather-0 directly into the Python logic.

Note:

  • The {{ }} Syntax is evaluated before the Python code runs. It injects real JSON data at runtime.

  • Make sure the referenced node has already executed successfully and produced output.

Last updated

Was this helpful?