Pass Custom Parameters from webchat control to bot framework

微笑、不失礼 提交于 2019-12-02 22:08:16

问题


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>

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.

I tried

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'));
})();

but Context.Activity.ChannelData in bot returning Null

and also tried

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"] returns Null


回答1:


From Cilent Side

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'));
})();

from BOt Framework

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


来源:https://stackoverflow.com/questions/54257379/pass-custom-parameters-from-webchat-control-to-bot-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!