无法通过Directline在Webchat中发送附件,相同的代码在模拟器中也可以正常工作

问题描述 投票:2回答:1
var response = MessageFactory.Attachment(new Attachment
{
     Name = @"application.png",
     ContentType = "image/png",
     ContentUrl =  "base64sting"
});

await dc.Context.SendActivityAsync(response);

当我尝试向用户发送附件时,上面的代码在webchat中抛出以下异常,在模拟器中运行正常

在Microsoft.Bot.Connector.Conversations.ReplyToActivityWithHttpMessagesAsync(StringsessionId,字符串activityId,活动活动,字典2customHeaders,CancelationToken cancelToken)D:\ a \ 1 \ s \ libraries \ Microsoft.Bot.Connector \ Conversations.cs:line 1121

在Microsoft.Bot.Connector.ConversationsExtensions.ReplyToActivityAsync(IConversations操作,字符串对话ID,字符串activityId,活动活动,在D:\ a \ 1 \ s \ libraries \ Microsoft.Bot.Connector \ ConversationsExtensions.cs:line241

在Microsoft.Bot.Builder.BotFrameworkAdapter.SendActivitiesAsync(ITurnContextturnContext,Activity []活动,CancellationTokencancelToken)在D:\ a \ 1 \ s \ libraries \ Microsoft.Bot.Builder \ BotFrameworkAdapter.cs:line316

在Microsoft.Bot.Builder.TurnContext。<> c__DisplayClass22_0.d.MoveNext()在D:\ a \ 1 \ s \ libraries \ Microsoft.Bot.Builder \ TurnContext.cs:line 267

我什至尝试过]

using (var connector = new ConnectorClient(new Uri(serviceUrl)))
{
    var attachments = new Attachments(connector);
    var response = await attachments.Client.Conversations.UploadAttachmentAsync(
        conversationId,
        new AttachmentData
        {
            Name = @"Resources\architecture-resize.png",
            OriginalBase64 = File.ReadAllBytes(imagePath),
            Type = "image/png",
        }
    );

    var attachmentUri = attachments.GetAttachmentUri(response.Id);

    return new Attachment
    {
        Name = @"Resources\architecture-resize.png",
        ContentType = "image/png",
        ContentUrl = attachmentUri,
    };
}

这同样失败,是否可以通过网络聊天在没有托管内容网址的情况下向用户发送附件?

var response = MessageFactory.Attachment(新附件{名称= @“ application.png”,ContentType =“ image / png”,ContentUrl =“ base64sting”});等待dc.Context.SendActivityAsync(...

c# .net-core botframework direct-line-botframework
1个回答
0
投票

对于那些面临此问题的人,以下是根本原因。

© www.soinside.com 2019 - 2024. All rights reserved.