### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Configuration\XBotServiceConfiguration.cs
namespace xBotService.Configuration
{
public class XBotServiceConfiguration
{
///
/// Bot Required Token ...
///
public string Token { get; set; }
///
/// Base Route of Bot Api ...
///
public string BaseRoute { get; set; }
///
/// Verification Code Time to Live ...
///
public int VerificationCodeTTL { get; set; } = 300;
///
/// Verification Code Length ...
///
public int VerificationCodeLength { get; set; } = 6;
///
/// Default Timeout ...
///
public int DefaultClientTimeout { get; set; } = 360;
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Configuration\Entities\XBotUserEntityConfiguration.cs
using xBotService.Constants;
using xDataService.Providers;
using xBotService.Models.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace xBotService.Configuration.Entities
{
public class XBotUserEntityConfiguration: XBaseEntityTypeConfiguration
{
public override void Configure(EntityTypeBuilder builder)
{
builder.ToTable(XBotServiceConstants.XBotUserTable);
}
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Constants\ConfigurationNodeNames.cs
namespace xBotService.Constants
{
public partial struct ConfigurationNodeNames
{
public const string BOT_SERVICE_NODE = "BotServiceConfiguration";
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Constants\XBaleBotEndpoints.cs
using xExceptions.Attributes;
namespace xBotService.Constants
{
public enum XBotEndpoints
{
[StringValue("/bot{xBotToken}/getMe")]
GetMe,
[StringValue("/bot{xBotToken}/getChat")]
GetChat,
[StringValue("/bot{xBotToken}/sendMessage")]
SendMessage,
[StringValue("/bot{xBotToken}/getUpdates")]
GetUpdates,
[StringValue("/bot{xBotToken}/setWebhook")]
SetWebhook,
[StringValue("/bot{xBotToken}/deleteWebhook")]
DeleteWebhook,
[StringValue("/bot{xBotToken}/answerCallbackQuery")]
AnswerCallbackQuery,
[StringValue("/bot{xBotToken}/editMessageReplyMarkup")]
EditMessageReplyMarkup,
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Constants\XBotMessageParseMode.cs
using xExceptions.Attributes;
namespace xBotService.Constants
{
public enum XBotMessageParseMode
{
[StringValue("HTML")]
Html,
[StringValue("Markdown")]
Markdown
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Constants\XBotParams.cs
namespace xBotService.Constants
{
public struct XBotParams
{
public const string XLimit = "limit";
public const string XOffest = "offset";
public const string XTimeout = "timeout";
public const string XTokenParam = "{xBotToken}";
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Constants\XBotServiceConstants.cs
namespace xBotService.Constants
{
public struct XBotServiceConstants
{
//
// Bot Service Log Tag ...
public const string XBotServiceDILogTag = "XBotService";
//
// Table Mapping ...
public const string XBotUserTable = "BotUsers";
//
// GraphQL Mappings ...
public const string XBotUserSingleName = "botUser";
public const string XBotUserCollectionName = "botUsers";
//
// Hubs ...
public const string XBotUserDtoHub = "botUserDto";
public const string XBotUserEntityHub = "botUserEntity";
//
// Helper Method Names ...
public const string GetXBotUserEFRepositoryDescriptor = "GetXBotUserEFRepositoryDescriptor";
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Constants\XBotStyle.cs
using xExceptions.Attributes;
namespace xBotService.Constants
{
public enum XBotStyle
{
[StringValue("primary")]
Primary,
[StringValue("success")]
Success,
[StringValue("danger")]
Danger,
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Controllers\XBotProviderControllerBase.cs
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 logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider
)
{
this.botProvider = botProvider;
}
//
#region Actions ...
[HttpGet("Me")]
public virtual async Task> 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>> 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> 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> 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> 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> 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> 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> 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
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\DI\XDIHelperExtension.cs
using System;
using xDataService.Db;
using xDataService.DI;
using xPushService.DI;
using xCommons.Helpers;
using xCommons.Extensions;
using xDataService.Models;
using xPushService.Helpers;
using xExceptions.Constants;
using xBotService.Constants;
using xBotService.Providers;
using xDataService.Constants;
using xBotService.Interfaces;
using XBotUserService.Helpers;
using xHttpService.Interfaces;
using xBotService.Configuration;
using xBotService.Providers.Dtos;
using xBotService.Interfaces.Dtos;
using Microsoft.AspNetCore.Builder;
using xBotService.Providers.Entities;
using xBotService.Interfaces.Entities;
using Microsoft.Extensions.Configuration;
using xBotService.Interfaces.Entities.Dtos;
using Microsoft.Extensions.DependencyInjection;
using ConfigurationNodeNames = xBotService.Constants.ConfigurationNodeNames;
using xBotService.Reciever;
namespace xBotService.DI
{
public static class XDIHelperExtension
{
///
/// Retrieve Bot Service Configuration ...
///
///
///
public static XBotServiceConfiguration GetXBotServiceConfiguration(
this IConfiguration source
)
{
//
var section = source
.GetSection(ConfigurationNodeNames.BOT_SERVICE_NODE);
//
var result = section.Get();
if (result.IsNull())
{
result = new();
}
//
return result;
}
///
/// Extract Service Configurations and Register it ...
///
///
///
public static void AddXBotServiceConfiguration(
this IServiceCollection source,
IConfiguration configuration
)
{
//
var config = configuration.GetXBotServiceConfiguration();
source.AddXBotServiceConfiguration(config);
}
///
/// Register Service Configuration ...
///
///
///
public static void AddXBotServiceConfiguration(
this IServiceCollection source,
XBotServiceConfiguration configuration
)
{
//
if (configuration.IsNullOrDefault())
{
//
Log("Service Registration faild, Invalid Configuration ...");
XException.InvalidConfiguration.Throw();
}
//
source.AddSingleton(configuration);
Log("Service Configuration, Registered ...");
}
///
/// Register Service ...
///
///
///
///
///
public static void AddXBotService(
this IServiceCollection services,
IConfiguration configuration,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
//
var config = configuration.GetXBotServiceConfiguration();
//
AddBotService(
contextType: null,
services: services,
lifeTime: lifeTime,
configuration: config,
repositoryType: repositoryType
);
}
///
/// Register Service with Context ...
///
///
///
///
///
///
public static void AddXBotService(
this IServiceCollection services,
IConfiguration configuration,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
) where TContext : XDbContext
{
//
var config = configuration.GetXBotServiceConfiguration();
//
AddBotService(
services: services,
lifeTime: lifeTime,
configuration: config,
contextType: typeof(TContext),
repositoryType: repositoryType
);
}
///
/// Register Service ...
///
///
///
///
///
public static void AddXBotService(
this IServiceCollection services,
XBotServiceConfiguration configuration,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
//
AddBotService(
contextType: null,
services: services,
lifeTime: lifeTime,
configuration: configuration,
repositoryType: repositoryType
);
}
///
/// Register Service with Context ...
///
///
///
///
///
///
public static void AddXBotService(
this IServiceCollection services,
XBotServiceConfiguration configuration,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
) where TContext : XDbContext
{
//
AddBotService(
services: services,
lifeTime: lifeTime,
configuration: configuration,
contextType: typeof(TContext),
repositoryType: repositoryType
);
}
///
/// Use XBotService Middleware ...
///
///
///
public static void UseXBotService(
this IApplicationBuilder app,
bool isDevelopmentEnvironment = false
)
{
//
#region Using XTag Hubs ...
//
var pushHelper = new XPushServiceHelper();
//
pushHelper.AddHub(XBotServiceConstants.XBotUserDtoHub);
pushHelper.AddHub(XBotServiceConstants.XBotUserEntityHub);
//
app.UseXPushService(pushHelper);
#endregion
//
// Using XBotUser Repository Descriptor ...
if (!botUserDescriptor.IsNull())
{
//
app.UseXRepository(
descriptor: botUserDescriptor,
isDevelopmentEnvironment: isDevelopmentEnvironment
);
}
}
//
#region Private ...
private static XRepositoryDescriptor botUserDescriptor = null;
private static string XLogTag = XBotServiceConstants.XBotServiceDILogTag;
private static void Log(string message)
{
Console.WriteLine($"{XLogTag} => {message}");
}
private static void AddBotService(
IServiceCollection services,
XBotServiceConfiguration configuration,
XRepositoryType repositoryType,
Type contextType = null,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
//
var exception = XException.InvalidArgs.ToException();
//
// Validate Services
if (services.IsNull())
{
//
Log("Service Registration failed, services not provided ...");
throw exception;
}
//
// Check Requirements ...
var httpService = services.GetRegisteredService();
if (httpService.IsNull())
{
//
Log("Service Registration failed, HttpService not provided ...");
throw exception;
}
//
// Validate Configuration ...
services.AddXBotServiceConfiguration(configuration);
//
// Validate Repository Type
var isRepositoryTypeValid =
(repositoryType == XRepositoryType.EF && !contextType.IsNull()) ||
((repositoryType == XRepositoryType.Mongo || repositoryType == XRepositoryType.InMemory) && contextType.IsNull());
if (!isRepositoryTypeValid)
{
//
Log("Service Registration failed, Invalid Repository Type and Context Type ...");
throw exception;
}
//
// Make Instance of Repository Descriptor ...
switch (repositoryType)
{
//
case XRepositoryType.EF:
botUserDescriptor = typeof(XBotServiceHelper)
.InvokeGenericMethod(
args: null,
runtimeType: contextType,
methodName: XBotServiceConstants.GetXBotUserEFRepositoryDescriptor
);
break;
//
case XRepositoryType.Mongo:
botUserDescriptor = XBotServiceHelper.GetXBotUserMongoRepositoryDescriptor();
break;
//
case XRepositoryType.InMemory:
botUserDescriptor = XBotServiceHelper.GetXBotUserInMemoryRepositoryDescriptor();
break;
}
//
// Register XBotUser Repository Descriptor ...
services.AddXRepository(
lifeTime: lifeTime,
descriptor: botUserDescriptor
);
//
// Register Dto Services ...
services.Add(
new ServiceDescriptor(typeof(IXBotUserServiceProvider), typeof(XBotUserServiceProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXBotUserRepositoryService), typeof(XBotUserRepositoryService), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXBotUserRepositoryProvider), typeof(XBotUserRepositoryProvider), lifeTime)
);
//
// Bot Provider Registration ...
services.Add(
new ServiceDescriptor(typeof(IXBotProvider), typeof(XBotProvider), lifeTime)
);
//
// Using Bot Update Reciever ...
services.AddXBackgroundService();
//
Log("Service Registration Succeed ...");
}
#endregion
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Extensions\XBotServiceExtensions.cs
using xBotService.Models;
using xCommons.Extensions;
using xExceptions.Constants;
namespace xBotService.Extensions
{
public static class XBotServiceExtensions
{
///
/// Make Sure a Response Message is Valid ...
///
///
public static void EnsureBotResponseSucceed(
this XBotResponse source
)
{
//
var isValid =
!source.IsNull() &&
source.Ok;
if (!isValid)
{
XException.ActionFailed.Throw();
}
}
///
/// Validate a Message Send Request ...
///
///
///
public static bool IsValid(
this XBotSendMessageRequest source
)
{
//
var result =
!source.IsNull() &&
source.ChatId > 0;
//
return result;
}
///
/// Normalize ot Update Request ...
///
///
///
public static XBotUpdatesRequest Normalize(
this XBotUpdatesRequest source
)
{
//
if (source.IsNull())
{
source = new();
}
//
// Limit ...
if (source.Limit <= 0 || source.Limit > 100)
{
source.Limit = 100;
}
//
if (source.Offset < 0)
{
source.Offset = 0;
}
//
if (source.Timeout <= 30)
{
source.Timeout = 30;
}
//
return source;
}
///
/// Converts To Dto ...
///
///
///
public static XBotSendMessageRequestDto ToDto(
this XBotSendMessageRequest source
)
{
//
XBotSendMessageRequestDto result = null;
if (source.IsNull())
{
return result;
}
//
result = new();
result.UpdateData(source);
//
return result;
}
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Helper\XBotServiceHelper.cs
using GraphQL.Types;
using xDataService.Db;
using xDataService.Models;
using xDataService.Providers;
using xBotService.Models.Entities;
using xBotService.Providers.GraphQL;
using xBotService.Providers.Entities;
using xBotService.Interfaces.Entities;
namespace XBotUserService.Helpers
{
public static class XBotServiceHelper
{
//
#region EF Repository Descriptor Provider(s) ...
public static XEFRepositoryDescriptor<
XBotUser,
int,
IXBotUserKeyGenerator,
XBotUserKeyGenerator,
IXBotUserRepositoryEvents,
XBotUserRepositoryEvents,
XBotUserGraphType,
IntGraphType,
XBotUserGraphQuery,
IXBotUserGraphQLTypeHelper,
XBotUserGraphQLTypeHelper,
XBotUserGraphSchema,
IXBotUserRepository,
XBotUserEFRepository,
TContext
> GetXBotUserEFRepositoryDescriptor()
where TContext : XDbContext
{
//
var result = new XEFRepositoryDescriptor<
XBotUser,
int,
IXBotUserKeyGenerator,
XBotUserKeyGenerator,
IXBotUserRepositoryEvents,
XBotUserRepositoryEvents,
XBotUserGraphType,
IntGraphType,
XBotUserGraphQuery,
IXBotUserGraphQLTypeHelper,
XBotUserGraphQLTypeHelper,
XBotUserGraphSchema,
IXBotUserRepository,
XBotUserEFRepository,
TContext
>();
//
return result;
}
public static XEFRepositoryDescriptor<
XBotUser,
int,
IXBotUserKeyGenerator,
XBotUserKeyGenerator,
IXBotUserRepositoryEvents,
XBotUserRepositoryEvents,
XBotUserGraphType,
IntGraphType,
XBotUserGraphQuery,
IXBotUserGraphQLTypeHelper,
XBotUserGraphQLTypeHelper,
XBotUserGraphSchema,
IXBotUserRepository,
XBotUserEFRepository,
TContext,
IXBotUserSeeder,
TSeederImplementation
> GetXBotUserEFRepositoryDescriptor()
where TContext : XDbContext
where TSeederImplementation : XBaseDbSeeder
{
//
var result = new XEFRepositoryDescriptor<
XBotUser,
int,
IXBotUserKeyGenerator,
XBotUserKeyGenerator,
IXBotUserRepositoryEvents,
XBotUserRepositoryEvents,
XBotUserGraphType,
IntGraphType,
XBotUserGraphQuery,
IXBotUserGraphQLTypeHelper,
XBotUserGraphQLTypeHelper,
XBotUserGraphSchema,
IXBotUserRepository,
XBotUserEFRepository,
TContext,
IXBotUserSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region Mongo Repository Descriptor Provider(s) ...
public static XMongoRepositoryDescriptor<
XBotUser,
int,
IXBotUserKeyGenerator,
XBotUserKeyGenerator,
IXBotUserRepositoryEvents,
XBotUserRepositoryEvents,
XBotUserGraphType,
IntGraphType,
XBotUserGraphQuery,
IXBotUserGraphQLTypeHelper,
XBotUserGraphQLTypeHelper,
XBotUserGraphSchema,
IXBotUserRepository,
XBotUserMongoRepository
> GetXBotUserMongoRepositoryDescriptor()
{
//
var result = new XMongoRepositoryDescriptor<
XBotUser,
int,
IXBotUserKeyGenerator,
XBotUserKeyGenerator,
IXBotUserRepositoryEvents,
XBotUserRepositoryEvents,
XBotUserGraphType,
IntGraphType,
XBotUserGraphQuery,
IXBotUserGraphQLTypeHelper,
XBotUserGraphQLTypeHelper,
XBotUserGraphSchema,
IXBotUserRepository,
XBotUserMongoRepository
>();
//
return result;
}
public static XMongoRepositoryDescriptor<
XBotUser,
int,
IXBotUserKeyGenerator,
XBotUserKeyGenerator,
IXBotUserRepositoryEvents,
XBotUserRepositoryEvents,
XBotUserGraphType,
IntGraphType,
XBotUserGraphQuery,
IXBotUserGraphQLTypeHelper,
XBotUserGraphQLTypeHelper,
XBotUserGraphSchema,
IXBotUserRepository,
XBotUserMongoRepository,
IXBotUserSeeder,
TSeederImplementation
> GetXBotUserMongoRepositoryDescriptor()
where TSeederImplementation : XBaseDbSeeder
{
//
var result = new XMongoRepositoryDescriptor<
XBotUser,
int,
IXBotUserKeyGenerator,
XBotUserKeyGenerator,
IXBotUserRepositoryEvents,
XBotUserRepositoryEvents,
XBotUserGraphType,
IntGraphType,
XBotUserGraphQuery,
IXBotUserGraphQLTypeHelper,
XBotUserGraphQLTypeHelper,
XBotUserGraphSchema,
IXBotUserRepository,
XBotUserMongoRepository,
IXBotUserSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region InMemory Repository Descriptor Provider(s) ...
public static XInMemoryRepositoryDescriptor<
XBotUser,
int,
IXBotUserKeyGenerator,
XBotUserKeyGenerator,
IXBotUserRepositoryEvents,
XBotUserRepositoryEvents,
XBotUserGraphType,
IntGraphType,
XBotUserGraphQuery,
IXBotUserGraphQLTypeHelper,
XBotUserGraphQLTypeHelper,
XBotUserGraphSchema,
IXBotUserRepository,
XBotUserInMemoryRepository
> GetXBotUserInMemoryRepositoryDescriptor()
{
//
var result = new XInMemoryRepositoryDescriptor<
XBotUser,
int,
IXBotUserKeyGenerator,
XBotUserKeyGenerator,
IXBotUserRepositoryEvents,
XBotUserRepositoryEvents,
XBotUserGraphType,
IntGraphType,
XBotUserGraphQuery,
IXBotUserGraphQLTypeHelper,
XBotUserGraphQLTypeHelper,
XBotUserGraphSchema,
IXBotUserRepository,
XBotUserInMemoryRepository
>();
//
return result;
}
public static XInMemoryRepositoryDescriptor<
XBotUser,
int,
IXBotUserKeyGenerator,
XBotUserKeyGenerator,
IXBotUserRepositoryEvents,
XBotUserRepositoryEvents,
XBotUserGraphType,
IntGraphType,
XBotUserGraphQuery,
IXBotUserGraphQLTypeHelper,
XBotUserGraphQLTypeHelper,
XBotUserGraphSchema,
IXBotUserRepository,
XBotUserInMemoryRepository,
IXBotUserSeeder,
TSeederImplementation
> GetXBotUserInMemoryRepositoryDescriptor()
where TSeederImplementation : XBaseDbSeeder
{
//
var result = new XInMemoryRepositoryDescriptor<
XBotUser,
int,
IXBotUserKeyGenerator,
XBotUserKeyGenerator,
IXBotUserRepositoryEvents,
XBotUserRepositoryEvents,
XBotUserGraphType,
IntGraphType,
XBotUserGraphQuery,
IXBotUserGraphQLTypeHelper,
XBotUserGraphQLTypeHelper,
XBotUserGraphSchema,
IXBotUserRepository,
XBotUserInMemoryRepository,
IXBotUserSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Interfaces\IXBotProvider.cs
using System.Threading;
using xBotService.Models;
using xBotService.Constants;
using System.Threading.Tasks;
using System.Collections.Generic;
using xCommons.Extensions;
namespace xBotService.Interfaces
{
public interface IXBotProvider
{
///
/// Retrieve Bot Info ...
///
///
///
Task GetMe(
CancellationToken cancellationToken = default
);
///
/// Retrieve Messages ...
///
///
///
///
Task> GetUpdates(
XBotUpdatesRequest requestModel,
CancellationToken cancellationToken = default
);
///
/// Sending Simple String Message to Bot ...
///
///
///
///
Task SendMessage(
XBotSendMessageRequest requestModel,
CancellationToken cancellationToken = default
);
///
/// Show Verification Request Menu ...
///
///
///
///
///
Task ShowVerificationMenu(
long botUserId,
string label = "🔐 دریافت کد وریفیکیشن",
CancellationToken cancellationToken = default
);
///
/// Send Verification Code to Requests ...
///
///
///
///
///
///
// Task SendVerificationCode(
// long chatId,
// string code,
// int ttlSeconds,
// CancellationToken cancellationToken = default
// );
///
/// an Accept for Exit Loading on Bot ...
///
///
///
///
///
///
// Task AnswerCallbackQuery(
// string callbackQueryId,
// string text = null,
// bool showAlert = false,
// CancellationToken cancellationToken = default
// );
///
/// Remove Inline Keyboard After Click (Optional) ...
///
///
///
///
///
// Task RemoveInlineKeyboard(
// long chatId,
// long messageId,
// CancellationToken cancellationToken = default
// );
///
/// Set Webhook for Retrieve Messages on Recieved ...
///
///
///
///
///
// Task SetWebhook(
// string webhookUrl,
// string secretToken = null,
// CancellationToken cancellationToken = default
// );
}
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Interfaces\Dtos\IXBotUserDtoHub.cs
using xBotService.Models.Dtos;
using xPushService.Interfaces;
using xBotService.Models.Entities;
namespace xBotService.Interfaces.Dtos
{
public interface IXBotUserDtoHub : IXBaseDtoHub
{ }
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Interfaces\Dtos\IXBotUserRepositoryService.cs
using xBotService.Models.Dtos;
using xDataService.Interfaces;
using xBotService.Models.Entities;
namespace xBotService.Interfaces.Entities.Dtos
{
public interface IXBotUserRepositoryService : IXBaseRepositoryService
{ }
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Interfaces\Dtos\IXBotUserServiceProvider.cs
using xBotService.Models.Dtos;
using xPushService.Interfaces;
using xBotService.Models.Entities;
using xBotService.Providers.Dtos;
namespace xBotService.Interfaces.Dtos
{
public interface IXBotUserServiceProvider : IXBaseDtoProvider
{ }
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Interfaces\Entities\IXBotUserEntityHub.cs
using xPushService.Interfaces;
using xBotService.Models.Entities;
namespace xBotService.Interfaces.Entities
{
public interface IXBotUserEntityHub : IXBaseEntityHub
{ }
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Interfaces\Entities\IXBotUserGraphQLTypeHelper.cs
using xDataService.Interfaces;
using xBotService.Models.Entities;
namespace xBotService.Interfaces.Entities
{
public interface IXBotUserGraphQLTypeHelper : IXBaseGraphQLTypeHelper
{ }
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Interfaces\Entities\IXBotUserKeyGenerator.cs
using xDataService.Interfaces;
using xBotService.Models.Entities;
namespace xBotService.Interfaces.Entities
{
public interface IXBotUserKeyGenerator : IXKeyGenerator
{ }
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Interfaces\Entities\IXBotUserRepository.cs
using xDataService.Interfaces;
using xBotService.Models.Entities;
namespace xBotService.Interfaces.Entities
{
public interface IXBotUserRepository : IXBaseRepository
{ }
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Interfaces\Entities\IXBotUserRepositoryEvents.cs
using xDataService.Interfaces;
using xBotService.Models.Entities;
namespace xBotService.Interfaces.Entities
{
public interface IXBotUserRepositoryEvents : IXBaseRepositoryEvents
{ }
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Interfaces\Entities\IXBotUserRepositoryProvider.cs
using xPushService.Interfaces;
using xBotService.Models.Entities;
using xBotService.Providers.Entities;
namespace xBotService.Interfaces.Entities
{
public interface IXBotUserRepositoryProvider : IXBaseEntityProvider
{ }
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Interfaces\Entities\IXBotUserSeeder.cs
using xDataService.Interfaces;
using xBotService.Models.Entities;
namespace xBotService.Interfaces.Entities
{
public interface IXBotUserSeeder: IXBaseDbSeeder
{ }
}
### FILE: C:\Users\saherelm\Documents\Projects\xSaherelmWorkspace\Modules\xBotService\Models\XBotModels.cs
using System;
using Newtonsoft.Json;
using xCommons.Extensions;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace xBotService.Models
{
///
/// Represent XBot Response User ...
///
public class XBotResUser
{
[JsonProperty("id",
NullValueHandling = NullValueHandling.Ignore)]
public long Id { get; set; }
[JsonProperty("is_bot",
NullValueHandling = NullValueHandling.Ignore)]
public bool IsBot { get; set; }
[JsonProperty("last_name",
NullValueHandling = NullValueHandling.Ignore)]
public string LastName { get; set; }
[JsonProperty("username",
NullValueHandling = NullValueHandling.Ignore)]
public string Username { get; set; }
[JsonProperty("first_name",
NullValueHandling = NullValueHandling.Ignore)]
public string FirstName { get; set; }
[JsonProperty("language_code",
NullValueHandling = NullValueHandling.Ignore)]
public string LanguageCode { get; set; }
[JsonProperty("has_main_web_app",
NullValueHandling = NullValueHandling.Ignore)]
public string HasMainWebApp { get; set; }
[JsonProperty("has_topics_enabled",
NullValueHandling = NullValueHandling.Ignore)]
public bool HasTopicsEnabled { get; set; }
[JsonProperty("allows_users_to_create_topics",
NullValueHandling = NullValueHandling.Ignore)]
public bool AllowsUsersToCreateTopics { get; set; }
}
///
/// Base Bot Response ...
///
public class XBotResponse : XBotResponse