如何自动将用户信息传递给Bot Framework对话实例,而不将其作为显式消息发布到聊天窗口中? [英] How do I automatically pass user information to the Bot Framework conversation instance without posting it as an explicit message in the chat window?

查看:34
本文介绍了如何自动将用户信息传递给Bot Framework对话实例,而不将其作为显式消息发布到聊天窗口中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[问题与Microsoft Bot Framework有关]

[Question pertains to the Microsoft Bot Framework]

我的机器人需要有关用户的某些信息,但我不希望用户自己提交它,因为

There is certain information about the user that my bot will need, but I don't want the user himself to submit it because

  1. 他可能没有. 2.我的网页上肯定有它,所以我不必问.

基本上,我的聊天机器人已嵌入到网页中.我需要将该网页的每个会话中的信息提交到相应的聊天机器人控制器实例,而在聊天窗口中看不到显式消息.

Essentially, my chat bot is embedded in a web page. There is information in each session of that web page that I need to submit to the corresponding chat bot controller instance without an explicit message becoming visible in the chat window.

如何将信息传递给聊天机器人控制器?如果我需要对话ID来解决漫游器,如何在我的网页Javascript中以编程方式获取它?现在,我的聊天机器人已通过可在文档

How do I pass information to the chat bot controller? If I need the conversation Id to address the bot, how do I get it programmatically inside of my web page Javascripts? Right now, my chat bot is integrated into the web page with the simple iframe line that can be found in the docs

http://docs.botframework.com/connector/embed-chat -control/#navtitle

示例场景:我的聊天机器人是Facebook页面上的聊天窗口.我需要聊天机器人知道用户是谁,然后说你好用户名",而无需任何提示来获取用户名

Example Scenario : My chat bot is a chat window on a facebook page. I need the chat bot to know who the user is and say, for instance, 'Hello username' without any prompting to get username

推荐答案

在这种情况下,您必须创建自己的对话窗口,使您可以发布并获取Message对象.

In that case you have to create your own conversation window that allows you to post and get the Message object.

Index.html

Index.html

<script src="script.js">
<ul class="chat" id="conversation">

</ul>
<input id="input-text" type="text" />
<button type="button"   id="btn-send">Send</button>

script.js

script.js

$('#btn-send').click(function () {

    // Convert text to Message object
    var message = {
        text: $('#input-text').val(),
        type: "Message"
    };

    // Create outgoing message html and add to list
    var htmlOutgoing = "<li>" + message.text + "</li>";
    $('#conversation').append(html);

    $.ajax({
        url: 'api/Messages/Post', // Change to your proper url
        dataType: "json",
        type: "POST",
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(message),
        async: true,
        processData: false,
        cache: false,
        success: function (data) {
            // Create incoming message html and add to list
            var htmlIncoming = "<li>" + data.text + "</li>";
            $('#conversation').append(htmlIncoming);
        },
        error: function (xhr) {
            alert('error');
        }
    });

    $('#text-input').val("");
})

我希望这会对您有所帮助.

I hope, this would help you.

这篇关于如何自动将用户信息传递给Bot Framework对话实例,而不将其作为显式消息发布到聊天窗口中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆