获取URL引用程序[BotFramework WebChat]



我在我的网站中使用了一条直线,我想知道是否有办法在我的机器人代码中获取网站的URL。之前,在v3中,我初始化了与的聊天

BotChat.App({
directLine: { secret: "{directline_secret}" },
user: { id: 'You', referrer: window.location.href},
bot: { id: '{bot_id}' },
resize: 'detect'
}, document.getElementById("bot"));

我可以用这行代码activity.From.Properties["referrer"].ToString()获取引用者,但在v4中,我找不到在机器人中获取引用者的方法。

有人能帮我吗?提前谢谢。

在v4中,该值是turnContext.activity(在Node中(或turnContent.activity((在C#中(对象的一部分。正如你在问题中所做的那样(即,作为用户对象的一部分(传递url值,你会这样访问它(节点示例(:

async onTurn(turnContext) {
if (
turnContext.activity.type === "event" && turnContext.activity.name === "eventName"
) {
this.userProfile.location = turnContext.activity.from.referrer;
await console.log(this.userProfile.location);
}

我在我的BotChat.App帖子中包含了一个名称和指定的类型,以将事件匹配到turnContext.activity:

function testMethod(someValue) {
botConnection
.postActivity({
from: { id: 'me', referrer: window.location.href },
name: 'eventName',
type: 'event',
value: someValue
})
.subscribe(function (id) {
console.log('"eventName" sent');
});
};

在本例中,该方法绑定到页面上正在按下的按钮。

希望得到帮助!

最新更新