by Minh Le
Version 5 (June 10, 2024)
Download (40 downloads)
/*
TL;DR: Run the "Function Scanner" flow to scan flow titles and descriptions for functions and variables to store in an API file.
Update: Changed import() function.
If we want to start running a statement in a separate flow file, we usually must specify the flow URI to run. However, this connection breaks down when sharing flows online or changing device because flow IDs change. One method to keep IDs consistent is to create an API file that matches names with flow URIs. If we then read the file into a dictionary, we can start flows using function names as long as we keep passing the dictionary between flows within the payload. For more information, there are other community-uploaded tutorials on how to effectively call and return payloads.
This flow scans both flow titles and descriptions for functions denoted by the pattern "@className function(" and variables following the pattern "@className var = . Additionally, the scan follows Java commenting rules, which is why this part if tue description will not interfere with the scan. Functions will be stored as "className.function()" and variables as "className.var" except @global functions and variables, which are stored without a className prefix to make life easier. The API file path is included below as well as an example import function:
*/
@global apiFile = "/data/data/com.llamalab.automate/files/functionsAPI"
@global(statement=89) void() : ends flows without background errors
@global(statement = 41) import(api, packages, rename, returnTo, discardExtras = 0)
/** Filters and renames imports
@param api (Dictionary) : contains functions and variables previously imported
@param packages (String or array of strings) : names of packages to import
@param rename (Dictionary) : Keys are names of packages to import, values are what to rename package
@param returnTo (string) : Name of function to return to after import
@param discardExtras (0 or 1) : Determines whether to discard extra API packages or variables that were previously imported
*/
/*
There is also an example template on how to start a flow from scratch.
As evident, multiple functions can be in the same flow. A statement parameter can be used to specify beginning blocks. If omitted, the next beginning block found within the flow will be assigned.
Including parameters in the description is strongly encouraged to keep track of how the payload is used but not required as they will not affect the API scan. As in most programming languages, optional parameters should be placed at the end of the payload as a dictionary.
Flow descriptions are sometimes lost when downloading flows, so it is recommended to put functions in separate flows titled with the @className function(....) syntax.
*/