Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何使用节点在MS bot中动态创建流_Node.js_Nodes_Botframework - Fatal编程技术网

Node.js 如何使用节点在MS bot中动态创建流

Node.js 如何使用节点在MS bot中动态创建流,node.js,nodes,botframework,Node.js,Nodes,Botframework,我想像第一张图片一样,在MS bot中创建N流量。我添加了流程图(第二幅图) 流量是:当用户从A、B、C和D按A时,它将显示A1、A2、A3和A4,当用户按A1时,它将显示A11、A12、A13和A14,当用户按A12时,它将显示A121、A122、A123和A124,同样连续流动 下面是完整的流程 我使用以下代码创建了这个流。但最终的代码有2000多行。所有这些都是重复的功能。所以,我想用最少的代码来实现这一点。有什么想法吗 我需要使用问题、请求、返回、访问、房间类型、预订引擎、最佳灵活费

我想像第一张图片一样,在MS bot中创建N流量。我添加了流程图(第二幅图)

流量是:当用户从A、B、C和D按A时,它将显示A1、A2、A3和A4,当用户按A1时,它将显示A11、A12、A13和A14,当用户按A12时,它将显示A121、A122、A123和A124,同样连续流动

下面是完整的流程

我使用以下代码创建了这个流。但最终的代码有2000多行。所有这些都是重复的功能。所以,我想用最少的代码来实现这一点。有什么想法吗

我需要使用问题、请求、返回、访问、房间类型、预订引擎、最佳灵活费率、虚拟费率代码、库存计数等来代替A、B、C。为了理解目的,我使用了A、B、C

将这些输入作为关系,而不是A、B、C

['PvtBank',GovtBank'] 

PvtBank=>['TBM','CUB','KVB'], 
GovtBank=>['IOB','CBI','BOB'], 
TBM => ['OUTSIDE INDIA','INSIDE INDIA'], 
INSIDE INDIA => ['DELHI','MUMBAI','PUNE'],
OUTSIDE INDIA => ['US','UK','CHINA'], 
DELHI => ['INDIA GATE','NEW DELHI'], 
US=> ['NEW YORK','LOS ANGELES'] and etc


请参阅以下代码段:

bot.dialog('mainFlow', [(session, args, next) => {
    let currentChoice = session.conversationData.TravelType;
    let promits = currentChoice ? [`${currentChoice}1`, `${currentChoice}2`, `${currentChoice}3`, `${currentChoice}4`].join(`|`) : `A|B|C|D`;
    builder.Prompts.choice(session, "Whould you like me to taks about?", promits, {
        listStyle: builder.ListStyle.button
    });
}, (session, args, next) => {
    session.conversationData.TravelType = args.response.entity;
    session.replaceDialog('mainFlow');
}]).endConversationAction("stop",
    "", {
        matches: /^cancel$|^goodbye$|^exit|^stop|^close/i
        // confirmPrompt: "This will cancel your order. Are you sure?"
    }
);
const _ = require('lodash');
let getRegion = () => {
    return {
        'OUTSIDE INDIA': getOutInd(),
        'INSIDE INDIA': getInInd()
    }
}
let getOutInd = () => {
    return {
        'US': ['NEW YORK', 'LOS ANGELES'],
        'UK': [],
        'CHINA': []
    }
}
let getInInd = () => {
    return {
        'DELHI': ['INDIA GATE', 'NEW DELHI'],
        'MUMBAI': [],
        'PUNE': []
    }
}
let map = {
    'PvtBank': {
        'TBM': getRegion(),
        'CUB': getRegion(),
        'KVB': getRegion()
    },
    'GovtBank': ['IOB', 'CBI', 'BOB']
}
bot.dialog('mainFlow', [(session, args, next) => {
    if(!_.isArray(session.conversationData.choices)){
        session.conversationData.choices = new Array();
    }
    if(session.conversationData.TravelType){
        session.conversationData.choices.push(session.conversationData.TravelType)
        session.conversationData.currentChoice = _.last(session.conversationData.choices)
    }
    session.conversationData.currentMap = session.conversationData.currentChoice? _.get(session.conversationData.currentMap,session.conversationData.currentChoice):map;
    let promits = _.isArray(session.conversationData.currentMap) ? _.values(session.conversationData.currentMap).join(`|`): _.keys(session.conversationData.currentMap).join(`|`);
    builder.Prompts.choice(session, "Whould you like me to taks about?", promits, {
        listStyle: builder.ListStyle.button
    });
}, (session, args, next) => {
    session.conversationData.TravelType = args.response.entity;
    session.replaceDialog('mainFlow');
}]).endConversationAction("stop",
    "", {
        matches: /^cancel$|^goodbye$|^exit|^stop|^close/i
        // confirmPrompt: "This will cancel your order. Are you sure?"
    }
);
更新
好的。将此输入用于关系,而不是A、B、C['PvtBank',GovtBank']PvtBank=>['TBM'、'CUB'、'KVB']、GovtBank=>['IOB'、'CBI'、'BOB']、TBM=>['OUTSIDE INDIA'、'INSIDE']、印度境内=>['DELHI'、'MUMBAI'、'PUNE']、印度境外=>['US'、'UK'、'CHINA'、德里=>['INDIA GATE'、'NEW DELHI']、美国=['NEW YORK'、'LOS']

因此,您的需求具有明确的映射关系,因此您可以尝试在前面构建映射器对象或数组以供映射使用。请参考以下代码片段:

bot.dialog('mainFlow', [(session, args, next) => {
    let currentChoice = session.conversationData.TravelType;
    let promits = currentChoice ? [`${currentChoice}1`, `${currentChoice}2`, `${currentChoice}3`, `${currentChoice}4`].join(`|`) : `A|B|C|D`;
    builder.Prompts.choice(session, "Whould you like me to taks about?", promits, {
        listStyle: builder.ListStyle.button
    });
}, (session, args, next) => {
    session.conversationData.TravelType = args.response.entity;
    session.replaceDialog('mainFlow');
}]).endConversationAction("stop",
    "", {
        matches: /^cancel$|^goodbye$|^exit|^stop|^close/i
        // confirmPrompt: "This will cancel your order. Are you sure?"
    }
);
const _ = require('lodash');
let getRegion = () => {
    return {
        'OUTSIDE INDIA': getOutInd(),
        'INSIDE INDIA': getInInd()
    }
}
let getOutInd = () => {
    return {
        'US': ['NEW YORK', 'LOS ANGELES'],
        'UK': [],
        'CHINA': []
    }
}
let getInInd = () => {
    return {
        'DELHI': ['INDIA GATE', 'NEW DELHI'],
        'MUMBAI': [],
        'PUNE': []
    }
}
let map = {
    'PvtBank': {
        'TBM': getRegion(),
        'CUB': getRegion(),
        'KVB': getRegion()
    },
    'GovtBank': ['IOB', 'CBI', 'BOB']
}
bot.dialog('mainFlow', [(session, args, next) => {
    if(!_.isArray(session.conversationData.choices)){
        session.conversationData.choices = new Array();
    }
    if(session.conversationData.TravelType){
        session.conversationData.choices.push(session.conversationData.TravelType)
        session.conversationData.currentChoice = _.last(session.conversationData.choices)
    }
    session.conversationData.currentMap = session.conversationData.currentChoice? _.get(session.conversationData.currentMap,session.conversationData.currentChoice):map;
    let promits = _.isArray(session.conversationData.currentMap) ? _.values(session.conversationData.currentMap).join(`|`): _.keys(session.conversationData.currentMap).join(`|`);
    builder.Prompts.choice(session, "Whould you like me to taks about?", promits, {
        listStyle: builder.ListStyle.button
    });
}, (session, args, next) => {
    session.conversationData.TravelType = args.response.entity;
    session.replaceDialog('mainFlow');
}]).endConversationAction("stop",
    "", {
        matches: /^cancel$|^goodbye$|^exit|^stop|^close/i
        // confirmPrompt: "This will cancel your order. Are you sure?"
    }
);

从你的问题中,我只能想到创建一个规则引擎,就像规则a比规则b发生,规则b比你执行规则c。我不确定,但这可能会有帮助
https://www.npmjs.com/package/node-rules
。使用这一个你可以用最少的代码实现这样的事情。谢谢你的回复。我的问题是,如果用户单击流a,那么流a子模块将工作。流程a子模块为a1、a2、a3、a4。如果用户单击了流a1,那么它将显示流a1子模块(a11、a12、a13和a14),同样,这也会起作用。你的链接不适用于甲烷,它运行良好。但是,我需要使用Issue、Request、Back、Access、Room type、Booking engine、Best Flexible Rate、Virtual Rate code、Inventory Count等,而不是A、B、C。您的场景仍然有一个有限的逻辑流,我无法理解您如何嵌套或无限地存储这些Issue、Request、Back、Access、Room type,预订引擎。流程与我在流程图中给出的流程相同。但是我将使用其他文本来代替A、B、C。我期望一个函数能够接受像['Bank'、'Access'、'Roomtype']、['TBM'、'SBI'、'IOB']、['IN'、'US'、'UK'这样的输入数组。如果用户按下Bank键,则应显示['TBM'、'SBI'、'IOB']。如果用户按下SBI键,它应该显示['IN'、'US'、'UK'],同样,它将继续流程以确认,它不喜欢这些数组的简单组合,但应该有一些映射关系?比如银行=>['TBM','SBI','IOB']=>,SBI=>['IN','US','UK']。TBM=>不同的东西?好的。将此输入用于关系,而不是A、B、C['PvtBank',GovtBank']PvtBank=>['TBM'、'CUB'、'KVB']、GovtBank=>['IOB'、'CBI'、'BOB']、TBM=>['OUTSIDE INDIA'、'INSIDE']、印度境内=>['DELHI'、'MUMBAI'、'PUNE']、印度境外=>['US'、'UK'、'CHINA'、德里=>['INDIA GATE'、'NEW DELHI']、美国=['NEW YORK'、'LOS']