Complete customer communication system with automatic message delivery working correctly
This commit is contained in:
parent
eae5be3e7c
commit
3f4789730c
87
LittleShop/Controllers/BotMessagesController.cs
Normal file
87
LittleShop/Controllers/BotMessagesController.cs
Normal 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;
|
||||||
|
}
|
||||||
@ -90,6 +90,7 @@ public class MessagesController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("pending")]
|
[HttpGet("pending")]
|
||||||
|
[AllowAnonymous] // Allow bots to access without authentication
|
||||||
public async Task<ActionResult<IEnumerable<CustomerMessageDto>>> GetPendingMessages([FromQuery] string platform = "Telegram")
|
public async Task<ActionResult<IEnumerable<CustomerMessageDto>>> GetPendingMessages([FromQuery] string platform = "Telegram")
|
||||||
{
|
{
|
||||||
var messages = await _messageService.GetPendingMessagesAsync(platform);
|
var messages = await _messageService.GetPendingMessagesAsync(platform);
|
||||||
@ -97,6 +98,7 @@ public class MessagesController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("{id}/mark-sent")]
|
[HttpPost("{id}/mark-sent")]
|
||||||
|
[AllowAnonymous] // Allow bots to access without authentication
|
||||||
public async Task<ActionResult> MarkMessageAsSent(Guid id, [FromQuery] string? platformMessageId = null)
|
public async Task<ActionResult> MarkMessageAsSent(Guid id, [FromQuery] string? platformMessageId = null)
|
||||||
{
|
{
|
||||||
var success = await _messageService.MarkMessageAsSentAsync(id, platformMessageId);
|
var success = await _messageService.MarkMessageAsSentAsync(id, platformMessageId);
|
||||||
@ -121,6 +123,7 @@ public class MessagesController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("{id}/mark-failed")]
|
[HttpPost("{id}/mark-failed")]
|
||||||
|
[AllowAnonymous] // Allow bots to access without authentication
|
||||||
public async Task<ActionResult> MarkMessageAsFailed(Guid id, [FromBody] string reason)
|
public async Task<ActionResult> MarkMessageAsFailed(Guid id, [FromBody] string reason)
|
||||||
{
|
{
|
||||||
var success = await _messageService.MarkMessageAsFailedAsync(id, reason);
|
var success = await _messageService.MarkMessageAsFailedAsync(id, reason);
|
||||||
|
|||||||
BIN
LittleShop/littleshop.db-shm
Normal file
BIN
LittleShop/littleshop.db-shm
Normal file
Binary file not shown.
BIN
LittleShop/littleshop.db-wal
Normal file
BIN
LittleShop/littleshop.db-wal
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user