我是C#的新手,我想做一个混合Luis服务和customvision的机器人。
我希望用户能够向机器人发送图像或文本。
我从microsoft bot框架“核心bot” *和图像处理bot **(* https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/13.core-bot,** https://github.com/mandardhikari/ImageProcessingBot)开始
目前,我确实有这段代码是在两个样本之间混合使用的
#region References
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using microsoft.Bot.Builder;
using microsoft.Bot.Builder.Dialogs;
using microsoft.Bot.Schema;
using Newtonsoft.Json;
using microsoft.Extensions.Configuration;
using System.Net.Http;
using System.IO;
using microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models;
using microsoft.Extensions.Logging;
using microsoft.Recognizers.Text.DataTypes.TimexExpression;
#endregion
namespace ImageProcessingBot
{
public class ImageProcessingBot : IBot
{
private readonly FlightBookingRecognizer _luisRecognizer;
protected readonly ILogger Logger;
private readonly ImageProcessingBotaccessors _accessors;
private readonly IConfiguration _configuration;
private readonly DialogSet _dialogs;
public ImageProcessingBot(ImageProcessingBotaccessors accessors,IConfiguration configuration)
{
_accessors = accessors ?? throw new ArgumentNullException(nameof(accessors));
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
_dialogs = new DialogSet(_accessors.ConversationDialogState);
}
public async Task OnTurnAsync(ITurnContext turnContext,CancellationToken cancellationToken = default(CancellationToken))
{
activity reply = null;
HeroCard card ;
StringBuilder sb;
switch(turnContext.activity.Type)
{
case activityTypes.ConversationUpdate:
foreach(var member in turnContext.activity.MembersAdded)
{
if(member.Id != turnContext.activity.Recipient.Id)
{
reply = await CreateReplyAsync(turnContext,"Welcome. Please select and operation");
await turnContext.SendactivityAsync(reply,cancellationToken:cancellationToken);
}
}
break;
case activityTypes.Message:
int attachmentCount = turnContext.activity.Attachments != null ? turnContext.activity.Attachments.Count() : 0;
var command = !string.IsnullOrEmpty(turnContext.activity.Text) ? turnContext.activity.Text : await _accessors.CommandState.Getasync(turnContext,() => string.Empty,cancellationToken);
command = command.ToLowerInvariant();
if(attachmentCount == 0)
{
var luisResult = await _luisRecognizer.RecognizeAsync<FlightBooking>(turnContext,cancellationToken);
switch (luisResult.TopIntent().intent)
{
case FlightBooking.Intent.Weather:
// We haven't implemented the GetWeatherDialog so we just display a TODO message.
var getWeatherMessageText = "TODO: get weather flow here";
var getWeatherMessage = MessageFactory.Text(getWeatherMessageText,getWeatherMessageText,InputHints.IgnoringInput);
await turnContext.SendactivityAsync(getWeatherMessage,cancellationToken);
var attachments = new List<Attachment>();
var reply = MessageFactory.Attachment(attachments);
reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment());
default:
// Catch all for unhandled intents
var didntUnderstandMessageText = $"Sorry,I didn't get that. Please try asking in a different way (intent was {luisResult.TopIntent().intent})";
var didntUnderstandMessage = MessageFactory.Text(didntUnderstandMessageText,didntUnderstandMessageText,InputHints.IgnoringInput);
await turnContext.SendactivityAsync(didntUnderstandMessage,cancellationToken);
break;
}
}
else
{
HttpClient client = new HttpClient();
Attachment attachment = turnContext.activity.Attachments[0];
...// then it stays as in https://github.com/mandardhikari/ImageProcessingBot/blob/master/ImageProcessingBot/ImageProcessingBot/ImageProcessingBot.cs
我正在获取这些日志。
1>ImageProcessingBot.cs(78,41,78,46): error CS0136: A local or parameter named 'reply' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
1>ImageProcessingBot.cs(72,33,72,67): error CS0163: Control cannot fall through from one case label ('case FlightBooking.Intent.Weather:') to another
我是C#的新手,因此,对以上内容的任何见解将不胜感激!