我能够按照我的本地开发系统上的说明here将EchoBot转换为与QnAMaker交互,但是当我使用kudu repo发布相同的内容时(使用Azure DevOps服务Ci / CD管道进行了尝试,但是它无法在[预览中]工作,因为在部署之后,该bot仅挂在门户上,却无法在网络聊天中对其进行测试。.因此放弃并使用了推荐的kudu repo ),我没有得到正确的答案我的回复。对于我发送的每个问题,它都无法检测到QnAMaker服务。而且我从代码中返回错误消息,提示未找到QnaMaker答案。
如何解决此问题的原因? 我的Bot文件在本地似乎运行良好,我可以从QnAMaker本地获得答案,但是在将代码发布到Azure中的 Web App Bot 之后,却没有。
我觉得 Botframework V4 (使用.net)不是很简单,并且门户(文档)上的说明仍在不断发展,或者有时难以理解。
这是在本地测试聊天时来自我的模拟器的快照:
这是生产端点的快照(在门户网站上使用相同的问题),以及来自OnTurnAsync函数的错误消息:
我的.bot已定义了所有服务,本地bot运行正常。
这是我的ChatBot类中的代码:
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)
{
// Get the conversation state from the turn context.
var state = await _accessors.CounterState.GetAsync(turnContext, () => new CounterState());
// Bump the turn count for this conversation.
state.TurnCount++;
// Set the property using the accessor.
await _accessors.CounterState.SetAsync(turnContext, state);
// Save the new turn count into the conversation state.
await _accessors.ConversationState.SaveChangesAsync(turnContext);
// Echo back to the user whatever they typed.
//var responseMessage = $"Turn {state.TurnCount}: You sent '{turnContext.Activity.Text}'\n";
//await turnContext.SendActivityAsync(responseMessage);
// QnAService
foreach(var qnaService in _qnaServices)
{
var response = await qnaService.GetAnswersAsync(turnContext);
if (response != null && response.Length > 0)
{
await turnContext.SendActivityAsync(
response[0].Answer,
cancellationToken: cancellationToken);
return;
}
}
var msg = "No QnA Maker answers were found. Something went wrong...!!";
await turnContext.SendActivityAsync(msg, cancellationToken: cancellationToken);
}
else
{
await turnContext.SendActivityAsync($"{turnContext.Activity.Type} event detected");
}
}