Function Templates and Variable Rendering
In DMflow, we use double curly braces {{ }} for variable rendering and function calls.
Basic Syntax Tips
- Auto-complete: Most parameter input boxes support autocomplete. Typing
{{usually pops up available variable suggestions. - Input Fields: If calculating or calling functions in an input field, the entire expression must be wrapped in
{{ }}.- Example:
{{ 'Today temperature ' + data.conversation.temperature_today + ' degrees' }}
- Example:
- Textarea (Multi-line Text): You can freely intersperse
{{ }}in the text.- Example:
Today temperature {{data.conversation.temperature_today}} degrees Tomorrow temperature {{data.conversation.temperature_tomorrow}} degrees
- Example:
Application Differences in Various Scenes
1. Triggers
- Auto Unboxing: If there is only one variable in the Input field, the system will automatically “unbox” its value.
- Example:
["a"]will becomea. But if there are more than two values, it won’t.
- Example:
- Keyword Separation: If the placeholder prompt says comma
,separated, when you input keywords, they will be automatically separated, no need to manually input commas.
2. Chat Role (Gossip Role)
Chat role prompts currently only support text replacement and do not support complex function operations yet.
- Built-in Parameters:
cur_time: Provides date, time, and day of week.user_profile: Includes email, mobile phone, and username.
- Passing Variables: A domain currently supports up to three passing variables.
- Example:
Assume passing variable is
{"test": "1234"}. Prompt writes:Prompt is {{ test }}Actual output:Prompt is 1234
- Example:
Assume passing variable is
3. Chatbot Flow
- Constant Prefix: Except for start and reply nodes, other nodes must choose
constantprefix if they want to use functions, and must be wrapped with{{ }}. - Common Data Sources: Variables usually start with
data.user,data.sys_user,data.conversation,data.session.
4. Resource Node
- URL Path Replacement: Except for the Domain part, the path (Path) can be replaced by
{{ }}.- O Correct:
https://app.dmflow.chat/{{ path }} - X Error:
https://{{ domain }}/test
- O Correct:
- Domain Restriction: To ensure stability, Domain cannot use pure IP or generic cloud server domains. It is recommended to bind your own Domain. If the system detects that the domain cannot be used, it will automatically disable the resource node function.
Built-in Function Library (Utils)
We provide a series of powerful Utils functions for you to call:
| Function | Description |
|---|---|
Utils.generateSignature(body, secret, algo) |
Generate Signaturealgo supports: HMACSHA256, HMACSHA1, HMACSHA384, HMACSHA512, HMACMD5 (HMAC prefix can also be omitted). |
Utils.hash(text) |
Hash Calculation Uses MurmurHash algorithm, returns value as number (can be negative). |
Utils.atob(text) |
Base64 Decode Converts Base64 encoded text back to original text. |
Utils.toSeconds(date) |
To Seconds Converts yyyy-MM-ddTHH:mm:ssZZZ format to UTC seconds. |
Utils.randomValue(length) |
Random String Generates random alphanumeric string of specified length ( A-Z, a-z, 0-9). |
Utils.extractTime(value, format, offset) |
Time Extractionvalue is seconds. format is target format (e.g., yyyy-MM-dd). offset is timezone (e.g., +08:00). |
Utils.extractTime(value, format) |
Time Extraction (Default Timezone) Uses bot flow’s default timezone for conversion. |
Utils.now(offset) |
Get Current Time Return format is yyyy-MM-ddTHH:mm:ssZZZ. |
Utils.format(dateString, format) |
Time Format Conversion Converts yyyy-MM-ddTHH:mm:ssZZZ format to other specified formats. |
Utils.encrypt(text) |
Encrypt Encrypts using the exclusive key generated when the bot and domain were created. |
Utils.decrypt(text) |
Decrypt Decrypts using the exclusive key generated when the bot and domain were created. |
Time Format Explanation
- Domain: Time format is unified as ISO 8601 standard:
yyyy-MM-ddTHH:mm:ssZZZ. - Bot: Internal calculations mainly use UTC seconds.