在MS团队中删除chatbot @mention

时间:2019-07-15 10:04:52

标签: c# botframework microsoft-teams

我使用v4和C#开发了聊天机器人。首先将其部署到Web,现在我们将bot添加到了MS团队中。在团队中,聊天机器人无法从QnA服务获得准确的答案,但是在Web中使用正确的答案可以回答相同的问题。我们发现了原因,聊天机器人名称(@ChatBot)被附加在问题的前面,从而改变了问题的结构。

我尝试了RemoveMentionText(turnContext.Activity.Id)方法;和RemoveRecipientMention,但到目前为止没有运气。

有没有一种方法可以在致电QnA或Luis服务之前从问题中删除聊天机器人名称。 ?请帮助

尝试了以下代码,但没有解决。

public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
    if (turnContext.Activity.Type == ActivityTypes.Message)
    {
        query = turnContext.Activity.Text;

        if (turnContext.Activity.ChannelId == "msteams")
        {
            // I WANT TO ADD CODE HERE TO REMOVE THE @MENTIONS FROM QUESTION, BEFORE CALLING THE QNA Service.
            // incoming query ->  turnContext.Activity.Text value "<at> chat bot name </a> what is sharepoint? "
            // modified query -> turnContext.Activity.Text value "what is sharepoint? "       
        }
        var qnaResponse = await _services.QnAServices[QnAMakerKey].GetAnswersAsync(turnContext);

        if (qnaResponse[0].Score < .70)
        {
            await turnContext.SendActivityAsync("I'm having some trouble understanding what you mean. Could you please rephrase your question?", cancellationToken: cancellationToken);
        }
        else
        {
            await turnContext.SendActivityAsync(qnaResponse[0].Answer, cancellationToken: cancellationToken);
        }

    }
}  

1 个答案:

答案 0 :(得分:0)

您的问题在这里:

pip install -U scikit-learn

您要定义query = turnContext.Activity.Text; ,然后/当您调用query时,它将更改turnContext.Activity.RemoveRecipientMention(),但不会更改turnContext.Activity.Text

您需要做的就是在定义查询之前删除提及内容:

query