Ejemplo n.º 1
0
        public Task ChatBot(string authToken, string AuctionId, string phone)
        {
            try
            {
                phone = WebClientHelper.HandlePhoneFormat(phone);

                UserAuctionId[phone] = AuctionId;
                UserAuthToken[phone] = authToken;

                string APIUrl = $"checkout/cars/getauctiondetails?auctionid={AuctionId}&authtoken={authToken}&source = androidphone";

                var result = WebClientHelper.Consume(APIBaseUrl, HttpMethod.Get, APIUrl);

                UserAuctionDetails[phone] = JsonSerializer.Deserialize <AuctionDetailsVM>(result.Content.ReadAsStringAsync().Result);


                UserWatsonResult[phone] = _watsonHelper.Consume(phone, "hello", true);

                string message   = UserWatsonResult[phone].Output.Generic[0].Text.Replace("{SOPCode}", UserAuctionDetails[phone].SOPNumber).Replace("{TotalAmount}", UserAuctionDetails[phone].TotalAmount.ToString());
                var    send      = false;
                string carOption = "{0} lot# {1} with the price of {2} {3} ";
                for (int i = 0; i < UserAuctionDetails[phone].Cars.Count; i++)
                {
                    send = true;
                    var car = UserAuctionDetails[phone].Cars[i];
                    message += Environment.NewLine + (i + 1) + "-" + string.Format(carOption, car.makeEn + " " + car.modelEn, car.AuctionInfo.lot, car.AuctionInfo.currencyEn, car.AuctionInfo.currentPrice);
                }
                if (send)
                {
                    WebHookHelper.sendTXTMsg(phone, message);
                }

                message = string.Empty;
                if (!UserCars.ContainsKey(phone))
                {
                    UserCars[phone] = new List <CarVM>(UserAuctionDetails[phone].Cars);
                }
                var cars      = UserCars[phone];
                var carsCount = cars.Count;
                for (int i = 0; i < carsCount; i++)
                {
                    var car = cars[i];
                    if (car.BidderHyazaOrigin == string.Empty && car.RequireSelectHyaza == 1)
                    {
                        UserCarNum[phone] = i;
                        message           = _watsonHelper.Consume(phone).Output.Generic[0].Text;
                        message           = message.Replace("{CarNum}", car.makeEn + " " + car.modelEn).Replace("{number}", car.AuctionInfo.lot.ToString()).
                                            Replace("{currency}", car.AuctionInfo.currencyEn).Replace("{price}", car.AuctionInfo.currentPrice.ToString());

                        message += Environment.NewLine + "1- Abu Dhabi" + Environment.NewLine + "2- Dubai" + Environment.NewLine + "3- Sharja" + Environment.NewLine + "4- Ras Al Khaimah" +
                                   Environment.NewLine + "5- Fujairah" + Environment.NewLine + "6- Ajman" + Environment.NewLine + "7- Umm Al Quwian";

                        UserCars[phone].Remove(car);
                        _sessionsManager.UpdateSessionStep(phone);

                        break;
                    }
                    else if (car.DeliveryStatus != 1 && car.CheckOutInfo.HasSourceLocation == 1 && car.CheckOutInfo.AllowDeliveryRequest == 1)
                    {
                        UserCarNum[phone] = i;
                        _sessionsManager.UpdateSessionStep(phone, 3);
                        message = _watsonHelper.Consume(phone, "1").Output.Generic[0].Text.Replace("{CarNum}", car.makeEn + " " + car.modelEn).Replace("{lot}", car.AuctionInfo.lot.ToString());
                        UserCars[phone].Remove(car);
                        break;
                    }
                }
                WebHookHelper.sendTXTMsg(phone, message);
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
            }

            return(null);
        }