我使用 botframework v4 创建了一个 Web 应用程序机器人,并将其与使用 Iframe 的 Web 应用程序集成。我想访问机器人所在页面的当前 url。
我尝试了反向通道机制,但未能从 ChannelData 中的服务器端获取任何值。我有脚本标签src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js" > 在头标签和 iframe iframe id="chatBot" src=' https://webchat.botframework .com/embed/EdgewellSampleBot?s=xxx ' style='min-width: 400px; 宽度:100%;min-height: 500px;'> 在 body 标记内并在页面加载时调用getUrl()。
<script>
function getURL()
{
var dl = new BotChat.DirectLine({
secret: 'xxx',
webSocket: false,
pollingInterval: 1000,
});
var urlref = window.location.href;
BotChat.App({
botConnection: {
...dl,
postActivity: activity => dl.postActivity({
...activity,
channelData: { pageurl: urlref }
})
},
user: { id: 'userid' },
bot: { id: 'xxx' },
resize: 'detect'
}, document.getElementById("chatBot"));
}