在 Microsoft Bot Framework 上处理消息附件

Handling Message Attachment on Microsoft Bot Framework

我正在尝试处理带有附件的邮件,我收到了 远程服务器返回错误:(400) 错误请求。错误。我怎样才能正确处理这个问题?

消息控制器

        if (activity.Type == ActivityTypes.Message)
        {
            try
            {
                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                // Check in QnA Dialog
                await Conversation.SendAsync(activity, () => new QnADialog());
            }
            catch (Exception ex)
            {

                throw;
            }

        }
        else
        {
            HandleSystemMessage(activity);
        }
        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;

您可以直接查看 activity 对象上的附件计数并执行以下操作,例如:

if (activity.Type == ActivityTypes.Message)
{
    try
    {
        if (activity.Attachments.Count > 0)
        {
            var replyNoAttachmentAllowed = activity.CreateReply("This QnA bot cannot handle attachments, please send only text");
            await context.PostAsync(replyNoAttachmentAllowed);
        }
        else
        {
            // Check in QnA Dialog
            await Conversation.SendAsync(activity, () => new QnADialog());
        }
    }
    catch (Exception ex)
    {

        throw;
    }

}