Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ChatBot did not work in Web Emulator but work well in Local Bot Framework 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.

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("[email protected]", "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

like image 993
Eng Soon Cheah Avatar asked Dec 06 '19 00:12

Eng Soon Cheah


People also ask

What is bot Framework emulator?

Bot Framework Emulator is a desktop application that allows bot developers to test and debug bots, either locally or remotely. Using the Emulator, you can chat with your bot and inspect the messages that your bot sends and receives.

How do I run a bot framework emulator?

bot file for your bot, you can simply open it in the Emulator by clicking on the 'Open Bot' button on the welcome page or File -> Open Bot Configuration and select your . bot file. If you do not have a . bot file, click on 'create a new bot configuration' in the Welcome page or File -> New Bot Configuration.

How does Microsoft bot framework work?

The Bot Framework Activity schema defines the activities that can be exchanged between a user or channel and a bot. Activities can represent human text or speech, app-to-app notifications, reactions to other messages, and so on.


1 Answers

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.

like image 200
Stanley Gong Avatar answered Oct 11 '22 22:10

Stanley Gong