示例#1
0
            public async Task <IHttpActionResult> Post()
            {
                try
                {
                    Console.WriteLine("omadNotif");
                    var bot        = Bot.Api;
                    var botManager = new KntuBotManager();
                    var notifRoute = botManager.GetNotifRoute();
                    if (notifRoute != null)
                    {
                        //منوی زمان مسیر
                        var setRouteMenu = new ReplyKeyboardMarkup()
                        {
                            Keyboard = new[]
                            {
                                new[] { new KeyboardButton("تنظیمات اعلان‌ها") },
                                new[] { new KeyboardButton("انتخاب مسیر"), new KeyboardButton("تماس با پشتیبانی") },
                            },
                            OneTimeKeyboard = true,
                            ResizeKeyboard  = true
                        };

                        Console.WriteLine(notifRoute.StationRouteId);
                        var times     = botManager.GetRouteTimesByStId(notifRoute.StationRouteId);
                        var routeName = botManager.GetStationName(notifRoute.StationRouteId);
                        var items     = new Dictionary <string, string>();
                        foreach (var routeTimese in times)
                        {
                            items.Add(routeTimese.Count + " نفر ساعت " + routeTimese.Time.ToString("HH:mm"),
                                      routeTimese.Time.ToString("HH:mm"));
                        }
                        var inlineKeyboardMarkup = InlineKeyboardMarkupMaker(items);
                        var timemsg = string.Format(
                            messages.ResourceManager.GetString("NotifString"), routeName);
                        Console.WriteLine(timemsg);
                        var chatIds = botManager.GetNotifiChatIds(notifRoute.StationRouteId);
                        Console.WriteLine(chatIds.Count);
                        foreach (var userchatId in chatIds)
                        {
                            try
                            {
                                bot.SendTextMessageAsync(userchatId, timemsg, ParseMode.Default, false, false, 0,
                                                         inlineKeyboardMarkup).Wait();
                                bot.SendTextMessageAsync(userchatId, "👇👇👇👇تنظیمات اعلان ها برای مسیر",
                                                         ParseMode.Default, false, false, 0, setRouteMenu).Wait();
                            }
                            catch (Exception ie)
                            {
                                Console.WriteLine(userchatId + " " + ie.Message);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                    {
                        Console.WriteLine(e.Message + " - " + e.InnerException.Message);
                    }
                    else
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                return(Ok());
            }