1

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;                      }
Loai Tayem
  • 61
  • 8

1 Answers1

0

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:

enter image description here

Fei Han
  • 26,415
  • 1
  • 30
  • 41
  • Hi @LoaiTayem, any updates? Do you achieve the requirement to get page URL? – Fei Han May 03 '18 at 09:55
  • Is there anyway to do it in the message controller since I cant get the referrer without typing a first message, when I try to add it in message controller the referrer is null. @Fei Han – Loai Tayem Jun 12 '18 at 15:11
  • I use ChannelData from direct line, and deserialize it within my dialogs. – NiteLordz Sep 29 '18 at 23:59