public TextMessage Process(TextMessage message, ref string userContext, out string intentName)
        {
            ApiAiSDK.AIConfiguration config;
            switch (message.Language)
            {
            case Language.English:
                config = new ApiAiSDK.AIConfiguration(tocken, ApiAiSDK.SupportedLanguage.English);
                break;

            case Language.Russian:
                config = new ApiAiSDK.AIConfiguration(tocken, ApiAiSDK.SupportedLanguage.Russian);
                break;

            default:
                throw new Exceptions.InvalidMessageException(message.Id, "Invalid Language: " + message.Language.ToString());
            }
            apiAi = new ApiAiSDK.ApiAi(config);
            ApiAiSDK.Model.AIResponse aiResponse;
            ApiAiSDK.RequestExtras    requestExtras;
            if (!string.IsNullOrWhiteSpace(userContext))
            {
                try
                {
                    requestExtras = JsonConvert.DeserializeObject <ApiAiSDK.RequestExtras>(userContext);
                }
                catch
                {
                    requestExtras = new ApiAiSDK.RequestExtras();
                }
            }
            else
            {
                requestExtras = new ApiAiSDK.RequestExtras();
            }
            aiResponse = apiAi.TextRequest(message.Text, requestExtras);
            if (aiResponse == null)
            {
                throw new InvalidMessageException(message.Id, "invalid ApiAiReapone");
            }
            requestExtras.Contexts = new List <ApiAiSDK.Model.AIContext>();
            foreach (var outContext in aiResponse.Result.Contexts)
            {
                ApiAiSDK.Model.AIContext aIContext = new ApiAiSDK.Model.AIContext
                {
                    Parameters = new Dictionary <string, string>(),
                    Lifespan   = outContext.Lifespan,
                    Name       = outContext.Name
                };
                foreach (var param in outContext.Parameters)
                {
                    string key = param.Key;
                    string value;
                    if (param.Value != null)
                    {
                        value = param.Value.ToString();
                        aIContext.Parameters.Add(key, value);
                    }
                }
                requestExtras.Contexts.Add(aIContext);
            }
            userContext = JsonConvert.SerializeObject(requestExtras);
            intentName  = aiResponse.Result.Action;
            if (string.IsNullOrWhiteSpace(intentName) || string.IsNullOrWhiteSpace(aiResponse.Result.Fulfillment.Speech))
            {
                intentName = "input.unknown";
            }
            else if (intentName != "input.unknown")
            {
                message.Text = aiResponse.Result.Fulfillment.Speech;
            }
            return(message);
        }
            public override async Task <TextProcessingServiceRespone> Invork(TextRequest textRequest)
            {
                var time = DateTime.Now;
                TextProcessingServiceRespone textProcessingServiceRespone = new TextProcessingServiceRespone()
                {
                    Id = textRequest.Id.Value
                };

                ApiAiSDK.Model.AIResponse aiResponse;
                ApiAiSDK.RequestExtras    requestExtras;
                DbClient db      = new DbClient();
                var      context = await db.GetContext(textRequest.Id.Value);

                if (context != null && !string.IsNullOrWhiteSpace(context.IntentContext))
                {
                    requestExtras = JsonConvert.DeserializeObject <ApiAiSDK.RequestExtras>(context.IntentContext);
                }
                else
                {
                    requestExtras = new ApiAiSDK.RequestExtras();
                }

                aiResponse = apiAi.TextRequest(textRequest.TextData, requestExtras);

                //TODO: Update Exceptions
                if (aiResponse == null)
                {
                    throw new Exception("Invalid output message");
                }

                requestExtras.Contexts = new List <ApiAiSDK.Model.AIContext>();
                foreach (var outContext in aiResponse.Result.Contexts)
                {
                    ApiAiSDK.Model.AIContext aIContext = new ApiAiSDK.Model.AIContext
                    {
                        Parameters = new Dictionary <string, string>(),
                        Lifespan   = outContext.Lifespan,
                        Name       = outContext.Name
                    };
                    foreach (var param in outContext.Parameters)
                    {
                        string key = param.Key;
                        string value;
                        if (param.Value != null)
                        {
                            value = param.Value.ToString();
                            aIContext.Parameters.Add(key, value);
                        }
                    }
                    requestExtras.Contexts.Add(aIContext);
                }
                if (requestExtras == null)
                {
                    requestExtras = new ApiAiSDK.RequestExtras();
                }
                if (context == null)
                {
                    context = new DbModels.UserContext()
                    {
                        Id = textRequest.Id.Value, IntentContext = "", TalkContext = "", TalkReplicCount = 0
                    }
                }
                ;
                context.IntentContext = JsonConvert.SerializeObject(requestExtras);
                await db.AddOrUpdateContext(context);

                requestExtras = null;
                db.Dispose();
                textProcessingServiceRespone.TextData = aiResponse.Result.Fulfillment.Speech;


                if (!string.IsNullOrWhiteSpace(aiResponse.Result.Action))
                {
                    foreach (var parametr in aiResponse.Result.Parameters)
                    {
                        if (!string.IsNullOrWhiteSpace(parametr.Value.ToString()))
                        {
                            textProcessingServiceRespone.Entities.Add(parametr.Key, parametr.Value.ToString());
                            if (parametr.Value.ToString().Contains("dress"))
                            {
                                textProcessingServiceRespone.WayPoint = "adidas";
                            }
                            else if (parametr.Value.ToString().Contains("shop"))
                            {
                                textProcessingServiceRespone.WayPoint = "adidas";
                            }
                            else if (parametr.Value.ToString().Contains("furniture"))
                            {
                                textProcessingServiceRespone.WayPoint = "adidas";
                            }
                            else if (parametr.Value.ToString().ToLower().Contains("ikea"))
                            {
                                textProcessingServiceRespone.WayPoint = "adidas";
                            }
                            else if (parametr.Value.ToString().ToLower().Contains("adidas"))
                            {
                                textProcessingServiceRespone.WayPoint = "adidas";
                            }
                        }
                    }
                    if (aiResponse.Result.Action == "navigation_shops")
                    {
                        textProcessingServiceRespone.WayPoint = "adidas";
                    }
                    if (aiResponse.Result.Action == "Cheese")
                    {
                        textProcessingServiceRespone.WayPoint = "cheese";
                    }
                    textProcessingServiceRespone.IntentName = aiResponse.Result.Action;
                }
                else
                {
                    textProcessingServiceRespone.IntentName = "none";
                }

                //DEBUG INFO
                #region DebugInfo
                if (SHOW_DEBUG_INFO)
                {
                    Console.WriteLine("Id: {0} | BOT PARAMS:", textRequest.Id.Value);
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine("Intent {0}", textProcessingServiceRespone.IntentName);
                    Console.WriteLine("\tName\t\t\t|Value");
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    foreach (var parametr in textProcessingServiceRespone.Entities)
                    {
                        Console.WriteLine("\t{0,-23} |{1}", parametr.Key, parametr.Value);
                    }
                    Console.WriteLine(textProcessingServiceRespone.WayPoint);
                    Console.ForegroundColor = ConsoleColor.Gray;

                    /*
                     * Console.WriteLine("User: "******"Masha: " + outputText);
                     * Console.ForegroundColor = ConsoleColor.DarkMagenta;
                     * Console.WriteLine("BOT CONTEXTS:");
                     * foreach (var context in aiResponse.Result.Contexts)
                     * {
                     *  Console.ForegroundColor = ConsoleColor.DarkCyan;
                     *  Console.WriteLine("## {0}", context.Name);
                     *  Console.ForegroundColor = ConsoleColor.Gray;
                     *  Console.WriteLine("\tName\t\t\t|Value");
                     *  Console.ForegroundColor = ConsoleColor.DarkGreen;
                     *  foreach (var parameter in context.Parameters)
                     *      Console.WriteLine("\t{0,-23} |{1}", parameter.Key, parameter.Value);
                     * }
                     * Console.ForegroundColor = ConsoleColor.Gray;
                     *
                     * Console.ForegroundColor = ConsoleColor.DarkMagenta;
                     * Console.WriteLine("BOT PARAMS:");
                     * Console.ForegroundColor = ConsoleColor.Gray;
                     * Console.WriteLine("\tName\t\t\t|Value");
                     * Console.ForegroundColor = ConsoleColor.DarkGreen;
                     * foreach (var parametr in aiResponse.Result.Parameters)
                     * {
                     *  Console.WriteLine("\t{0,-23} |{1}", parametr.Key, parametr.Value);
                     * }
                     * Console.ForegroundColor = ConsoleColor.Gray;
                     */
                }

                #endregion

                Log.LogInformation(textRequest.Id.Value, 0, this.GetType().ToString(), $"service end work in {(DateTime.Now - time).Milliseconds} ms");

                //Console.WriteLine("WayPoint: " + textProcessingServiceRespone.WayPoint);
                return(textProcessingServiceRespone);
            }
        }