Example #1
0
        private async Task <IActionResult> GetContact()
        {
            int Help_followerId = Argumetns[0]; // id пользователя которой создал заявку
            var follower        = FollowerFunction.GetFollower(Help_followerId);

            if (follower != null && follower.Telephone != null && follower.Telephone != "")
            {
                Contact contact = new Contact
                {
                    FirstName   = follower.FirstName,
                    PhoneNumber = follower.Telephone
                };

                await SendContact(contact);
            }

            if (follower != null && follower.UserName != null && follower.UserName != "")
            {
                await SendUrl(BotMessage.HrefUrl("https://t.me/" + follower.UserName, follower.UserName));

                return(OkResult);
            }

            else
            {
                return(base.OkResult);
            }
        }
Example #2
0
        public override InlineQueryResult[] GetResult()
        {
            var Address = FollowerFunction.FollowerAddress(FollowerId).Take(MaxResult).ToList();

            InlineQueryResultLocation[] location = new InlineQueryResultLocation[Address.Count];
            InlineQueryResult[]         result   = new InlineQueryResult[Address.Count];

            int i = 0;

            foreach (var adr in Address)
            {
                location[i]       = new InlineQueryResultLocation();
                location[i].Id    = adr.Id.ToString();
                location[i].Title = adr.House.Street.Name + " " + adr.House.Number;
                result[i]         = location[i];

                if (adr.House != null && adr.House.Latitude != null && adr.House.Longitude != null)
                {
                    location[i].Longitude = Convert.ToSingle(adr.House.Longitude);
                    location[i].Latitude  = Convert.ToSingle(adr.House.Latitude);
                }

                else
                {
                    location[i].Longitude = 0;
                    location[i].Latitude  = 0;
                }

                i++;
            }

            return(result);
        }
        public override InlineQueryResult[] GetResult()
        {
            var Orders = FollowerFunction.FollowerOrder(FollowerId).Take(MaxResult).ToList();

            InputTextMessageContent[]  textcontent = new InputTextMessageContent[Orders.Count];
            InlineQueryResultArticle[] article     = new InlineQueryResultArticle[Orders.Count];
            InlineQueryResult[]        result      = new InlineQueryResult[Orders.Count];

            int i = 0;

            foreach (var order in Orders)
            {
                textcontent[i]                       = new InputTextMessageContent();
                textcontent[i].ParseMode             = Telegram.Bot.Types.Enums.ParseMode.Html;
                textcontent[i].DisableWebPagePreview = true;
                textcontent[i].MessageText           = "/order" + order.Number.ToString();

                article[i]             = new InlineQueryResultArticle();
                article[i].HideUrl     = false;
                article[i].Id          = order.Id.ToString();
                article[i].Title       = "Заказ №" + order.Number.ToString();
                article[i].Description = "Время:" + order.DateAdd.ToString() + BotMessage.NewLine();

                article[i].ThumbUrl            = "https://cdn2.iconfinder.com/data/icons/shop-payment-vol-6/128/shop-19-256.png";
                article[i].InputMessageContent = textcontent[i];

                result[i] = new InlineQueryResult();
                result[i] = article[i];

                i++;
            }

            return(result);
        }
        private async Task <IActionResult> SendNewNotifi()
        {
            var Followers = FollowerFunction.GetFollowerList();

            var Notifi = NotificationFunction.GetNotification(NotifiId);

            if (Notifi != null && !Notifi.Sended)
            {
                Notifi = NotificationFunction.NotificationIsSended(NotifiId);

                await SendNotifiEditor(Notifi);

                foreach (var follower in Followers)
                {
                    await SendMessage(follower.ChatId, new BotMessage { TextMessage = Notifi.Text });

                    //пауза три секунды. Если начать отправлять все сразу телегам будет выдавать ошибку.

                    System.Threading.Thread.Sleep(300);
                }
            }

            if (Notifi != null && Notifi.Sended)
            {
                await AnswerCallback("Рассылка уже отправлена", true);
            }

            if (Notifi == null)
            {
                await AnswerCallback("Данные отсутствуют", true);
            }

            return(OkResult);
        }
Example #5
0
        private async Task <IActionResult> AddOperatorRule()
        {
            int followerid = Argumetns[0];
            var admin      = AdminFunction.FindAdmin(followerid);

            var followerinfo = FollowerFunction.GetFollower(followerid);

            if (followerinfo.ChatId == BotInfo.OwnerChatId)
            {
                await AnswerCallback("Владелец бота не может обладать правами оператора", true);

                return(OkResult);
            }

            //даем пользователю права оператора. И если есть общий чат то даем пользователю приглашение
            if (admin == null && followerinfo != null && followerinfo.ChatId != BotInfo.ChatId)
            {
                var key = AdminFunction.InsertAdminKey(GeneralFunction.GenerateHash());

                admin = AdminFunction.InsertAdmin(followerid, key);

                if (admin != null && admin.Follower != null)
                {
                    await AnswerCallback("Сохранено!", true);

                    await base.SendMessage(admin.Follower.ChatId,
                                           new BotMessage { TextMessage = "Вы получили права оператора. Нажмите сюда /admin" });

                    if (BotInfo.Configuration != null && BotInfo.Configuration.PrivateGroupChatId != null && BotInfo.Configuration.PrivateGroupChatId != "")
                    {
                        await base.SendMessage(admin.Follower.ChatId,
                                               new BotMessage {
                            TextMessage = "Что бы подключиться в общий чат, перейдите по ссылке "
                                          + await CreateInviteToGroupChat(Convert.ToInt64(BotInfo.Configuration.PrivateGroupChatId), admin.Follower.ChatId)
                        });
                    }
                }


                return(OkResult);
            }


            if (admin != null)
            {
                await AnswerCallback("Этот пользователь уже обладает правами оператора", true);

                return(OkResult);
            }

            else
            {
                return(OkResult);
            }
        }
        /// <summary>
        /// Добавить UserName для пользователя
        /// </summary>
        /// <returns></returns>
        private async Task <IActionResult> AddUserName()
        {
            //Пользователь написал username в настройках Telegram  и нажал на кнопку
            if (Update.CallbackQuery != null && Update.CallbackQuery.From != null &&
                FollowerFunction.AddUserName(FollowerId, Update.CallbackQuery.From.Username) != null)
            {
                return(await SendOrderTemp());
            }

            else // Не написал
            {
                return(await SendUserNameAddedFaq());
            }
        }
        public override Stream BuildReport()
        {
            FollowerWorksheet = Excel.Workbook.Worksheets.Add("Список Пользователей");

            FollowerList = FollowerFunction.GetFollowerList();

            // шапка
            FollowerWorksheet.Cells[1, 1].Value = "Имя";
            FollowerWorksheet.Cells[1, 2].Value = "Фамилия";
            FollowerWorksheet.Cells[1, 3].Value = "UserName";
            FollowerWorksheet.Cells[1, 4].Value = "Телефон";
            FollowerWorksheet.Cells[1, 5].Value = "Дата регистрации";
            FollowerWorksheet.Cells[1, 6].Value = "Заблокирован";

            int row = 2;

            foreach (var follower in FollowerList)
            {
                //имя
                FollowerWorksheet.Cells[row, 1].Value = follower.FirstName;

                //фамилия
                FollowerWorksheet.Cells[row, 2].Value = follower.LastName;


                //username
                FollowerWorksheet.Cells[row, 3].Value = follower.UserName;

                //телефон
                FollowerWorksheet.Cells[row, 4].Value = follower.Telephone;


                FollowerWorksheet.Cells[row, 5].Value = follower.DateAdd.ToString();

                if (follower.Blocked)
                {
                    FollowerWorksheet.Cells[row, 6].Value = "Да";
                }

                else
                {
                    FollowerWorksheet.Cells[row, 6].Value = "Нет";
                }


                row++;
            }

            return(new MemoryStream(Excel.GetAsByteArray()));
        }
Example #8
0
        /// <summary>
        /// Добавить номер телефона клиента
        /// </summary>
        /// <returns></returns>
        private async Task <IActionResult> InsertTelephoneNumber()
        {
            BotMessage = new OrderTempMessage(base.FollowerId, BotInfo.Id);
            if (FollowerFunction.AddTelephoneNumber(FollowerId, Update.Message.Contact.PhoneNumber) != null)
            {
                await SendMessage(BotMessage.BuildMsg());
            }

            else
            {
                await SendMessage(new BotMessage { TextMessage = "Ошибка!" });
            }

            return(OkResult);
        }
        private async Task <IActionResult> SaveHelpDesk(int HelpDeskId)
        {
            if (!FollowerFunction.IsBlocked(FollowerId))
            {
                var Help = HelpDeskFunction.SaveHelpDesk(HelpDeskId);

                BotMessage = new HelpDeskEditorMessage(Help);
                await EditMessage(BotMessage.BuildMsg());

                AdminHelpDeskMessage adminHelpDesk = new AdminHelpDeskMessage(Help);
                await base.SendMessageAllBotEmployeess(adminHelpDesk.BuildMsg());
            }

            else
            {
                await SendMessage(new BotMessage { TextMessage = "Пользователь заблокирован!" });
            }

            return(OkResult);
        }
Example #10
0
        public override BotMessage BuildMsg()
        {
            if (Follower == null)
            {
                Follower = FollowerFunction.GetFollower(FollowerId);
            }

            if (Follower != null)
            {
                string status = "";

                string IsOperator = "";

                if (Follower.Blocked)
                {
                    status = Italic("Заблокирован");
                }

                if (Follower.Admin != null && Follower.Admin.Count > 0)
                {
                    IsOperator = Bold("Роль: ") + "Оператор системы | удалить  /removeoperator" + Follower.Admin.LastOrDefault().Id.ToString();
                }

                base.TextMessage = Bold("Имя: ") + Follower.FirstName + NewLine() +
                                   Bold("Фамилия: ") + Follower.LastName + NewLine() +
                                   Bold("Профиль:") + HrefUrl("https://t.me/" + Follower.UserName, Follower.UserName) + NewLine() +
                                   Bold("Дата регистрации:") + Follower.DateAdd.ToString() + NewLine() +
                                   Bold("Телефон:") + Follower.Telephone + NewLine() + IsOperator + NewLine() + status;


                base.MessageReplyMarkup = SetInline();

                return(this);
            }

            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Сохрнанить заказ. Перенести все данные из корзины.
        /// </summary>
        /// <returns></returns>
        private async Task <IActionResult> OrderSave()
        {
            Orders new_order = null;
            bool   blocked   = false;

            OrderFunction = new OrderFunction();

            ConfigurationBot = base.GetConfigurationBot(BotInfo.Id);

            blocked = FollowerFunction.IsBlocked(FollowerId);

            if (blocked)
            {
                await AnswerCallback("Вы заблокированы администратором системы!", true);
            }

            // если в настройках бота указано время работы магазина, то проверяем подходит ли текщее время
            //под это правило. Если подходит то офрмляем заказ
            if (!blocked && ConfigurationBot.StartTime != null &&
                ConfigurationBot.EndTime != null && ConfigurationBot.StartTime.Value.Hours <=
                DateTime.Now.Hour && ConfigurationBot.StartTime.Value <= DateTime.Now.TimeOfDay &&
                ConfigurationBot.EndTime.Value > DateTime.Now.TimeOfDay)
            {
                new_order = OrderFunction.CreateOrder(FollowerId, BotInfo);
            }


            //Время работы магазина не указано.
            else if (!blocked && ConfigurationBot.EndTime == null && ConfigurationBot.StartTime == null)
            {
                new_order = OrderFunction.CreateOrder(FollowerId, BotInfo);
            }

            else
            {
                await AnswerCallback("Мы обрабатываем заказы только в период с " + ConfigurationBot.StartTime.ToString() +
                                     " и по " + ConfigurationBot.EndTime.ToString(), true);
            }

            if (new_order != null && new_order.Invoice != null)
            {
                BotMessage = new InvoiceViewMessage(new_order.Invoice, new_order.Id);
                await EditMessage(BotMessage.BuildMsg());
            }

            if (new_order != null && new_order.Invoice == null)
            {
                BotMessage = new OrderViewMessage(new_order);
                await EditMessage(BotMessage.BuildMsg());
            }

            //то отправляем уведомление о новом заказке Админам
            if (new_order != null)
            {
                BotMessage = new AdminOrderMessage(new_order);

                var message = BotMessage.BuildMsg();

                await SendMessageAllBotEmployeess(message);
            }


            OrderFunction.Dispose();

            return(OkResult);
        }
        /// <summary>
        /// Пользователь выбрал методо оплаты
        /// </summary>
        /// <returns></returns>
        private async Task <IActionResult> SelectPaymentMethod()
        {
            OrderFunction = new OrderFunction();

            int PaymentTypeId = 0;

            bool TestConnection = false;

            bool ExistUserName = false;

            bool ExistTelephone = false;

            OrderTemp orderTemp = null;

            ConfigurationBot = GetConfigurationBot(BotInfo.Id);

            if (Argumetns.Count > 0)
            {
                PaymentTypeId = Argumetns[0];

                TestConnection = OrderFunction.PaymentTypeTestConnection(PaymentTypeId);
            }

            if (TestConnection == false)
            {
                await AnswerCallback("Ошибка. Данный способ оплаты недоступен!", true);

                OrderFunction.Dispose();
                return(OkResult);
            }

            if (TestConnection)
            {
                orderTemp = OrderFunction.AddPaymentMethodToOrderTmp(FollowerId, BotInfo.Id, PaymentTypeId);
                OrderFunction.Dispose();
            }


            //Данные о выбраном способоне оплаты успешно занесены в БД.
            //Если в настройках бота включена верификация по номеру телефона, то проверяем указан ли номер телефона у этого пользователя
            //Если не указан то просим указать
            ExistTelephone = FollowerFunction.ExistTelephone(FollowerId);
            if (orderTemp != null && ConfigurationBot != null && ConfigurationBot.VerifyTelephone && !ExistTelephone)
            {
                BotMessage = new RequestPhoneNumberMessage();
                await SendMessage(BotMessage.BuildMsg());
            }
            //телефон указан
            if (orderTemp != null && ConfigurationBot != null && ConfigurationBot.VerifyTelephone && ExistTelephone)
            {
                return(await SendOrderTemp());
            }


            //Данные о выбраном способоне оплаты успешно занесены в БД.
            //Если в настройках бота верификация по телефону отключена, проверяем указан ли у пользователя UserName
            ExistUserName = FollowerFunction.ExistUserName(FollowerId);
            if (orderTemp != null && ConfigurationBot != null && !ConfigurationBot.VerifyTelephone && !ExistUserName)
            {
                return(await SendUserNameAddedFaq());
            }

            //UserName указан
            if (orderTemp != null && ConfigurationBot != null && !ConfigurationBot.VerifyTelephone && ExistUserName)
            {
                return(await SendOrderTemp());
            }


            return(OkResult);
        }