将自定义参数从Webchat控件传递到Bot框架 [英] Pass Custom Parameters from webchat control to bot framework

查看:85
本文介绍了将自定义参数从Webchat控件传递到Bot框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我目前正在使用这个:

So, I'm currently using this:

<!DOCTYPE html>
<html>
  <body>
    <div id="webchat"></div>
    <script src="https://cdn.botframework.com/botframework-webchat/preview/botchat.js"></script>
    <script>
      window.WebChat.renderWebChat({
        directLine: window.WebChat.createDirectLine({ secret: 'YOUR_BOT_SECRET_FROM_AZURE_PORTAL' })
      }, document.getElementById('webchat'));
    </script>
  </body>
</html>

,它工作正常,但是我有多个QnA知识库用于不同的客户端应用程序.因此,我想为'applicationname'传递自定义参数,以便在OnTurnAsync方法的BOT框架工作(V4)中确定QNA KB.

and it works fine, however I have multiple QnA Knowledge base for different client applications. SO I would like to pass custom parameter for 'applicationname' to decide the QNA KB in my BOT frame work(V4) in OnTurnAsync method.

我尝试了

var d1 = window.WebChat.createDirectLine({ token })
window.WebChat.renderWebChat({
        directLine: d1,
         styleSet,
postActivity: activity => {
     var newActivity = Object.assign({}, activity, {channelData: { "userparam": "test" } });
     return dl.postActivity(newActivity);
    }

}, document.getElementById('webchat'));
})();

但是bot中的Context.Activity.ChannelData返回Null

but Context.Activity.ChannelData in bot returning Null

也尝试过

var d1 = window.WebChat.createDirectLine({ token })
window.WebChat.renderWebChat({
        directLine: d1,
        user: { id: 'userid', userparam:'test'},
            styleSet

}, document.getElementById('webchat'));
})();

still Context.Activity.From.Properties ["userparam"]返回Null

still Context.Activity.From.Properties["userparam"] returns Null

推荐答案

从Cilent方面

var d1 = window.WebChat.createDirectLine({ token })
window.WebChat.renderWebChat({
        directLine: Object.assign({}, d1, {
     postActivity: activity => {
     var newActivity = Object.assign({}, activity, { channelData: { "param1": "test" } });
     return d1.postActivity(newActivity);
    }
  }),
            styleSet,
            botAvatarInitials: 'CAB',
            userAvatarInitials: 'You'

}, document.getElementById('webchat'));
})();

来自BOt Framework

from BOt Framework

var channelObj = turnContext.Activity.ChannelData.ToString();
var channeldata = Newtonsoft.Json.Linq.JObject.Parse(channelObj);
var customdata = channeldata["param1"].ToString();

这篇关于将自定义参数从Webchat控件传递到Bot框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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