C# 如何获取bot用户上传的附件

C# 如何获取bot用户上传的附件,c#,botframework,C#,Botframework,我想通过bot用户获取上传的附件,以便将其插入数据库。我试图使用我创建的附件变量,但它似乎不是用户上传的确切文件。请问如何获取上传的文件?。谢谢参见官方样本: 根据频道,您必须提供特定令牌: public virtual async Task MotgaAtt(IDialogContext context, IAwaitable<IMessageActivity> argument) { var message = await argument

我想通过bot用户获取上传的附件,以便将其插入数据库。我试图使用我创建的附件变量,但它似乎不是用户上传的确切文件。请问如何获取上传的文件?。谢谢

参见官方样本:

根据频道,您必须提供特定令牌:

public virtual async Task MotgaAtt(IDialogContext context, IAwaitable<IMessageActivity> argument)
        {
            var message = await argument;
            if (message.Attachments != null && message.Attachments.Any())
            {
                var attachment = message.Attachments.First();
                using (HttpClient httpClient = new HttpClient())
                {
                    var responseMessage = await httpClient.GetAsync(attachment.ContentUrl);
                    var contentLenghtBytes = responseMessage.Content.Headers.ContentLength;
                    await context.PostAsync($"Attachment of {attachment.ContentType} type and size of {contentLenghtBytes} bytes received.");
                }
            }

            context.Done<object>(new object());
        }

我尝试使用我创建的附件变量,但它似乎不是用户上载的确切文件<问题出在哪里?可能重复感谢您的帮助,但您能否指导我如何获取附件,以便我可以创建数据库连接并将其保存在数据库中?。我需要为收到的附件创建一个变量。
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
{
    var message = await argument;

    if (message.Attachments != null && message.Attachments.Any())
    {
        var attachment = message.Attachments.First();
        using (HttpClient httpClient = new HttpClient())
        {
            // Skype & MS Teams attachment URLs are secured by a JwtToken, so we need to pass the token from our bot.
            if ((message.ChannelId.Equals("skype", StringComparison.InvariantCultureIgnoreCase) || message.ChannelId.Equals("msteams", StringComparison.InvariantCultureIgnoreCase)) 
                && new Uri(attachment.ContentUrl).Host.EndsWith("skype.com"))
            {
                var token = await new MicrosoftAppCredentials().GetTokenAsync();
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            }

            var responseMessage = await httpClient.GetAsync(attachment.ContentUrl);

            var contentLenghtBytes = responseMessage.Content.Headers.ContentLength;

            await context.PostAsync($"Attachment of {attachment.ContentType} type and size of {contentLenghtBytes} bytes received.");
        }
    }
    else
    {
        await context.PostAsync("Hi there! I'm a bot created to show you how I can receive message attachments, but no attachment was sent to me. Please, try again sending a new message including an attachment.");
    }

    context.Wait(this.MessageReceivedAsync);
}