Team recording bot from scratch(error at response) - botframework

We are creating a recording bot in .netframework 4.7.2 using the bot framework. We are making this bot from scratch. we were stuck at one point. please see the image below to see the error we are facing: What we are trying to do is we are making a bot controller and in that, we are getting an error at ( await Adapter.ProcessAsync(Request, Response, Bot)) response. please see the code below:
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using HttpGetAttribute = System.Web.Http.HttpGetAttribute;
using HttpPostAttribute = System.Web.Http.HttpPostAttribute;
namespace ScratchTeamrecordingBot.Controllers
{
[System.Web.Http.Route("api/messages")]
public class HomeController : ApiController
{
private readonly IBotFrameworkHttpAdapter Adapter;
private readonly IBot Bot;
public HomeController(IBotFrameworkHttpAdapter adapter, IBot bot)
{
Adapter = adapter;
Bot = bot;
}
[HttpPost, HttpGet]
public async Task PostAsync()
{
// Delegate the processing of the HTTP POST to the adapter.
// The adapter will invoke the bot.
await Adapter.ProcessAsync`(Request, Response, Bot);
}
}
}
We are creating a recording bot in .netframework 4.7.2 using the bot framework. We are making this bot from scratch. we were stuck at one point. please see the image below to see the error we are facing: What we are trying to do is we are making a bot controller and in that, we are getting an error at ( await Adapter.ProcessAsync(Request, Response, Bot)) response. please see the code below:

Go to View > Error List in Visual Studio and check the error message. But probably, your error is because you are using .Net Framework. If you check the type of the Response object you will see is type of Microsoft.AspNetCore.HttpResponse.IBotFrameworkHttpAdapter . My recomendation is to use .Net Core for your project.
For information about the IBotFrameworkHttpAdapter go here
Hope you find this information useful :)
Best regard!

Related

Agent Handoff intermediator-bot-sample (c#) by tompaana on github doesn't work on upgrading Microsoft.Bot.Builder and related packages to Ver 4.10.3

Problem Statement
This is regarding the Live Agent Handoff intermediator-bot-sample (c#) created by tompaana at https://github.com/tompaana/intermediator-bot-sample on guithub.
The intermediator-bot-sample works perfectly with Microsoft.Bot.Builder (4.2.2) and Microsoft.Bot.Builder.Integration.AspNet.Core(4.2.2) and dependent Version 4.2.2 packages but, It does not use Dialogs.
The HandoffMiddleware Code stopped getting invoked , when I added the package Microsoft.Bot.Builder.Dialogs (4.10.3) (as my existing code requires Dialogs) . This also caused upgrading to Microsoft.Bot.Builder to version 4.10.3 along with it's dependent packages i.e. Microsoft.Bot.Builder.Integration.AspNet.Core etc..
Community Support
The Original Author Handoff intermediator-bot-sample Tomi Paananen A.K.A tompaana has moved on to other projects and would no longer be able to devote time to this project and has requested to reach out MS Botframework community members for support (Refer: Author Response to Github issue raised).
Requesting BotFramework community to please help out to add Agent Hand Off functionality to my existing Chatbot
Observation :
Even After Package upgrade, the HandoffMiddleware class is getting successfully instantiated during Startup.
My retrofitted code contains BotController class via which all the API get invoked. This BotController class which isn't present in the original Handoff intermediator-bot-sample code.
On typing any utterance on the chat bot (Upgraded/new code), the control goes into the BotController class rather than invoking/triggering HandoffMiddleware.OnTurnAsync(...)
As the original intermediator-bot-sample code does not have any BotController/ API Controller, could this be the reason that utterances aren't getting routed via, HandoffMiddleware Middleware if so, how could I fix the issue?
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.6.2
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
namespace Neo.Controllers
{
// This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot
// implementation at runtime. Multiple different IBot implementations running at different endpoints can be
// achieved by specifying a more specific type for the bot constructor argument.
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
private readonly IBotFrameworkHttpAdapter Adapter;
private readonly IBot Bot;
public BotController(IBotFrameworkHttpAdapter adapter, IBot bot)
{
Adapter = adapter;
Bot = bot;
}
[HttpPost, HttpGet]
public async Task PostAsync()
{
// Delegate the processing of the HTTP POST to the adapter.
// The adapter will invoke the bot.
await Adapter.ProcessAsync(Request, Response, Bot);
}
}
}
Referenced Packages
Original intermediator-bot-sample referenced Packages
Upgraded intermediator-bot-sample referenced Packages
Original intermediator-bot-sample Solution Files
Upgraded intermediator-bot-sample Solution Files
Query
Could you please suggest How I can fix this issue?
As the HandoffMiddleware.OnTurnAsync(..) works fine when I execute the coriginal code_ but, doesn't get triggered from My Code after retrofitting IntermediateBot code with upgraded Microsoft.Bot.Builder and related packages to Version 4.10.3 .
Pointing to an existing working Agent HandOff sample(c#) would also help
The following solution makes the upgraded Tompanna Agent Handoff solution work smoothly:
The solution lies in the way BotFrameworkHttpAdapter needs to invoke HandoffMiddleware.
The inspection Middleware example in Github provides the methodology to invoke any middleware i.e. in those scenarios where we have the upgraded Microsoft.Bot.Builder and related packages which introduce the concept of BotController class / API Controller .
Code reference of AdapterWithInspection.cs from BotBuilder-Samples/samples
Replace InspectionMiddleware in the following code with HandoffMiddleware
namespace Microsoft.BotBuilderSamples
{
public class AdapterWithInspection : BotFrameworkHttpAdapter
{
public AdapterWithInspection(IConfiguration configuration, InspectionState inspectionState, UserState userState, ConversationState conversationState, ILogger<BotFrameworkHttpAdapter> logger)
: base(configuration, logger)
{
// Inspection needs credentiaols because it will be sending the Activities and User and Conversation State to the emulator
var credentials = new MicrosoftAppCredentials(configuration["MicrosoftAppId"], configuration["MicrosoftAppPassword"]);
//***********************************************************************************//
//* InspectionMiddleware needs to be replace HandOffMddieWare in the execution pipeline *//
//***********************************************************************************//
Use(new InspectionMiddleware(inspectionState, userState, conversationState, credentials));
OnTurnError = async (turnContext, exception) =>
{
// Log any leaked exception from the application.
logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}");
// Send a message to the user
await turnContext.SendActivityAsync("The bot encountered an error or bug.");
await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code.");
// Send a trace activity, which will be displayed in the Bot Framework Emulator
await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError");
};
}
}
}
New code should look like the following
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace Microsoft.BotBuilderSamples
{
public class AdapterWithInspection : BotFrameworkHttpAdapter
{
public AdapterWithInspection(IConfiguration configuration, InspectionState inspectionState, UserState userState, ConversationState conversationState, ILogger<BotFrameworkHttpAdapter> logger)
: base(configuration, logger)
{
// Inspection needs credentials because it will be sending the Activities and User and Conversation State to the emulator
var credentials = new MicrosoftAppCredentials(configuration["MicrosoftAppId"], configuration["MicrosoftAppPassword"]);
//***********************************************************************************//
//*************** Adding HandOffMddieWare in the execution pipeline *****************//
//***********************************************************************************//
Use(new HandoffMiddleware(configuration));
OnTurnError = async (turnContext, exception) =>
{
// Log any leaked exception from the application.
logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}");
// Send a message to the user
await turnContext.SendActivityAsync("The bot encountered an error or bug.");
await turnContext.SendActivityAsync("To continue to run this bot, please fix the bot source code.");
// Send a trace activity, which will be displayed in the Bot Framework Emulator
await turnContext.TraceActivityAsync("OnTurnError Trace", exception.Message, "https://www.botframework.com/schemas/error", "TurnError");
};
}
}
}
NOTE
You would need to inject dependencies in the Startup.cs accordingly
Inject Dependencies in Startup.cs
Add following code to facilitate dependency injection of AdapterWithInspection
services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithInspection>();

cannot get xamarin andriod project to see portable class project classes in same solution

Environment - if you need additional information, please let me know.
Windows 10 developer laptop (latest service packs and updates)
Visual Studio 2017 15.3
.net - 4.7.02046
xamarin 4.6.0295
xamarin.android sdk 7.4.0.19 java 1.8
I have a solution with 4 projects
portable class library
android UI
IOS UI
Windows UI
I am trying to access a class in the portable class from the android ui. The ValidateShopLoginAsync exists in the portable class library. The following is from the android UI project and code.
Boolean shopvalidated = ValidateShopLoginAsync("http://m.rometech.net/MWebService/AuthenticateUser", globalshopid, globalshoplicense);
The ETechX is the namespace of the portable class, yet it does not recognize it in the using. The following is from the Android ui project and code.
using System;
using ETechX;
using System.Threading.Tasks;
using Android.App;
using Android.Text;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
I added the reference from the Android project to the portable class library.
Here is the code in the portable class library project and code snippet. The task ValidateShopLoginAsync is listed here.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Windows.Web.Http;
using HttpClient = System.Net.Http.HttpClient;
namespace ETechX
{
class ETechX
{
public async Task<bool> ValidateShopLoginAsync(Uri tUri, string tShopIdentification, string tShopLicense)
{
var soapString = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><AuthenticateUser xmlns='http://m.rometech.net/MWebService'><shopIdentification>" + tShopIdentification + "</shopIdentification><shopLicence>" + tShopLicense + "</shopLicence></AuthenticateUser></soap:Body></soap:Envelope>";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("SOAPAction", "http://m.rometech.net/MWebService/AuthenticateUser");
var content = new StringContent(soapString, Encoding.UTF8, "text/xml");
var response = await client.PostAsync(tUri, content);
using (response)
{
var soapResponse = await response.Content.ReadAsStringAsync();
return ParseSoapResponse(soapResponse);
}
}
}
private bool ParseSoapResponse(string soapResponse)
{
throw new NotImplementedException();
}
}
}
Everything I have read says this should work, but I must be missing something else, that no one is telling me about in linking the android project to a task in the portable class library.
I scoured through 100's of comments on this. Even e-mail Xamarin support. They have yet to respond to anything I have ever sent them. Not sure if they ever do respond.
When I get this working, it will solve a ton of issues I am having right now. Please assist.

BasicHttpBinding Error - Xamarin

Problem is not calling the wcf function using basichttpBinding and showing an error.
No host to route error comes up on Visual Studio.
Unhandled Exception:
System.Net.WebException: Error: ConnectFailure (No route to host)
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using HelloWorld_App4.localhost;
namespace HelloWorld_App4
{
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
localhost.Service1 obj = new localhost.Service1();
obj.GetData(32, true);
UIApplication.Main(args, null, "AppDelegate");
}
}
}
What license have you got?
If you only have the Indie license you wont be allowed to access web/wcf services and have to rely on rest services.
I found that out the hard way but then just switched ot using ASP.Net Web API to create my services. Simple and much cheaper that to buy the business license.

C# ComVisible DLL not registering

I'm working for someone running a windows 2003 server. They want me to make a SMTP sink which can categorize what database and table we want to send messages to. They don't have exchange on this server, only the default virtual SMTP server.
I've made a class, which I think should fire when the SMTP servers onarrival event occurs. I'm having an issue registering my class however, when I run RegAsm /regfile i'm getting a "Warning, RA0000: no registeration will occur, no types to register." if I run RegAsm with /TLB it will tell me types were registered, but by class doesn't show up in the global registery and my class isn't called when mail is sent to the server. I'm a little at a loss as to what I'm doing wrong.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace SMTPSink
{
[Guid("????-????-?????-????")]
[ComVisible(true)]
[ProgId("SMTPSINK")]
public class SMTPSink : CDO.ISMTPOnArrival
{
SMTPSink()
{ }
void CDO.ISMTPOnArrival.OnArrival(CDO.Message Message, ref CDO.CdoEventStatus EStatus)
{
//Simple test to see if this fires on mail arrival
}
}
}
You forgot to make the constructor public. Required to export a coclass that doesn't have the [noncreatable] type library attribute. Fix:
public SMTPSink()
{ }
Or just omit it if it doesn't do anything useful.

PROBLEM :An error message cannot be displayed because an optional resource assembly containing it cannot be found

I created Windows Mobile Application and I loaded web service that contain one method (GetNumber). When I call this method from my emulator I got a following exception
An error message cannot be displayed because an optional resource assembly containing it cannot be found.
Can anyone help me. This is my code from WM Application, it is very siple.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MobileClientApp;
namespace MobileClientApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MobileClientApp.localhost.WebService m = new MobileClientApp.localhost.WebService();
int result;
bool resbool;
m.GetNumber(10, true, out result, out resbool);
label1.Text = result.ToString();
}
}
}
For a very good explanation:
http://blogs.msdn.com/b/netcfteam/archive/2004/08/06/210232.aspx
(excerpt from above)
There has been some confusion about the error message: "Could not find resource assembly". Basically, this means that there is some exception that has happened in the program. The error did not happen because it could not find the resource assembly. The resource assembly that it is searching for contains exception messages (strings) that would be helpful in debugging what went wrong with the program.
Since the user is never expected to see this error message if the program works as expected and all exceptions are handled appropriately, it was decided (due to size constraints) that the resource assembly that has these error strings are never put on a user's device. Thus the main target audience of these error strings are developers who would like to debug issues. Hence, when you do an F5 deploy onto the device, the System.SR.dll assembly which have these error strings are copied to the device and the developer can see the error messages. But in case .Net Compact Framework is installed from a redistributable or you are using .Net Compact Framework that come with the device (as a user of the device would be doing), the System.SR.dll is not present on the device. Hence, if the application did come upon an exceptional condition that wasn't handled by the application, this "Could not find resource assembly" message would be shown to the user.
If you are not using Visual Studio F5 deploy to the device and would still like to see the exception messages, you can achieve this by taking the System_SR_[Language].CAB where [Language] corresponds to the language in which you want to see the error message to appear and clicking on the cab file to install it
Sounds like you are missing an assembly in your deployment.

Resources