Implement bidirectional customer conversations with customer-based grouping and order tagging
This commit is contained in:
@@ -72,10 +72,60 @@ public class BotMessagesController : ControllerBase
|
||||
|
||||
return Ok(message);
|
||||
}
|
||||
|
||||
[HttpPost("customer-create")]
|
||||
public async Task<ActionResult> CreateCustomerMessage([FromBody] CreateCustomerMessageFromTelegramDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Create CustomerToAdmin message directly
|
||||
var message = new CustomerMessage
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CustomerId = dto.CustomerId,
|
||||
OrderId = dto.OrderId,
|
||||
Direction = MessageDirection.CustomerToAdmin,
|
||||
Type = dto.Type,
|
||||
Subject = dto.Subject,
|
||||
Content = dto.Content,
|
||||
Status = MessageStatus.Read, // Customer messages are immediately "read" by system
|
||||
Platform = "Telegram",
|
||||
Priority = dto.Priority,
|
||||
IsUrgent = dto.IsUrgent,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
ThreadId = Guid.NewGuid() // Will be updated if part of existing thread
|
||||
};
|
||||
|
||||
// Save directly to database (bypass the regular CreateMessageAsync which is for AdminToCustomer)
|
||||
var result = await _messageService.CreateCustomerToAdminMessageAsync(message);
|
||||
if (!result)
|
||||
{
|
||||
return BadRequest("Failed to create customer message");
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest($"Error creating customer message: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TEMPORARY DTO FOR TESTING
|
||||
public class CreateTestMessageDto
|
||||
{
|
||||
public Guid CustomerId { get; set; }
|
||||
public Guid? OrderId { get; set; }
|
||||
public MessageType Type { get; set; }
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
public string Content { get; set; } = string.Empty;
|
||||
public int Priority { get; set; } = 5;
|
||||
public bool IsUrgent { get; set; } = false;
|
||||
}
|
||||
|
||||
// DTO for customer messages from Telegram
|
||||
public class CreateCustomerMessageFromTelegramDto
|
||||
{
|
||||
public Guid CustomerId { get; set; }
|
||||
public Guid? OrderId { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user