Get URL Referer and Origin header from Microsoft Bot Framework

谁说胖子不能爱 提交于 2019-12-13 02:52:00

问题


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;                      }

回答1:


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>

Inside bot dialog:

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

Test result:



来源:https://stackoverflow.com/questions/49888690/get-url-referer-and-origin-header-from-microsoft-bot-framework

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