Complete customer communication system with automatic message delivery working correctly

This commit is contained in:
sysadmin 2025-08-27 18:51:19 +01:00
parent eae5be3e7c
commit 3f4789730c
4 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,87 @@
using Microsoft.AspNetCore.Mvc;
using LittleShop.DTOs;
using LittleShop.Services;
using LittleShop.Models;
namespace LittleShop.Controllers;
[ApiController]
[Route("api/bot/messages")]
public class BotMessagesController : ControllerBase
{
private readonly ICustomerMessageService _messageService;
private readonly ILogger<BotMessagesController> _logger;
public BotMessagesController(ICustomerMessageService messageService, ILogger<BotMessagesController> logger)
{
_messageService = messageService;
_logger = logger;
}
[HttpGet("pending")]
public async Task<ActionResult<IEnumerable<CustomerMessageDto>>> GetPendingMessages([FromQuery] string platform = "Telegram")
{
var messages = await _messageService.GetPendingMessagesAsync(platform);
return Ok(messages);
}
[HttpPost("{id}/mark-sent")]
public async Task<ActionResult> MarkMessageAsSent(Guid id, [FromQuery] string? platformMessageId = null)
{
var success = await _messageService.MarkMessageAsSentAsync(id, platformMessageId);
if (!success)
{
return NotFound("Message not found");
}
return Ok();
}
[HttpPost("{id}/mark-failed")]
public async Task<ActionResult> MarkMessageAsFailed(Guid id, [FromBody] string reason)
{
var success = await _messageService.MarkMessageAsFailedAsync(id, reason);
if (!success)
{
return NotFound("Message not found");
}
return Ok();
}
// TEMPORARY TEST ENDPOINT - REMOVE IN PRODUCTION
[HttpPost("test-create")]
public async Task<ActionResult<CustomerMessageDto>> CreateTestMessage([FromBody] CreateTestMessageDto dto)
{
var createMessageDto = new CreateCustomerMessageDto
{
CustomerId = dto.CustomerId,
OrderId = dto.OrderId,
Type = dto.Type,
Subject = dto.Subject,
Content = dto.Content,
Priority = dto.Priority,
IsUrgent = dto.IsUrgent
};
var message = await _messageService.CreateMessageAsync(createMessageDto);
if (message == null)
{
return BadRequest("Failed to create message");
}
return Ok(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;
}

View File

@ -90,6 +90,7 @@ public class MessagesController : ControllerBase
}
[HttpGet("pending")]
[AllowAnonymous] // Allow bots to access without authentication
public async Task<ActionResult<IEnumerable<CustomerMessageDto>>> GetPendingMessages([FromQuery] string platform = "Telegram")
{
var messages = await _messageService.GetPendingMessagesAsync(platform);
@ -97,6 +98,7 @@ public class MessagesController : ControllerBase
}
[HttpPost("{id}/mark-sent")]
[AllowAnonymous] // Allow bots to access without authentication
public async Task<ActionResult> MarkMessageAsSent(Guid id, [FromQuery] string? platformMessageId = null)
{
var success = await _messageService.MarkMessageAsSentAsync(id, platformMessageId);
@ -121,6 +123,7 @@ public class MessagesController : ControllerBase
}
[HttpPost("{id}/mark-failed")]
[AllowAnonymous] // Allow bots to access without authentication
public async Task<ActionResult> MarkMessageAsFailed(Guid id, [FromBody] string reason)
{
var success = await _messageService.MarkMessageAsFailedAsync(id, reason);

Binary file not shown.

Binary file not shown.