我正在从直线Web通道传递令牌和用户ID。我想知道如何在Bot端接收这些值,以显示从直接渠道传递的用户ID或电子邮件。
<html>
<div id="webchat" role="main" />
<head>
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
</head>
<body>
<script>
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token: '@Model.Token' }),
userID: '@Model.UserId'
},
document.getElementById('webchat'));
</script>
</body>
<html>
您可以创建如下所示的商店并添加c自定义数据channelData,我已经使用了simpleUpdatein包
const store = window.WebChat.createStore(
{},
({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
action = window.simpleUpdateIn(action, ['payload', 'activity', 'channelData', 'myData'], () => myDataObj);
}
return next(action);
}
);
然后将此商店注入到像这样的Directline实例中>
window.WebChat.renderWebChat({ directLine: window.WebChat.createDirectLine({ token: '@Model.Token', }), userID: '@Model.UserId' store, }, document.getElementById('webchat'));
现在在Bot端,您可以在上下文对象下访问它,下面是完整路径
dialogContext.Context.Activity.ChannelData
您也可以查看此Sample了解更多信息