public override async Task <OperationResult> Execute(OperationArgs args) { // checks if all arguments for concrete operation is defined if (!RequiredArgsName.Intersect(args.Args.Keys).Any()) { return(new OperationResult(null, OperationResult.OperationResultType.Failed, "One or more arguments for operation is missed!")); } if (!ValidateUser(args.User.UserRole)) { return(new OperationResult(null, OperationResult.OperationResultType.Failed, "User not valid to call this operation!")); } if (!args.Args.ContainsKey("CurrentDialog")) { return(new OperationResult(null, OperationResult.OperationResultType.Failed, "CurrentDialog arg is missed!")); } try { Dialog dia = args.Args["CurrentDialog"] as Dialog; if (dia == null) { return(new OperationResult(await BotManager.Core.Dialogs.RootDialog.Execute(args.User), OperationResult.OperationResultType.Success)); } var result = await dia.Owner.Execute(args.User); return(new OperationResult(result, OperationResult.OperationResultType.Success)); } catch (Exception e) { return(new OperationResult(null, OperationResult.OperationResultType.Failed, $"{e.Message}")); } }
public async override Task <OperationResult> Execute(OperationArgs args) { if (args == null) { return(new OperationResult(null, OperationResult.OperationResultType.Failed, "Operation args can't be null!")); } var response = await base.Execute(args); if (response.ResultType == OperationResult.OperationResultType.Failed) { return(response); } var msgArgs = GetMessageParams(args); if (msgArgs == null) { return(new OperationResult(null, OperationResult.OperationResultType.Failed, "Can't parse operation arguments!")); } // do the job try { var msg = await BotManager.Core.BotApiManager.Api.SendTextMessageAsync (msgArgs.Value.ChatId, msgArgs.Value.Content, Telegram.Bot.Types.Enums.ParseMode.Html, replyMarkup : msgArgs.Value.ReplyMarkup); return(new OperationResult(msg.MessageId, OperationResult.OperationResultType.Success)); } catch (Exception e) { return(new OperationResult(e, OperationResult.OperationResultType.Failed, e.Message)); } }
public override async Task <OperationResult> Execute(OperationArgs args) { try { Dialog dia = BotManager.Core.Dialogs.RootDialog; var result = await dia.Execute(args.User); return(new OperationResult(result, OperationResult.OperationResultType.Success)); } catch (Exception e) { return(new OperationResult(null, OperationResult.OperationResultType.Failed, $"{e.Message}")); } }
/// <summary> /// Return converted basic message arguments /// </summary> protected virtual MessageParams?GetMessageParams(OperationArgs args) { MessageParams result = new MessageParams(); try { result.ChatId = Convert.ToInt64(args["ChatId"]); result.Content = args["Content"]?.ToString(); result.ReplyMarkup = (IReplyMarkup)args["ReplyMarkdown"]; result.MsgId = args["MsgId"] == null ? -1 : Convert.ToInt32(args["MsgId"]); return(result); } catch { return(null); } }
public async virtual Task <OperationResult> Execute(OperationArgs args) { // checks if all arguments for concrete operation is defined if (!RequiredArgsName.Intersect(args.Args.Keys).Any()) { return(new OperationResult(null, OperationResult.OperationResultType.Failed, "One or more arguments for operation is missed!")); } if (!ValidateUser(args.User.UserRole)) { return(new OperationResult(null, OperationResult.OperationResultType.Failed, "User not valid to call operation!")); } // return empty response to next handler await Task.Delay(BotManager.Core.Configs.BasicDelay); return(new OperationResult(null, OperationResult.OperationResultType.Unknown)); }
public override async Task <OperationResult> Execute(OperationArgs args) { if (args == null) { return(new OperationResult(null, OperationResult.OperationResultType.Failed, "Operation args can't be null!")); } var response = await base.Execute(args); if (response.ResultType == OperationResult.OperationResultType.Failed) { return(response); } try { // read collected arguments from dialog series // create user add info, fill preferences and etc. IUserAddInfo userAddInfo = BotManager.Core.Repository.CreateUserAddInfo(args.User); userAddInfo.SetFields(args.Args); args.User.UserInfo = userAddInfo; bool result = await BotManager.Core.BotApiManager.UsersController.CompleateRegistration(args.User); if (result) { return(new OperationResult(args.User, OperationResult.OperationResultType.Success)); } else { return(new OperationResult(null, OperationResult.OperationResultType.Failed)); } } catch (Exception e) { return(new OperationResult(e, OperationResult.OperationResultType.Failed, e.Message)); } }
public override async Task <OperationResult> Execute(OperationArgs args) { return(new OperationResult()); }