diff --git a/TaxBaik.Web/Pages/Contact.cshtml b/TaxBaik.Web/Pages/Contact.cshtml index a4fc1b6..c903eec 100644 --- a/TaxBaik.Web/Pages/Contact.cshtml +++ b/TaxBaik.Web/Pages/Contact.cshtml @@ -16,6 +16,7 @@ }
+ @Html.AntiForgeryToken()
diff --git a/TaxBaik.Web/Services/TelegramInquiryNotificationService.cs b/TaxBaik.Web/Services/TelegramInquiryNotificationService.cs index 0dfd011..ced8bac 100644 --- a/TaxBaik.Web/Services/TelegramInquiryNotificationService.cs +++ b/TaxBaik.Web/Services/TelegramInquiryNotificationService.cs @@ -1,5 +1,6 @@ using System.Net.Http.Json; using System.Text; +using System.Text.Json; using TaxBaik.Application.Services; namespace TaxBaik.Web.Services; @@ -60,13 +61,14 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService try { var response = await client.PostAsJsonAsync(url, payload, ct); + var responseBody = await response.Content.ReadAsStringAsync(ct); if (!response.IsSuccessStatusCode) { - _logger.LogWarning("텔레그램 알림 전송 실패: {StatusCode}", response.StatusCode); + _logger.LogWarning("텔레그램 알림 전송 실패: {StatusCode} {ResponseBody}", response.StatusCode, Truncate(responseBody)); } else { - _logger.LogInformation("텔레그램 새 문의 알림 전송 성공: #{InquiryId}", inquiryId); + _logger.LogInformation("텔레그램 새 문의 알림 전송 성공: #{InquiryId}, message_id={MessageId}", inquiryId, TryGetMessageId(responseBody)); } } catch (Exception ex) @@ -111,13 +113,14 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService try { var response = await client.PostAsJsonAsync(url, payload, ct); + var responseBody = await response.Content.ReadAsStringAsync(ct); if (!response.IsSuccessStatusCode) { - _logger.LogWarning("텔레그램 상태 변경 알림 실패: {StatusCode}", response.StatusCode); + _logger.LogWarning("텔레그램 상태 변경 알림 실패: {StatusCode} {ResponseBody}", response.StatusCode, Truncate(responseBody)); } else { - _logger.LogInformation("텔레그램 상태 변경 알림 전송 성공: #{InquiryId}", inquiryId); + _logger.LogInformation("텔레그램 상태 변경 알림 전송 성공: #{InquiryId}, message_id={MessageId}", inquiryId, TryGetMessageId(responseBody)); } } catch (Exception ex) @@ -133,4 +136,26 @@ public class TelegramInquiryNotificationService : IInquiryNotificationService "completed" => "완료", _ => status }; + + private static string TryGetMessageId(string responseBody) + { + try + { + using var document = JsonDocument.Parse(responseBody); + if (document.RootElement.TryGetProperty("result", out var result) + && result.TryGetProperty("message_id", out var messageId)) + { + return messageId.ToString(); + } + } + catch (JsonException) + { + return "unknown"; + } + + return "unknown"; + } + + private static string Truncate(string value) + => value.Length <= 500 ? value : value[..500] + "..."; }