Первое: вам не следует использовать SDK-V3, если вы начинаете сейчас: используйте v4, которая обычно доступна в течение нескольких месяцев. v3 не будет развиваться в будущем (за исключением нескольких исправлений).
Затем посмотрите образцы v4, используя QnA Maker
, здесь: https://github.com/Microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/11.qnamaker/QnAMaker/QnABot.cs
В этом примере вы можете увидеть, как вы можете реализовать свою логику в QnABot.cs
:
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
// Handle Message activity type, which is the main activity type for shown within a conversational interface
// Message activities may contain text, speech, interactive cards, and binary or unknown attachments.
// see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
if (turnContext.Activity.Type == ActivityTypes.Message)
{
// Check QnA Maker model
var response = await _services.QnAServices[QnAMakerKey].GetAnswersAsync(turnContext);
if (response != null && response.Length > 0)
{
// PUT YOUR LOGIC HERE
//await turnContext.SendActivityAsync(response[0].Answer, cancellationToken: cancellationToken);
}
else
{
var msg = @"No QnA Maker answers were found. This example uses a QnA Maker Knowledge Base that focuses on smart light bulbs.
To see QnA Maker in action, ask the bot questions like 'Why won't it turn on?' or 'I need help'.";
await turnContext.SendActivityAsync(msg, cancellationToken: cancellationToken);
}
}
else if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate)
{
if (turnContext.Activity.MembersAdded != null)
{
// Send a welcome message to the user and tell them what actions they may perform to use this bot
await SendWelcomeMessageAsync(turnContext, cancellationToken);
}
}
else
{
await turnContext.SendActivityAsync($"{turnContext.Activity.Type} event detected", cancellationToken: cancellationToken);
}
}