Skip to content

Commit

Permalink
fix(Directories): Ensure directories exist before saving files.
Browse files Browse the repository at this point in the history
  • Loading branch information
frostaura committed Feb 23, 2024
1 parent d9713bb commit 44c2f8a
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ private async Task OnMessageAsync(ITelegramBotClient bot, Update update, Cancell

_logger.LogInformation($"[{this.GetType().Name}][{senderFullName}] Received a new message: {update}");

// Ensure directories exist.
if (!Directory.Exists(Path.Combine(_telegramConfig.MediaStoragePath)))
Directory.CreateDirectory(Path.Combine(_telegramConfig.MediaStoragePath));
if (!Directory.Exists(Path.Combine(_telegramConfig.MediaStoragePath, "photos")))
Directory.CreateDirectory(Path.Combine(_telegramConfig.MediaStoragePath, "photos"));
if (!Directory.Exists(Path.Combine(_telegramConfig.MediaStoragePath, "documents")))
Directory.CreateDirectory(Path.Combine(_telegramConfig.MediaStoragePath, "documents"));
if (!Directory.Exists(Path.Combine(_telegramConfig.MediaStoragePath, "voicenotes")))
Directory.CreateDirectory(Path.Combine(_telegramConfig.MediaStoragePath, "voicenotes"));

// Process Photo Messages
if (message?.Photo != default)
{
Expand Down

0 comments on commit 44c2f8a

Please sign in to comment.