refactor uncompleted works exists in Bot Service ...
This commit is contained in:
@@ -0,0 +1,329 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using xCommons.Providers;
|
||||
using xBotService.Models;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using xBotService.Interfaces;
|
||||
using System.Threading.Tasks;
|
||||
using xCommons.Configurations;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using xIdentityService.Interfaces;
|
||||
using xIdentityService.Controllers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace xBotService.Controllers
|
||||
{
|
||||
public abstract class XBotProviderControllerBase : XBaseIdentityApiV1Controller
|
||||
{
|
||||
private readonly IXBotProvider botProvider;
|
||||
|
||||
protected XBotProviderControllerBase(
|
||||
IXBotProvider botProvider,
|
||||
ILogger<XBotProviderControllerBase> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
)
|
||||
{
|
||||
this.botProvider = botProvider;
|
||||
}
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
[HttpGet("Me")]
|
||||
public virtual async Task<ActionResult<XBotResUser>> GetMe(
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
var result = await botProvider.GetMe(cancellationToken);
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("Updates")]
|
||||
public virtual async Task<ActionResult<IList<XBotUpdateResponse>>> GetUpdates(
|
||||
[FromQuery] XBotUpdatesRequest request,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validation ...
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await botProvider.GetUpdates(
|
||||
requestModel: request,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("Message")]
|
||||
public virtual async Task<ActionResult<XBotMessage>> SendMessage(
|
||||
[FromBody] XBotSendMessageRequest request,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
try
|
||||
{
|
||||
//
|
||||
// Validation ...
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
await ValidationProvider.GroupValidationBuilder()
|
||||
.AddNotNull(request)
|
||||
.AddNotEmpty(request.Text)
|
||||
.AddNotZero(request.ChatId)
|
||||
.ValidateGroupAsync();
|
||||
|
||||
//
|
||||
var result = await botProvider.SendMessage(
|
||||
requestModel: request,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
return Ok(result.ToDynamicObject());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
var result = GetExceptionActionResult(ex);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// [HttpPost("{chatId}/ShowVerificationMenu")]
|
||||
// public virtual async Task<ActionResult<XBotMessageResponse>> ShowVerificationMenu(
|
||||
// [FromRoute] long chatId,
|
||||
// CancellationToken cancellationToken = default
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// try
|
||||
// {
|
||||
// //
|
||||
// // Validation ...
|
||||
// if (!ModelState.IsValid)
|
||||
// {
|
||||
// XException.InvalidArgs.Throw();
|
||||
// }
|
||||
// if (chatId <= 0)
|
||||
// {
|
||||
// XException.InvalidArgs.Throw();
|
||||
// }
|
||||
|
||||
// //
|
||||
// var result = await botProvider.SendVerificationMenu(
|
||||
// chatId: chatId,
|
||||
// cancellationToken: cancellationToken
|
||||
// );
|
||||
|
||||
// //
|
||||
// return Ok(result.ToDynamicObject());
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// //
|
||||
// var result = GetExceptionActionResult(ex);
|
||||
// return result;
|
||||
// }
|
||||
// }
|
||||
|
||||
// [HttpPost("{chatId}/SendVerificationCode")]
|
||||
// public virtual async Task<ActionResult<XBotMessageResponse>> SendVerificationCode(
|
||||
// [FromRoute] long chatId,
|
||||
// [FromQuery] string code,
|
||||
// [FromQuery] int ttlSeconds,
|
||||
// CancellationToken cancellationToken = default
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// try
|
||||
// {
|
||||
// //
|
||||
// // Validation ...
|
||||
// if (!ModelState.IsValid)
|
||||
// {
|
||||
// XException.InvalidArgs.Throw();
|
||||
// }
|
||||
// if (chatId <= 0 || code.IsNullOrEmpty() || ttlSeconds < 60)
|
||||
// {
|
||||
// XException.InvalidArgs.Throw();
|
||||
// }
|
||||
|
||||
// //
|
||||
// var result = await botProvider.SendVerificationCode(
|
||||
// code: code,
|
||||
// chatId: chatId,
|
||||
// ttlSeconds: ttlSeconds,
|
||||
// cancellationToken: cancellationToken
|
||||
// );
|
||||
|
||||
// //
|
||||
// return Ok(result.ToDynamicObject());
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// //
|
||||
// var result = GetExceptionActionResult(ex);
|
||||
// return result;
|
||||
// }
|
||||
// }
|
||||
|
||||
// [HttpPost("{id}/AnswerCallback")]
|
||||
// public virtual async Task<ActionResult<XBotMessageResponse>> AnswerCallbackQuery(
|
||||
// [FromRoute] string callbackQueryId,
|
||||
// [FromQuery] string text = null,
|
||||
// [FromQuery] bool showAlert = false,
|
||||
// CancellationToken cancellationToken = default
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// try
|
||||
// {
|
||||
// //
|
||||
// // Validation ...
|
||||
// if (!ModelState.IsValid ||
|
||||
// callbackQueryId.IsNullOrEmpty())
|
||||
// {
|
||||
// XException.InvalidArgs.Throw();
|
||||
// }
|
||||
|
||||
// //
|
||||
// var result = await botProvider.AnswerCallbackQuery(
|
||||
// text: text,
|
||||
// showAlert: showAlert,
|
||||
// callbackQueryId: callbackQueryId,
|
||||
// cancellationToken: cancellationToken
|
||||
// );
|
||||
|
||||
// //
|
||||
// return Ok(result.ToDynamicObject());
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// //
|
||||
// var result = GetExceptionActionResult(ex);
|
||||
// return result;
|
||||
// }
|
||||
// }
|
||||
|
||||
// [HttpPost("{chatId}/RemoveInlineKeyboard")]
|
||||
// public virtual async Task<ActionResult<XBotMessageResponse>> RemoveInlineKeyboard(
|
||||
// [FromRoute] long chatId,
|
||||
// [FromQuery] long messageId,
|
||||
// CancellationToken cancellationToken = default
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// try
|
||||
// {
|
||||
// //
|
||||
// // Validation ...
|
||||
// if (!ModelState.IsValid)
|
||||
// {
|
||||
// XException.InvalidArgs.Throw();
|
||||
// }
|
||||
// if (chatId <= 0 || messageId <= 0)
|
||||
// {
|
||||
// XException.InvalidArgs.Throw();
|
||||
// }
|
||||
|
||||
// //
|
||||
// var result = await botProvider.RemoveInlineKeyboard(
|
||||
// chatId: chatId,
|
||||
// messageId: messageId,
|
||||
// cancellationToken: cancellationToken
|
||||
// );
|
||||
|
||||
// //
|
||||
// return Ok(result.ToDynamicObject());
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// //
|
||||
// var result = GetExceptionActionResult(ex);
|
||||
// return result;
|
||||
// }
|
||||
// }
|
||||
|
||||
// [HttpPost("Webhook")]
|
||||
// public virtual async Task<ActionResult<bool>> SetWebhook(
|
||||
// [FromQuery] string webhookUrl,
|
||||
// [FromQuery] string secretToken = null,
|
||||
// CancellationToken cancellationToken = default
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// try
|
||||
// {
|
||||
// //
|
||||
// // Validation ...
|
||||
// if (!ModelState.IsValid)
|
||||
// {
|
||||
// XException.InvalidArgs.Throw();
|
||||
// }
|
||||
// await ValidationProvider
|
||||
// .GroupValidationBuilder()
|
||||
// .AddNotEmpty(webhookUrl)
|
||||
// .AddUrl(webhookUrl)
|
||||
// .ValidateGroupAsync();
|
||||
|
||||
// //
|
||||
// var result = await botProvider.SetWebhook(
|
||||
// webhookUrl: webhookUrl,
|
||||
// secretToken: secretToken,
|
||||
// cancellationToken: cancellationToken
|
||||
// );
|
||||
|
||||
// //
|
||||
// return Ok(result);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// //
|
||||
// var result = GetExceptionActionResult(ex);
|
||||
// return result;
|
||||
// }
|
||||
// }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user