### 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 in Minute ...
///
public int VerificationCodeTTL { get; set; } = 5;
///
/// 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\XBotMessageIds.cs
namespace xBotService.Constants
{
public struct XBotMessageIds
{
public const string XBotRequestVerificationCode = "request_verification_code";
public const string XBotRequestVerificationCodeLabel = "🔐 دریافت کد اعتبارسنجی";
public const string XBotVerificationCodeMessageText = """
کد اعتبارسنجی شما: {xVerificationCode}
مدت اعتبار {xTTLInMinute} دقیقه
این کد را با ورود به سامانه در بخش پروفایل کاربری وارد کنید
""";
public const string XBotRequestVerificationCodeMessageText = "برای دریافت کد اعتبارسنجی روی دکمه زیر کلیک کنید:";
public const string XBotUserVerificationSucceedMessageText = "کاربر گرامی، اعتبار سنجی شما با موفقیت انجام شد.";
}
}
### 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}";
public const string XTTLInMinuteParam = "{xTTLInMinute}";
public const string XVerificationTokenParam = "{xVerificationCode}";
}
}
### 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;
using xBotService.Reciever;
namespace xBotService.Controllers
{
public abstract class XBotProviderControllerBase : XBaseIdentityApiV1Controller
{
private readonly IXBotProvider botProvider;
private readonly XBotBotUpdateRecieverBackgroundService botHandler;
protected XBotProviderControllerBase(
IXBotProvider botProvider,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
ILogger logger,
XBotBotUpdateRecieverBackgroundService botHandler
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider
)
{
this.botProvider = botProvider;
this.botHandler = botHandler;
}
//
#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("{botUserId}/ShowVerificationMenu")]
public virtual async Task> ShowVerificationMenu(
[FromRoute] long botUserId,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Validation ...
if (botUserId <= 0)
{
XException.InvalidArgs.Throw();
}
//
var result = await botProvider.ShowVerificationMenu(
botUserId: botUserId,
cancellationToken: cancellationToken
);
//
return Ok(result.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
[HttpPost("{token}/VerifyUser")]
public virtual async Task> VerifyUser(
[FromRoute] string token,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Validation ...
if (token.IsNullOrEmpty())
{
XException.InvalidArgs.Throw();
}
//
var userInfo = await GetUserInfo();
//
var result = await botProvider.VerifyUser(
token: token,
userInfo: userInfo,
cancellationToken: cancellationToken
);
//
return Ok(result.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
[HttpPost("Refresh")]
public virtual async Task Refresh(
CancellationToken cancellationToken = default
)
{
//
try
{
//
await botHandler.Refresh(cancellationToken);
//
return Ok();
}
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 xBotService.Reciever;
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;
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;
using xBotService.Models.Dtos;
using xBotService.Configuration;
using xBotService.Models.Entities;
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;
}
///
/// Check a User is Verified or not ...
///
///
///
public static bool IsVerified(
this XBotUser source
)
{
//
var result =
!source.IsNullOrDefault() &&
source.VerifiedOn.HasValue;
//
return result;
}
///
/// Check a User is Verified or not ...
///
///
///
public static bool IsVerified(
this XBotUserDto source
)
{
//
var result =
!source.IsNullOrDefault() &&
source.VerifiedOn.HasValue;
//
return result;
}
///
/// Check a User's Verification Code is Expired or not ...
///
///
///
///
public static bool IsExpired(
this XBotUser source,
XBotServiceConfiguration configuration
)
{
//
// Validate ...
if (configuration.IsNull() ||
source.IsNullOrDefault() ||
!source.VerifiedOn.HasValue ||
configuration.VerificationCodeTTL <= 0)
{
XException.InvalidArgs.Throw();
}
//
var result = source.VerifiedOn.Value.IsExpiredTTL(configuration.VerificationCodeTTL);
return result;
}
///
/// Check a User's Verification Code is Expired or not ...
///
///
///
///
public static bool IsExpired(
this XBotUserDto source,
XBotServiceConfiguration configuration
)
{
//
// Validate ...
if (configuration.IsNull() ||
source.IsNullOrDefault() ||
!source.VerifiedOn.HasValue ||
configuration.VerificationCodeTTL <= 0)
{
XException.InvalidArgs.Throw();
}
//
var result = source.VerifiedOn.Value.IsExpiredTTL(configuration.VerificationCodeTTL);
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 = source.MapConvert();
//
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;
using xBotService.Models.Dtos;
using xIdentityModels.Models;
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 = XBotMessageIds.XBotRequestVerificationCodeLabel,
CancellationToken cancellationToken = default
);
///
/// Send Verification Code to Requests ...
///
///
///
///
Task SendVerificationCode(
long botUserId,
CancellationToken cancellationToken = default
);
///
/// Verify User Subscription ...
///
///
///
///
///
Task VerifyUser(
string token,
XUserClaimsInfoDto userInfo = 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