函数节点使用指南

1、函数节点工作方式

1.1、FlowBOT调用函数节点
带有Bot提问节点以及函数节点的机器人流程保存并启用后,用户触发本机器人流程
1、Bot提问节点接收用户输入并格式校验后,将匹配结果存入槽位变量
2、槽位变量采集完成后,流转到函数节点
3、函数节点将客户信息字段【"firstName", "lastName", "email", "phone", "country", "province", "timeZone", "gender", "age"】以【USER_】前缀代入函数入参,具体用法参照标准函数体注释说明
3、函数节点将槽位变量字段以【SLOT_】前缀代入函数入参
4、函数节点将函数返回值变量字段以【FUNC_】前缀带入函数入参,这里的变量返回值有可能是在此函数节点指点的函数节点产生的
      注意:
      4.1、并非所有的函数节点返回的内容都会被代入后续函数节点的入参,只有函数节点中配置的函数返回值变量同名返回值才可以;
      例如:A、B两个串联的函数节点,A执行后返回一个JSON对象,里面有var1、var2、var3、var4;但是在A节点的配置中只有var2、var3;
      则在B的入参中只会携带FUNC_var2和FUNC_var3。
      4.2、如果前后函数节点的函数返回值变量存在相同变量名,且已经按照顺序进行过执行,则后续节点引用的该函数变量值为最后一次函数体返回的变量值
      例如: A节点和B节点均设置该变量,A节点执行后的返回值有该变量;
      如果B节点执行后的返回值无该变量名,则后续引用以A的为准;
      如果B节点执行后的返回值有该变量名,则后续引用以B的为准;
5、某个函数节点执行完成后,后续可以引用槽位变量和函数返回值变量的节点均可以使用

2、函数示例

2.1、python
import json # Function entry, modify carefully and DO NOT remove. def handler(event, context): return { "statusCode": 200, "isBase64Encoded": False, "body": json.dumps(your_logic_function(event.get("queryStringParameters"))), "headers": { "Content-Type": "application/json" } } # Tips fot parameter keys and values: # 1.Get user properties with 'USER_' prefix. # 2.The following are the name options for user properties # [firstName, lastName, email, phone, country, province, timeZone, gender, age] # # # e.g. print(params.get("USER_firstName")) # 3.Get slot variables with 'SLOT_' prefix. # # # e.g. print(params.get("SLOT_param1")) # 3、Get function response variables with 'FUNC_' prefix. # # # e.g. print(params.get("FUNC_param1")) # 4.Returns a response variable [next_node_id] in your function code while you want to control the next flows. # # Variable [next_node_id] is in UUID string format which you can see and copy its value while modifying the node. # # Variable [next_node_id] is built-in, no need to specify a function response variable at your function nodes. # # Variable [next_node_id] is disposable, only effects while you returns this variable and is cleared after flow flows. # Function code area, let's begin. def your_logic_function(params): response = { "test_variable": params.get("USER_email") } # Make sure to returns JSON structure data, otherwise the system will fail to parse return response
2.2、javascript
// Function entry, modify carefully and DO NOT remove. exports.handler = async (event, context) => { return { 'statusCode': 200, 'isBase64Encoded': false, 'headers': { 'Content-type': 'application/json; charset=utf-8' }, 'body': JSON.stringify(your_logic_function(event.queryStringParameters)) }; } // Tips fot parameter keys and values: // 1.Get user properties with 'USER_' prefix. // 2.The following are the name options for user properties // [firstName, lastName, email, phone, country, province, timeZone, gender, age] // e.g. console.log(params.USER_firstName) // 3.Get slot variables with 'SLOT_' prefix. // e.g. console.log(params.SLOT_firstName) // 3、Get function response variables with 'FUNC_' prefix. // e.g. console.log(params.FUNC_firstName) // 4.Returns a response variable [next_node_id] in your function code while you want to control the next flows. // Variable [next_node_id] is in UUID string format which you can see and copy its value while modifying the node. // Variable [next_node_id] is built-in, no need to specify a function response variable at your function nodes. // Variable [next_node_id] is disposable, only effects while you returns this variable and is cleared after flow flows. // Function code area, let's begin. function your_logic_function(params) { // Make sure to returns JSON structure data, otherwise the system will fail to parse return { 'test_variable': params.USER_email }; }
2024-02-21
0 0