无法使用直线在Webchat中发送附件,相同的代码在模拟器中工作正常

时间:2019-04-24 22:24:24

标签: c# .net-core botframework direct-line-botframework

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(String   sessionId,字符串activityId,活动活动,字典2   customHeaders,CancelationToken cancelToken)   D:\ a \ 1 \ s \ libraries \ Microsoft.Bot.Connector \ Conversations.cs:第1121行

     在

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

     在

  Microsoft.Bot.Builder.BotFrameworkAdapter.SendActivitiesAsync(ITurnContext   turnContext,Activity []活动,CancellationToken   cancelToken)在   D:\ a \ 1 \ s \ libraries \ Microsoft.Bot.Builder \ BotFrameworkAdapter.cs:line   316

     在

  Microsoft.Bot.Builder.TurnContext。<> c__DisplayClass22_0.d.MoveNext()   在D:\ a \ 1 \ s \ libraries \ Microsoft.Bot.Builder \ TurnContext.cs:第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,
    };
}

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

1 个答案:

答案 0 :(得分:1)

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

我试图将图像作为一个项目发送以单击并保存,我想我已经解决了这个问题,Directline仅支持4MB消息大小,我图像的base64string非常大,导致消息超过4MB,现在是将图片上传到天蓝色的blob并将blob uri用作contentURI,它现在可以正常工作