ChatBot在Web模拟器中无法运行,但在Local Bot Framework模拟器中可以正常运行 [英] ChatBot did not work in Web Emulator but work well in Local Bot Framework emulator

查看:71
本文介绍了ChatBot在Web模拟器中无法运行,但在Local Bot Framework模拟器中可以正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了与SharePoint Inmise集成的ChatBot.当我在模拟器中调试ChatBot时,它可以工作.但是,当我使用DirectLine在Azure中的Web Emulator和公司网站中托管的网站上调试时,它不起作用.

I developed the ChatBot that integrates with SharePoint On Premise. When I debug the ChatBot in emulator, it work. But When I debug on Web Emulator in Azure and Website Hosted in Company Website by using DirectLine, it did not work.

有人知道如何解决吗?

这里是我的屏幕截图. 左侧来自Web模拟器,右侧来自本地Bot Framework模拟器

Herewith my screenshot. Left hand side is from Web Emulator, Right hand side is from local Bot Framework Emulator

使用源代码更新(2019年12月9日)

XmlNamespaceManager xmlnspm = new XmlNamespaceManager(new NameTable());

Uri sharepointUrl = new Uri("https://mvponduty.sharepoint.com/sites/sg/daw/");

xmlnspm.AddNamespace("atom", "http://www.w3.org/2005/Atom");
xmlnspm.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
xmlnspm.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");

NetworkCredential cred = new System.Net.NetworkCredential("engsooncheah@mvponduty.onmicrosoft.com", "Pa$$w0rd", "mvponduty.onmicrosoft.com");

HttpWebRequest listRequest = (HttpWebRequest)HttpWebRequest.Create(sharepointUrl.ToString() + "_api/lists/getByTitle('" + "data@work" + "')/items?$filter=Keywords%20eq%20%27bloomberg%27");
listRequest.Method = "GET";
listRequest.Accept = "application/atom+xml";
listRequest.ContentType = "application/atom+xml;type=entry";

listRequest.Credentials = cred;
//LINE 136 start from below
HttpWebResponse listResponse = (HttpWebResponse)listRequest.GetResponse();
StreamReader listReader = new StreamReader(listResponse.GetResponseStream());
XmlDocument listXml = new XmlDocument();

listXml.LoadXml(listReader.ReadToEnd());

if (listResponse.StatusCode == HttpStatusCode.OK)
{
    Console.WriteLine("Connected");
    await turnContext.SendActivityAsync("Connected");
}

// Get and display all the document titles.
XmlElement root = listXml.DocumentElement;
XmlNodeList elemList = root.GetElementsByTagName("content");
XmlNodeList elemList_title = root.GetElementsByTagName("d:Title");
XmlNodeList elemList_desc = root.GetElementsByTagName("d:Description");

//for LINK
XmlNodeList elemList_Id = root.GetElementsByTagName("d:Id");
XmlNodeList elemList_Source = root.GetElementsByTagName("d:Sources");
XmlNodeList elemList_ContentTypeId = root.GetElementsByTagName("d:ContentTypeId");

var attachments = new List<Attachment>();
for (int i = 0; i < elemList.Count; i++)
{

    string title = elemList_title[i].InnerText;
    string desc = elemList_desc[i].InnerText;

    string baseurllink = "https://mvponduty.sharepoint.com/sites/sg/daw/Lists/data/DispForm.aspx?ID=";
    string LINK = baseurllink + elemList_Id[i].InnerText + "&Source=" + elemList_Source[i].InnerText + "&ContentTypeId=" + elemList_ContentTypeId[i].InnerText;

    //// Hero Card
    var heroCard = new HeroCard(
        title: title.ToString(),
        text: desc.ToString(),

        buttons: new CardAction[]
        {
            new CardAction(ActionTypes.OpenUrl,"LINK",value:LINK)
        }
    ).ToAttachment();
    attachments.Add(heroCard);
}
var reply = MessageFactory.Carousel(attachments);
await turnContext.SendActivityAsync(reply);

更新2019年12月17日

我尝试使用嵌入式和直接线路.但是错误仍然相同.

I had try using Embedded and Direct Line. But the Error still same.

Bot不在SharePoint中托管.

更新2020年1月6日 它在Azure Bot Services中不起作用

Update 06 January 2020 Its did not work in Azure Bot Services

推荐答案

根据您的描述,您可以从本地获取数据.这意味着您的代码和逻辑都可以.

Based on your description, you can fetch data from it locally. This means your code and logic are all right.

我注意到您的sharePoint URL为:https://mvponduty.sharepoint.com/sites/sg/daw/,我尝试访问它,并且还尝试访问您的整个请求URL:https://mvponduty.sharepoint.com/sites/sg/daw/_api/lists/getByTitle('data@work')/items?$filter=Keywords eq 'bloomberg'两者的响应均为404.

I noticed that your sharePoint URL is : https://mvponduty.sharepoint.com/sites/sg/daw/ and I tried to access it, and also tried to access your whole request URL : https://mvponduty.sharepoint.com/sites/sg/daw/_api/lists/getByTitle('data@work')/items?$filter=Keywords eq 'bloomberg' the response of the two are all 404.

您说这是一个本地站点,所以您可以检查一下是否可以从公共网络访问此站点吗?

And you said this is an on-prem site , so could you pls have a check that if this site can be reached from a public network?

我假设当您在本地测试代码时,您可以像访问内部网络一样访问此站点,它将能够访问本地站点.但是,当您将代码发布到Azure时,它不再在内部工作中:它在公共网络中,因此无法访问导致此错误的本地sharePoint网站.

I assume when you test your code locally, you can access this site as you are in your internal network which will be able to access the on-prem site. However, when you publish your code to Azure, it is not in your internal work anymore: it is in public network so that can't access your on-prem sharePoint site which caused this error.

我们知道,机器人代码托管在Azure应用服务上,如果此错误是由上述原因引起的,则可能是

As we know, bot code is hosted on Azure app service, if this error is caused by the above reason, maybe Azure App Service Hybrid Connections feature will be helpful in this scenario.

这篇关于ChatBot在Web模拟器中无法运行,但在Local Bot Framework模拟器中可以正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆