Small cleanup

This commit is contained in:
2024-01-28 20:25:12 +03:00
parent 1088037e58
commit d578f6a413
+3 -6
View File
@@ -10,7 +10,6 @@ using Telegram.Bot.Types;
namespace Kruzya.TelegramBot.Core.Controllers namespace Kruzya.TelegramBot.Core.Controllers
{ {
[Route("/Telegram")]
public class Telegram : Controller public class Telegram : Controller
{ {
private const string SecretTokenHeader = "X-Telegram-Bot-Api-Secret-Token"; private const string SecretTokenHeader = "X-Telegram-Bot-Api-Secret-Token";
@@ -33,9 +32,8 @@ namespace Kruzya.TelegramBot.Core.Controllers
} }
} }
[Route("/WebHook")]
[HttpPost] [HttpPost]
public IActionResult Index() public IActionResult Index([FromBody] Update? update)
{ {
if (_secretToken != null && !Request.Headers.ContainsKey(SecretTokenHeader)) if (_secretToken != null && !Request.Headers.ContainsKey(SecretTokenHeader))
{ {
@@ -50,15 +48,14 @@ namespace Kruzya.TelegramBot.Core.Controllers
return BadRequest(); return BadRequest();
} }
LaunchHandle(); LaunchHandle(update);
return Ok(); return Ok();
} }
private void LaunchHandle() private void LaunchHandle(Update? update)
{ {
try try
{ {
var update = JsonConvert.DeserializeObject<Update>(Request.Body.ToString());
if (update == null) if (update == null)
{ {
throw new System.Exception("Invalid request body"); throw new System.Exception("Invalid request body");