feat: enrich inquiry telegram alerts
This commit is contained in:
@@ -59,7 +59,7 @@ public class InquiryServiceTests
|
|||||||
|
|
||||||
private sealed class FakeInquiryNotificationService : IInquiryNotificationService
|
private sealed class FakeInquiryNotificationService : IInquiryNotificationService
|
||||||
{
|
{
|
||||||
public Task NotifyCreatedAsync(int inquiryId, string name, string phone, string serviceType, string message, CancellationToken ct = default)
|
public Task NotifyCreatedAsync(int inquiryId, string name, string phone, string serviceType, string message, string? ipAddress, DateTime createdAtUtc, CancellationToken ct = default)
|
||||||
=> Task.CompletedTask;
|
=> Task.CompletedTask;
|
||||||
|
|
||||||
public Task NotifyStatusChangedAsync(int inquiryId, string name, string phone, string serviceType, string previousStatus, string newStatus, CancellationToken ct = default)
|
public Task NotifyStatusChangedAsync(int inquiryId, string name, string phone, string serviceType, string previousStatus, string newStatus, CancellationToken ct = default)
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ namespace TaxBaik.Application.Services;
|
|||||||
|
|
||||||
public interface IInquiryNotificationService
|
public interface IInquiryNotificationService
|
||||||
{
|
{
|
||||||
Task NotifyCreatedAsync(int inquiryId, string name, string phone, string serviceType, string message, CancellationToken ct = default);
|
Task NotifyCreatedAsync(int inquiryId, string name, string phone, string serviceType, string message, string? ipAddress, DateTime createdAtUtc, CancellationToken ct = default);
|
||||||
Task NotifyStatusChangedAsync(int inquiryId, string name, string phone, string serviceType, string previousStatus, string newStatus, CancellationToken ct = default);
|
Task NotifyStatusChangedAsync(int inquiryId, string name, string phone, string serviceType, string previousStatus, string newStatus, CancellationToken ct = default);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class InquiryService(IInquiryRepository repository, IInquiryNotificationS
|
|||||||
};
|
};
|
||||||
|
|
||||||
var inquiryId = await repository.CreateAsync(inquiry, ct);
|
var inquiryId = await repository.CreateAsync(inquiry, ct);
|
||||||
await notificationService.NotifyCreatedAsync(inquiryId, inquiry.Name, inquiry.Phone, inquiry.ServiceType, inquiry.Message, ct);
|
await notificationService.NotifyCreatedAsync(inquiryId, inquiry.Name, inquiry.Phone, inquiry.ServiceType, inquiry.Message, inquiry.IpAddress, inquiry.CreatedAt, ct);
|
||||||
return inquiryId;
|
return inquiryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ namespace TaxBaik.Application.Services;
|
|||||||
|
|
||||||
public sealed class NoopInquiryNotificationService : IInquiryNotificationService
|
public sealed class NoopInquiryNotificationService : IInquiryNotificationService
|
||||||
{
|
{
|
||||||
public Task NotifyCreatedAsync(int inquiryId, string name, string phone, string serviceType, string message, CancellationToken ct = default)
|
public Task NotifyCreatedAsync(int inquiryId, string name, string phone, string serviceType, string message, string? ipAddress, DateTime createdAtUtc, CancellationToken ct = default)
|
||||||
=> Task.CompletedTask;
|
=> Task.CompletedTask;
|
||||||
|
|
||||||
public Task NotifyStatusChangedAsync(int inquiryId, string name, string phone, string serviceType, string previousStatus, string newStatus, CancellationToken ct = default)
|
public Task NotifyStatusChangedAsync(int inquiryId, string name, string phone, string serviceType, string previousStatus, string newStatus, CancellationToken ct = default)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService
|
|||||||
_baseUrl = (_configuration["App:PublicBaseUrl"] ?? "http://178.104.200.7/taxbaik").TrimEnd('/');
|
_baseUrl = (_configuration["App:PublicBaseUrl"] ?? "http://178.104.200.7/taxbaik").TrimEnd('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task NotifyCreatedAsync(int inquiryId, string name, string phone, string serviceType, string message, CancellationToken ct = default)
|
public async Task NotifyCreatedAsync(int inquiryId, string name, string phone, string serviceType, string message, string? ipAddress, DateTime createdAtUtc, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
var botToken = _configuration["Telegram:BotToken"];
|
var botToken = _configuration["Telegram:BotToken"];
|
||||||
var chatId = _configuration["Telegram:ChatId"];
|
var chatId = _configuration["Telegram:ChatId"];
|
||||||
@@ -28,12 +28,15 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService
|
|||||||
|
|
||||||
var adminLink = $"{_baseUrl}/admin/inquiries/{inquiryId}";
|
var adminLink = $"{_baseUrl}/admin/inquiries/{inquiryId}";
|
||||||
var summary = message.Length > 180 ? message[..180] + "..." : message;
|
var summary = message.Length > 180 ? message[..180] + "..." : message;
|
||||||
|
var createdAtKst = createdAtUtc.AddHours(9);
|
||||||
var text = new StringBuilder()
|
var text = new StringBuilder()
|
||||||
.AppendLine("새 문의가 접수되었습니다.")
|
.AppendLine("🆕 새 문의가 접수되었습니다.")
|
||||||
.AppendLine()
|
.AppendLine()
|
||||||
.AppendLine($"제목: {serviceType}")
|
.AppendLine($"제목: {serviceType}")
|
||||||
.AppendLine($"이름: {name}")
|
.AppendLine($"이름: {name}")
|
||||||
.AppendLine($"연락처: {phone}")
|
.AppendLine($"연락처: {phone}")
|
||||||
|
.AppendLine($"접수 시각: {createdAtKst:yyyy-MM-dd HH:mm:ss} KST")
|
||||||
|
.AppendLine($"IP: {(string.IsNullOrWhiteSpace(ipAddress) ? "-" : ipAddress)}")
|
||||||
.AppendLine()
|
.AppendLine()
|
||||||
.AppendLine("내용 요약:")
|
.AppendLine("내용 요약:")
|
||||||
.AppendLine(summary)
|
.AppendLine(summary)
|
||||||
@@ -71,12 +74,12 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService
|
|||||||
|
|
||||||
var adminLink = $"{_baseUrl}/admin/inquiries/{inquiryId}";
|
var adminLink = $"{_baseUrl}/admin/inquiries/{inquiryId}";
|
||||||
var text = new StringBuilder()
|
var text = new StringBuilder()
|
||||||
.AppendLine("문의 상태가 변경되었습니다.")
|
.AppendLine("✏️ 문의 상태가 변경되었습니다.")
|
||||||
.AppendLine()
|
.AppendLine()
|
||||||
.AppendLine($"제목: {serviceType}")
|
.AppendLine($"제목: {serviceType}")
|
||||||
.AppendLine($"이름: {name}")
|
.AppendLine($"이름: {name}")
|
||||||
.AppendLine($"연락처: {phone}")
|
.AppendLine($"연락처: {phone}")
|
||||||
.AppendLine($"상태: {previousStatus} -> {newStatus}")
|
.AppendLine($"상태: {FormatStatus(previousStatus)} -> {FormatStatus(newStatus)}")
|
||||||
.AppendLine()
|
.AppendLine()
|
||||||
.AppendLine($"답변 링크: {adminLink}")
|
.AppendLine($"답변 링크: {adminLink}")
|
||||||
.ToString();
|
.ToString();
|
||||||
@@ -101,4 +104,12 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService
|
|||||||
_logger.LogWarning(ex, "텔레그램 상태 변경 알림 중 오류 발생");
|
_logger.LogWarning(ex, "텔레그램 상태 변경 알림 중 오류 발생");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string FormatStatus(string status) => status switch
|
||||||
|
{
|
||||||
|
"new" => "신규",
|
||||||
|
"contacted" => "연락함",
|
||||||
|
"completed" => "완료",
|
||||||
|
_ => status
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user