Skip to content

fix file save #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public async Task<bool> SendMessage(string agentId,
{
var conversation = await GetConversationRecord(agentId);

// Save message files
var fileService = _services.GetRequiredService<IBotSharpFileService>();
fileService.SaveMessageFiles(_conversationId, message.MessageId, FileSourceType.User, message.Files);
message.Files?.Clear();

var agentService = _services.GetRequiredService<IAgentService>();
Agent agent = await agentService.LoadAgent(agentId);

Expand Down Expand Up @@ -46,11 +51,6 @@ public async Task<bool> SendMessage(string agentId,
routing.Context.SetMessageId(_conversationId, message.MessageId);
routing.Context.Push(agent.Id);

// Save message files
var fileService = _services.GetRequiredService<IBotSharpFileService>();
fileService.SaveMessageFiles(_conversationId, message.MessageId, FileSourceType.User, message.Files);
message.Files?.Clear();

// Save payload
if (replyMessage != null && !string.IsNullOrEmpty(replyMessage.Payload))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Amazon.Runtime.Internal.Auth;
using BotSharp.Abstraction.Browsing;
using BotSharp.Abstraction.Browsing.Models;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -221,14 +222,16 @@ public bool SaveMessageFiles(string conversationId, string messageId, string sou
}

var (_, bytes) = GetFileInfoFromData(file.FileData);
Thread.Sleep(100);
var subDir = Path.Combine(dir, source, $"{i + 1}");
if (!ExistDirectory(subDir))
{
Directory.CreateDirectory(subDir);
}

File.WriteAllBytes(Path.Combine(subDir, file.FileName), bytes);
using var fs = new FileStream(Path.Combine(subDir, file.FileName), FileMode.OpenOrCreate);
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
Thread.Sleep(100);
}

return true;
Expand Down