/// <summary>
        /// Generates a response for client input sentence.
        /// </summary>
        /// <param name="dataFromClient"></param>
        /// <returns>Response generated by AIML Bot engine</returns>
        protected string ProcessRequestResponse(string dataFromClient)
        {
            BotUser user = Server.DefaultUser;
            dynamic js = JsonConvert.DeserializeObject <dynamic>(dataFromClient);
            string  userid = string.Empty, question = string.Empty;

            if (js != null && js.userid != null)
            {
                userid = js.userid.ToString();
                if (Server.Users.ContainsKey(userid))
                {
                    user = Server.Users[userid];
                }
                else
                {
                    user = new BotUser(Guid.Parse(userid), Server.ActiveBot);
                    Server.Users[userid] = user;
                }

                question = js.question.ToString();
            }

            WebhooksHelper.PreResponseHook(question, user);
            Result res               = Server.ActiveBot.Chat(new Request(question, user, Server.ActiveBot));
            string responseStatement = SkillsRepository.Instance.ProcessSkills(res.Output);

            WebhooksHelper.PostResponseHook(question, responseStatement, user);


            return(responseStatement);
        }
Exemplo n.º 2
0
        public void TestUnmarshalSuccess()
        {
            var store = InMemorySecretKeyStore.Instance;

            var marshaller = DefaultImpl.DefaultMarshaller.Instance;

            var helper = new WebhooksHelper(marshaller, store);

            store.StoreSecretKey(KeyId, SecretKey);

            // the signature is created with Unix line breaks, so replace any Windows line break
            var bodyStream = GoodVersionJson.Replace("\r\n", "\n");
            List <RequestHeader> requestHeaders = new List <RequestHeader> {
                new RequestHeader(SignatureHeader, SignatureGood),
                new RequestHeader(KeyIdHeader, KeyId)
            };

            WebhooksEvent anEvent = helper.Unmarshal(bodyStream, requestHeaders);

            Assert.AreEqual("v1", anEvent.ApiVersion);
            Assert.AreEqual("8ee793f6-4553-4749-85dc-f2ef095c5ab0", anEvent.Id);
            Assert.AreEqual("2017-02-02T11:24:14.040+0100", anEvent.Created);
            Assert.AreEqual("20000", anEvent.MerchantId);
            Assert.AreEqual("payment.paid", anEvent.Type);

            Assert.Null(anEvent.Refund);
            Assert.Null(anEvent.Payout);
            Assert.Null(anEvent.Token);

            Assert.NotNull(anEvent.Payment);
            Assert.AreEqual("00000200000143570012", anEvent.Payment.Id);
            Assert.NotNull(anEvent.Payment.PaymentOutput);
            Assert.NotNull(anEvent.Payment.PaymentOutput.AmountOfMoney);
            Assert.AreEqual(1000L, anEvent.Payment.PaymentOutput.AmountOfMoney.Amount);
            Assert.AreEqual("EUR", anEvent.Payment.PaymentOutput.AmountOfMoney.CurrencyCode);
            Assert.NotNull(anEvent.Payment.PaymentOutput.References);
            Assert.AreEqual("200001681810", anEvent.Payment.PaymentOutput.References.PaymentReference);
            Assert.AreEqual("bankTransfer", anEvent.Payment.PaymentOutput.PaymentMethod);

            Assert.Null(anEvent.Payment.PaymentOutput.CardPaymentMethodSpecificOutput);
            Assert.Null(anEvent.Payment.PaymentOutput.CashPaymentMethodSpecificOutput);
            Assert.Null(anEvent.Payment.PaymentOutput.DirectDebitPaymentMethodSpecificOutput);
            Assert.Null(anEvent.Payment.PaymentOutput.InvoicePaymentMethodSpecificOutput);
            Assert.Null(anEvent.Payment.PaymentOutput.RedirectPaymentMethodSpecificOutput);
            Assert.Null(anEvent.Payment.PaymentOutput.SepaDirectDebitPaymentMethodSpecificOutput);
            Assert.NotNull(anEvent.Payment.PaymentOutput.BankTransferPaymentMethodSpecificOutput);
            Assert.AreEqual(11, anEvent.Payment.PaymentOutput.BankTransferPaymentMethodSpecificOutput.PaymentProductId);

            Assert.AreEqual("PAID", anEvent.Payment.Status);
            Assert.NotNull(anEvent.Payment.StatusOutput);
            Assert.AreEqual(false, anEvent.Payment.StatusOutput.IsCancellable);
            Assert.AreEqual("COMPLETED", anEvent.Payment.StatusOutput.StatusCategory);
            Assert.AreEqual(1000, anEvent.Payment.StatusOutput.StatusCode);
            Assert.AreEqual("20170202112414", anEvent.Payment.StatusOutput.StatusCodeChangeDateTime);
            Assert.AreEqual(true, anEvent.Payment.StatusOutput.IsAuthorized);
        }
Exemplo n.º 3
0
        public void TestUnmarshalNoSecretKeyAvailable()
        {
            var store      = InMemorySecretKeyStore.Instance;
            var marshaller = DefaultImpl.DefaultMarshaller.Instance;
            var helper     = new WebhooksHelper(marshaller, store);

            Assert.Throws(typeof(SecretKeyNotAvailableException), () => helper.Unmarshal(GoodVersionJson, new List <RequestHeader> {
                new RequestHeader(KeyIdHeader, KeyId), new RequestHeader(SignatureHeader, SignatureGood)
            }));
        }
Exemplo n.º 4
0
        public void TestUnmarshalMissingHeaders()
        {
            var store      = InMemorySecretKeyStore.Instance;
            var marshaller = DefaultImpl.DefaultMarshaller.Instance;
            var helper     = new WebhooksHelper(marshaller, store);

            store.StoreSecretKey(KeyId, SecretKey);
            Assert.Throws(typeof(SignatureValidationException), () => helper.Unmarshal(GoodVersionJson, new List <RequestHeader> {
            }));
        }
Exemplo n.º 5
0
        public void TestUnmarshalApiVersionMismatch()
        {
            var store = InMemorySecretKeyStore.Instance;

            store.StoreSecretKey(KeyId, SecretKey);
            var marshaller = DefaultImpl.DefaultMarshaller.Instance;
            var helper     = new WebhooksHelper(marshaller, store);

            // the signature is created with Unix line breaks, so replace any Windows line break
            var bodyStream = BadVersionJson.Replace("\r\n", "\n");

            Assert.Throws(typeof(ApiVersionMismatchException), () => helper.Unmarshal(bodyStream, new List <RequestHeader> {
                new RequestHeader(KeyIdHeader, KeyId), new RequestHeader(SignatureHeader, SignatureWrongApi)
            }));
        }