【问题标题】:ChatBot did not work in Web Emulator but work well in Local Bot Framework emulatorChatBot 在 Web Emulator 中不起作用,但在 Local Bot Framework 仿真器中运行良好
【发布时间】:2020-03-30 23:41:23
【问题描述】:

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

有人知道怎么解决吗?

附上我的截图。 左侧来自 Web Emulator,右侧来自本地 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 日更新

我曾尝试使用嵌入式和直接线路。但是错误还是一样。

Bot 未托管在 SharePoint 中。

2020 年 1 月 6 日更新 它在 Azure 机器人服务中不起作用

【问题讨论】:

  • 网络模拟器是指网络聊天中的测试功能?或者它是full webchat 捆绑/实现。这是托管在 SharePoint 页面/webpart/spfx 中吗?
  • @DanaV ,是的。 Web 模拟器位于 Azure Web 模拟器中,并且还在另一个网页的 webchat 中使用 directline。聊天机器人未托管在 SharePoint 页面上。

标签: botframework sharepoint-2013 azure-bot-service direct-line-botframework


【解决方案1】:

根据您的描述,您可以从本地获取数据。这意味着你的代码和逻辑都没有问题。

我注意到您的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。

您说这是一个本地站点,那么您能否检查一下是否可以从公共网络访问该站点?

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

我们知道,bot 代码托管在 Azure 应用服务上,如果此错误是由上述原因引起的,那么 Azure App Service Hybrid Connections feature 在这种情况下可能会有所帮助。

【讨论】:

  • 正确,从内部 SharePoint 检索数据。我应该在内部 SharePoint 中发布 ChatBot 吗?
  • 嗨@EngSoonCheah 它是基于谁将使用这个机器人,如果它只针对您的内部网络用户,理论上,您可以将它发布到您的 SharePoint 站点所在的网络中。如果外部用户需要访问它,您应该将其发布到 azure bot 服务,并使用 Azure 应用服务的混合连接功能(Azure bot 服务基于 Azure 应用服务)将您的 bot 应用服务连接到您的本地站点。我认为这个文档会有所帮助:azuregems.io/azure-hybrid-connections
  • 嗨@EngSoonCheah,怎么样?您的问题解决了吗?
  • 仍在尝试 Azure 混合连接。
  • @EngSoonCheah,啊...我明白了。祝你好运,如果有任何更新,请告诉我:)
【解决方案2】:

ChatBot 似乎工作正常?它正在发送和接收消息。您拥有的一些代码在本地运行与托管时表现不同。有 Xml,它是文件还是生成的?您需要检查它是否遵循与在本地运行时相同的逻辑并使用相同的数据。也许如果您将一些(非机密)代码粘贴到它崩溃的地方,我们可以有更多的想法来提供帮助

【讨论】:

  • 错误从 DispatchBot.cs 的第 136 行开始。是哪条线?需要看这个方法ProcessRSSAsync的第136行
  • 我已经更新了源代码,来自 HttpWebResponse 的 LINE 136
  • 好的。您似乎可以在本地访问共享点 RSS,但托管时它不会返回相同的 xml,这意味着它很可能会返回 HTML 错误页面。我搜索了您的错误,发现:forums.asp.net/t/… 它表明您可能需要使用代理,请尝试该链接中的代码示例
  • 报错显示:System.PlatformNotSupportedException: Operation is not supported on this platform.
  • 错误发生在 listXml.LoadXml(listReader.ReadToEnd());正确的?尽管您可以在访问共享点 rss 时搜索错误,但我认为如果您能看到响应是什么(它很可能会告诉具体错误)会更直接。您有记录器还是正在使用应用程序洞察力?我会 JsonConvert.SerializeObject(listResponse) 并记录或抛出它,甚至将字符串作为消息发送到机器人中,这样你就可以看到它说了什么。一旦你有了序列化的字符串,只需将其保存为 HTML 文件 error.html 并打开。
【解决方案3】:

当你发布你的机器人时,会有一个选项如下:

选择编辑应用服务设置。仅添加以下详细信息,仅添加以下内容:

MicrosoftAppId : <xxxxx>
MicrosoftAppPassword : <xxxxx>

点击应用,确定。

确保从 appsettings.json 中删除 Microsoft App IdMicrosoft App Password,以便它在机器人模拟器中也能正常工作。

现在发布机器人。它适用于两个地方。

希望这有帮助。

【讨论】:

  • 我只看到了预览和配置,因为我从 Azure 门户下载了 ChatBot 源代码。
猜你喜欢
  • 1970-01-01
  • 2022-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-26
  • 2021-01-18
相关资源
最近更新 更多