9

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.

Does anyone know how to solve it?

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

enter image description here

Update with Source Code (09 December 2019)

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

Update 17 December 2019

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

The Bot is not hosted in SharePoint.

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

Eng Soon Cheah
  • 257
  • 1
  • 10
  • 42
  • By web emulator, you mean the Test in Web Chat feature? Or is it a [full webchat](https://github.com/microsoft/BotFramework-WebChat/tree/master/samples) bundle/implementation. Is this being hosted in a SharePoint page/webpart/spfx? – Dana V Dec 07 '19 at 00:31
  • @DanaV , yes. The web emulator is in Azure Web emulator and also using directline in webchat in another webpage. The chatbot is not hosted at SharePoint page. – Eng Soon Cheah Dec 07 '19 at 07:24

3 Answers3

4

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

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?

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.

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.

Stanley Gong
  • 11,522
  • 1
  • 8
  • 16
  • Correct, retrieve data from Internal SharePoint. Should I publish the ChatBot in the Internal SharePoint? – Eng Soon Cheah Dec 18 '19 at 03:16
  • Hi @EngSoonCheah it is based on who will use this bot, if it is only for your internal network users,theoretically, you can publish it in the network your SharePoint site in. If external users need to access it, you should publish it to azure bot service , and use hybrid connections feature of Azure app service (Azure bot service is based on Azure app service )to connect your bot app service to your local site . I think this doc will be helpful : https://azuregems.io/azure-hybrid-connections/ – Stanley Gong Dec 18 '19 at 03:26
  • Hi @EngSoonCheah , how's going ? Has your issue been solved? – Stanley Gong Dec 20 '19 at 01:20
  • still trying the Azure Hybrid Connections. – Eng Soon Cheah Dec 20 '19 at 01:22
  • @EngSoonCheah , Ah...I see . Good luck, if there are any updates, pls let me know : ) – Stanley Gong Dec 20 '19 at 01:24
  • OK. Thank for help. merry Christmas and Happy New Year. – Eng Soon Cheah Dec 20 '19 at 01:31
  • Hi @EngSoonCheah Merry Christmas! Hope you all the best in the new year! – Stanley Gong Dec 20 '19 at 01:32
  • I think the problems happen in the Login Part , when the the network is external. – Eng Soon Cheah Jan 08 '20 at 07:07
2

ChatBot seems to be working fine? it's sending and receiving messages. There's some code you have that is behaving differently when run locally versus hosted. There's Xml, is it a file or generated? You need check that it's following the same logic and using same data as when it is run locally. Maybe if you paste some of the (non confidential) code where it crashes, we can have more ideas how to help

waleed
  • 451
  • 3
  • 11
  • Error starts at line 136 in DispatchBot.cs. Which line is it? need to see line 136 of this method ProcessRSSAsync – waleed Dec 09 '19 at 05:18
  • I had update the source code, the LINE 136 from HttpWebResponse – Eng Soon Cheah Dec 09 '19 at 06:11
  • Ok. It seems locally you can access the sharepoint RSS fine, but when hosted it's not returning the same xml which means it's most likely returning an HTML error page. I searched your error and found this: https://forums.asp.net/t/1116247.aspx?System+Xml+XmlException+The+start+tag+does+not+match+the+end+tag+HELP It suggests that you might need to use Proxy, please try the code sample in that link – waleed Dec 09 '19 at 06:42
  • The error display: System.PlatformNotSupportedException: Operation is not supported on this platform. – Eng Soon Cheah Dec 09 '19 at 07:12
  • Error is happening at listXml.LoadXml(listReader.ReadToEnd()); correct? Although you could search for errors on accessing sharepoint rss, I think it's more straightforward if you can see what the response is (it will most likely tell the specific error). Do you have a logger or are you using application insights? I would JsonConvert.SerializeObject(listResponse) and log it or throw it, or even send the string as message in the bot so you can see what it says. Once you have that serialized string just save it as in HTML file error.html and open. – waleed Dec 09 '19 at 07:24
  • The localhost can read all the item from the XML, but the problems is at the HTML5 page that I use directline. – Eng Soon Cheah Dec 09 '19 at 07:44
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/203884/discussion-between-eng-soon-cheah-and-waleed). – Eng Soon Cheah Dec 09 '19 at 08:41
2

When you publish your bot, there will be an option as below :

Image

Select Edit App Service Settings. Add only the following details, nothing else :

MicrosoftAppId : <xxxxx>
MicrosoftAppPassword : <xxxxx>

Click Apply, Ok.

Make sure you remove the Microsoft App Id and Microsoft App Password from appsettings.json, so that it works in bot emulator as well.

Now Publish the bot. It will work at both places.

Hope this is helpful.

ashmit-001
  • 392
  • 4
  • 21