【问题标题】:End dialog Proactively主动结束对话
【发布时间】:2018-03-12 15:07:30
【问题描述】:

我想主动结束特定用户的对话。我看到 API 发送消息并使用对话地址主动启动对话。是否有任何 API 可以主动结束该对话的当前/特定对话(最好使用对话的地址)。我正在使用 bot builder Node.js SDK

这是为聊天管理员提供手动干预所必需的。我不想只是结束整个对话(也有一个 API 可以结束对话),而是在一些事情上帮助用户。

所有提到的API都可以找到here

【问题讨论】:

    标签: node.js botframework


    【解决方案1】:

    您可以尝试利用loadSession(address: IAddress, callback: (err: Error, session: Session) => void): void;,然后在回调函数中结束转换。请参考以下代码sn-p:

    let savedAddress;
    
    server.get('/api/CustomWebApi', function (req, res, next) {
        bot.loadSession(savedAddress, (err, session) => {
            if (!err) {
                session.send('ternimal this conversion')
                session.endConversation();
            }
        })
        res.send('triggered');
        next();
    });
    
    bot.dialog('/', [
        function (session) {
            savedAddress = session.message.address;
            message = 'You can terminate the conversation by accessing: ';
            message += 'http://localhost:' + server.address().port + '/api/CustomWebApi';
            session.send(message);
        }
    ])
    

    【讨论】:

    • 不知何故,我忽略了loadSession API。这就是线索。否则我正在考虑使用receive API,它模拟向机器人发送消息,这会触发会话中的 session.endDialog!
    【解决方案2】:

    对于 Node.js 机器人,您始终可以使用会话变量结束对话,即

    session.endDialog();
    

    请参阅 bot builder SDK session 参考。您还可以“链接”这些方法,即执行类似...

    session.send('proactiveMessage').endDialog(); 
    

    希望有帮助!

    【讨论】:

    • 我想主动结束会话。使用bot.send("this is a message", IAddresss) 发送主动消息。发送主动消息时没有可用的会话对象。会话对象表示当前会话。主动消息用于将消息发送到不同的对话。这不是正确答案。
    猜你喜欢
    • 2017-11-20
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-07
    • 1970-01-01
    相关资源
    最近更新 更多