fix: Bot registration duplicate prevention and SilverPay integration update
- Fixed BotService to prevent duplicate bot registrations by checking for existing bot with same name/type - Updated existing bot record instead of creating duplicates on re-registration - Configured SilverPay integration with production API key - Updated TeleBot configuration for local development (localhost API URL, Tor disabled) This ensures single bot instances and proper payment gateway integration for testing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -26,10 +26,41 @@ public class BotService : IBotService
|
||||
|
||||
public async Task<BotRegistrationResponseDto> RegisterBotAsync(BotRegistrationDto dto)
|
||||
{
|
||||
_logger.LogInformation("Registering new bot: {BotName}", dto.Name);
|
||||
_logger.LogInformation("Registering bot: {BotName} (Type: {BotType})", dto.Name, dto.Type);
|
||||
|
||||
// Check if a bot with the same name and type already exists
|
||||
var existingBot = await _context.Bots
|
||||
.FirstOrDefaultAsync(b => b.Name == dto.Name && b.Type == dto.Type);
|
||||
|
||||
if (existingBot != null)
|
||||
{
|
||||
_logger.LogInformation("Bot already exists: {BotId}. Updating existing bot instead of creating duplicate.", existingBot.Id);
|
||||
|
||||
// Update existing bot
|
||||
existingBot.Description = dto.Description;
|
||||
existingBot.Version = dto.Version;
|
||||
existingBot.Settings = JsonSerializer.Serialize(dto.InitialSettings);
|
||||
existingBot.PersonalityName = string.IsNullOrEmpty(dto.PersonalityName) ? existingBot.PersonalityName : dto.PersonalityName;
|
||||
existingBot.Status = BotStatus.Active;
|
||||
existingBot.IsActive = true;
|
||||
existingBot.LastConfigSyncAt = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
_logger.LogInformation("Existing bot updated: {BotId}", existingBot.Id);
|
||||
|
||||
return new BotRegistrationResponseDto
|
||||
{
|
||||
BotId = existingBot.Id,
|
||||
BotKey = existingBot.BotKey,
|
||||
Name = existingBot.Name,
|
||||
Settings = dto.InitialSettings
|
||||
};
|
||||
}
|
||||
|
||||
// Create new bot if none exists
|
||||
var botKey = await GenerateBotKeyAsync();
|
||||
|
||||
|
||||
var bot = new Bot
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
@@ -48,7 +79,7 @@ public class BotService : IBotService
|
||||
_context.Bots.Add(bot);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
_logger.LogInformation("Bot registered successfully: {BotId}", bot.Id);
|
||||
_logger.LogInformation("New bot registered successfully: {BotId}", bot.Id);
|
||||
|
||||
return new BotRegistrationResponseDto
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user