Exemplo n.º 1
0
 public Step(string id_, List <IAction_> actions_, IAction_ onRejectAction_ = null, string onRejectGotoStepId_ = null, int?stepEvalLimit_ = null)
 {
     Id                 = id_;
     Actions            = actions_;
     OnRejectAction     = onRejectAction_;
     OnRejectGotoStepId = onRejectGotoStepId_;
     _stepEvalLimit     = stepEvalLimit_;
 }
                protected override void OnAwaitingResponse(IAction_ action, Application workflow, Opt <Result <ActionResponse> > response, Lead evaluationCtx)
                {
                    if (response.IsNone)
                    {
                        return;
                    }

                    var response_ = response.Val.Map(ActionResponse.AsReceiveMessage);
                    var action_   = (Action_ <ReceiveMessageResponse>)action;

                    action_.ReceiveResponse(response_, UtcDateTime.Now, evaluationCtx);
                }
Exemplo n.º 3
0
 public void Eval(IAction_ action, TWorkflow workflow, Opt <Result <ActionResponse> > response, TEvalCtx evaluationCtx)
 {
     if (action.IsAwaitingAction)
     {
         OnAwaitingAction(action, workflow, response, evaluationCtx);
     }
     else if (action.IsAwaitingResponse)
     {
         OnAwaitingResponse(action, workflow, response, evaluationCtx);
     }
     else
     {
         throw new Exception($"Trying to run action: {action.ActionType}, but it is not awaiting.");
     }
 }
Exemplo n.º 4
0
        public static ActionDebug ToDebug(IAction_ action)
        {
            var dbgAction = new ActionDebug();

            dbgAction.ActionType         = action.ActionType;
            dbgAction.Description        = action.MessageText;
            dbgAction.IsAwaitingAction   = action.IsAwaitingAction;
            dbgAction.IsAwaitingResponse = action.IsAwaitingResponse;
            dbgAction.IsComplete         = action.IsComplete;
            dbgAction.IsAccepted         = action.IsAccepted;
            dbgAction.IsRejected         = action.IsRejected;

            dbgAction.RequestResponses = action.DebugResults.Select(ToDebug).ToList();

            return(dbgAction);
        }
Exemplo n.º 5
0
 protected override void OnAwaitingAction(IAction_ action, Application workflow, Opt <Result <ActionResponse> > response, Lead evaluationCtx)
 {
     // If we DONT have a response, do some IO to get the response we need.
     // Else we already have a predefined response for this action, so we dont need to do any IO, and just
     // receive the predefined response
     if (response.IsNone)
     {
         var sendResult = _messageSvc.SendMessage(action.MessageText, workflow.MobileNo).Map(_ => action.MessageText);
         action.MarkAsActioned(sendResult, Participant.User, UtcDateTime.Now, evaluationCtx);
     }
     else
     {
         action.MarkAsActioned(Ok(action.MessageText), Participant.User, UtcDateTime.Now, evaluationCtx);
         OnAwaitingResponse(action, workflow, response, evaluationCtx);
     }
 }
                protected override void OnAwaitingAction(IAction_ action, Application workflow, Opt <Result <ActionResponse> > response, Lead evaluationCtx)
                {
                    // extract the info we need to send to the Product Recommendation service
                    var lead      = evaluationCtx;
                    var appValues = workflow.Result;
                    var score     = appValues.ContainsKey("CustomerScoreValue") ? Convert.ToInt32(appValues["CustomerScoreValue"].ValOr("0").IfEmpty("0")) : lead.ScoreValue.ValOr(0);
                    var bracket   = appValues.ContainsKey("CustomerProductBracket") ? appValues["CustomerProductBracket"].ValOr("") : lead.ProductBracket.ValOr("");

                    // get the products EITHER as a predefined response, OR hit the WebAPI to get the products based on the customer score
                    var recommendedProducts = response.Fold(o => o.Map(ActionResponse.AsProductList)
                                                            , () => score >= 1 ? _productSvc.GetProductsByScore(score) : _productSvc.GetProductsByBracket(bracket));

                    // update the action to reflect that we have actioned it, and received a response
                    var action_ = (LoadRecommendedProductsAction)workflow.Action;

                    action_.MarkAsActioned(Ok($"LoadRecommendedProducts(score:'{score}', bracket:'{bracket}')"), Participant.ExternalSystem, UtcDateTime.Now, evaluationCtx);
                    action_.ReceiveResponse(recommendedProducts, UtcDateTime.Now, evaluationCtx);
                }
                protected override void OnAwaitingAction(IAction_ action, Application workflow, Opt <Result <ActionResponse> > response, Lead evaluationCtx)
                {
                    // extract the info that we need to send to the Scoring service from the conversation
                    var    lead      = evaluationCtx;
                    var    appValues = workflow.Result;
                    string idNo      = appValues.ContainsKey("CustomerIdNumber") ? appValues["CustomerIdNumber"].ValOr("") : lead.Surname.ValOr("");
                    string surname   = appValues.ContainsKey("CustomerSurname") ? appValues["CustomerSurname"].ValOr("") : lead.Surname.ValOr("");
                    string firstName = "FirstName";   // hard coded for now (because this is a required field in the API)

                    // get the customer score EITHER as a predefined response, OR hit the WebAPI to get the customer score
                    var score = response.Fold(o => o.Map(ActionResponse.AsScoreCustomer)
                                              , () => _scoringSvc.ScoreCustomer(idNo, firstName, surname));

                    // update the action to reflect that we have actioned it, and received a response
                    var action_ = (ScoringAction)action;

                    action_.MarkAsActioned(Ok($"ScoreCustomer(id:'{idNo}', firstname:'{firstName}', surname:'{surname}')"), Participant.ExternalSystem, UtcDateTime.Now, evaluationCtx);
                    action_.ReceiveResponse(score, UtcDateTime.Now, evaluationCtx);
                }
                protected override void OnAwaitingAction(IAction_ action, Application workflow, Opt <Result <ActionResponse> > response, Lead evaluationCtx)
                {
                    // If we DONT have a response, do some IO to get the response we need.
                    // Else we already have a predefined response for this action, so we dont need to do any IO, and just
                    // receive the predefined response
                    if (response.IsNone)
                    {
                        Console.WriteLine(action.MessageText);
                        action.MarkAsActioned(Ok(action.MessageText), Participant.User, UtcDateTime.Now, evaluationCtx);

                        var text = Console.ReadLine();
                        OnAwaitingResponse(action, workflow, Some(Ok((ActionResponse) new ReceiveMessageResponseActionResponse(new ReceiveMessageResponse("", "", text)))), evaluationCtx);
                    }
                    else
                    {
                        action.MarkAsActioned(Ok(action.MessageText), Participant.User, UtcDateTime.Now, evaluationCtx);
                        OnAwaitingResponse(action, workflow, response, evaluationCtx);
                    }
                }
                protected override void OnAwaitingAction(IAction_ action, Application workflow, Opt <Result <ActionResponse> > response, Lead evaluationCtx)
                {
                    var action_ = (VerifyBankAccountAction)workflow.Action;

                    if (action_.IsInCreateVerificationRequestFlow)
                    {
                        // extract the info we need to send to the Bank Account Verification service
                        var lead            = evaluationCtx;
                        var appValues       = workflow.Result;
                        var idNo            = appValues.ContainsKey("CustomerIdNumber") ? appValues["CustomerIdNumber"].ValOr("") : lead.IdNumber.ValOr("");  appValues["CustomerIdNumber"].ValOr("");
                        var surname         = appValues.ContainsKey("CustomerSurname") ? appValues["CustomerSurname"].ValOr("") : lead.Surname.ValOr("");  appValues["CustomerSurname"].ValOr("");
                        var bankName        = appValues["BankName"].ValOr("");
                        var bankAccountType = appValues["BankAccountType"].ValOr("");
                        var bankAccountNo   = appValues["BankAccountNo"].ValOr("");

                        // use the predefined JobId, OR hit the WebAPI to create the bank account verification request, and record the JobId, to be used later.
                        var verificationResult = response.Fold(o => o.Map(ActionResponse.AsBankAccountVerificationToken)
                                                               , () => _verificationSvc.CreateVerifyBankAccountRequest(idNo, surname, bankName, bankAccountType, bankAccountNo));

                        action_.MarkAsActioned_CreateVerificationRequest(Ok($"CreateVerifyBankAccountRequest('{idNo}', '{surname}', '{bankName}', '{bankAccountType}', '{bankAccountNo}')"), Participant.ExternalSystem, UtcDateTime.Now);
                        action_.ReceiveResponse_CreateVerificationRequest(verificationResult, UtcDateTime.Now);
                    }
                    else
                    {
                        // extract the info we need to send to the Bank Account Verification service.
                        // It is implied that if we are in the "check verification" flow, that the RequestToken is there and is valid.
                        var requestToken = action_.CreateVerificationResponse.Val.OkVal;

                        // use the predefined Status, OR hit the WebAPI to check the status of the bank account verification
                        // request, using the jobId that we got back previously.
                        var checkResult = response.Fold(o => o.Map(ActionResponse.AsBankAccountVerificationStatus)
                                                        , () => _verificationSvc.CheckVerifyBankAccountRequest(requestToken));

                        action_.MarkAsActioned_CheckVerificationRequest(Ok($"CheckVerifyBankAccountRequest('{requestToken.JobId}')"), Participant.ExternalSystem, UtcDateTime.Now);
                        action_.ReceiveResponse_CheckVerificationRequest(checkResult, UtcDateTime.Now);
                    }
                }
Exemplo n.º 10
0
 protected abstract void OnAwaitingResponse(IAction_ action, TWorkflow workflow, Opt <Result <ActionResponse> > response, TEvalCtx evaluationCtx);
 protected override void OnAwaitingResponse(IAction_ action, Application workflow, Opt <Result <ActionResponse> > response, Lead evaluationCtx)
 {
     throw new Exception("VerifyBankAccountAction receives its response as part of OnAwaitingAction.");
 }
 protected override void OnAwaitingResponse(IAction_ action, Application workflow, Opt <Result <ActionResponse> > response, Lead evaluationCtx)
 {
     throw new Exception("LoadRecommendedProductsAction receives its response as part of OnAwaitingAction.");
 }
 protected override void OnAwaitingResponse(IAction_ action, Application workflow, Opt <Result <ActionResponse> > response, Lead evaluationCtx)
 {
     throw new Exception("MessageAction does not accept any responses.  It only sends messages (fire and forget).");
 }
 protected override void OnAwaitingAction(IAction_ action, Application workflow, Opt <Result <ActionResponse> > response, Lead evaluationCtx)
 {
     Console.WriteLine(action.MessageText);
     action.MarkAsActioned(Ok(action.MessageText), Participant.User, UtcDateTime.Now, evaluationCtx);
 }
Exemplo n.º 15
0
            protected override void OnAwaitingAction(IAction_ action, Application workflow, Opt <Result <ActionResponse> > response, Lead evaluationCtx)
            {
                var sendResult = _messageSvc.SendMessage(action.MessageText, workflow.MobileNo).Map(_ => action.MessageText);

                action.MarkAsActioned(sendResult, Participant.User, UtcDateTime.Now, evaluationCtx);
            }