从Microsoft Bot Framework获取URL Referer和Origin标头

问题描述:

我在网站内部使用了一条直线,我想知道是否仍然可以通过Request标头Referrer和Origin告诉网站的网址,我想在Dialog中获取该值,我尝试使用Activity. ServiceUrl,但它给出的是directline.botframework.com,而HttpContext.Current.Request.Url.AbsoluteUri是给出的Azure URL.

I am using a directline inside my website, I was wondering if there is anyway to tell the URL of the website from the Request header Referrer and Origin, I want to get the value inside a Dialog, I have tried using Activity.ServiceUrl but it is giving directline.botframework.com and the HttpContext.Current.Request.Url.AbsoluteUri is giving the Azure URL.

   public Task StartAsync(IDialogContext context)
    {
        context.Wait(MessageReceivedAsync);
        return Task.CompletedTask;
    }

    private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
    {
        var activity = await result as Activity;                      }

如果您想获取将Webchat嵌入到bot应用程序Dialog中的网页的URL,则可以尝试获取该URL并将其传递给您机器人,像这样:

If you’d like to get the URL of the webpage where you embed webchat inside bot application Dialog, you can try to get the URL and pass it to your bot, like this:

<script>
    var urlref = window.location.href;

    BotChat.App({
        directLine: { secret: "{directline_secret}" },
        user: { id: 'You', referrer: urlref},
        bot: { id: '{bot_id}' },
        resize: 'detect'
    }, document.getElementById("bot"));
</script>

内部漫游器对话框:

if (activity.From.Properties["referrer"] != null)
{
    var urlref= activity.From.Properties["referrer"].ToString();
}

测试结果: