Beispiel #1
0
        private void sendUserBetsTelegram(Activity activity)
        {
            ApplicationUser curUser = getUserFromActivity(activity);

            var connector = new ConnectorClient(new Uri(activity.ServiceUrl));

            if (curUser != null)
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                Activity             reply = activity.CreateReply("");
                DateTime             curDt = DateTime.UtcNow + MvcApplication.utcMoscowShift;
                List <Bet>           bets  = getBetsByUserDay(curUser, curDt);
                TeleBot              tb    = new TeleBot();
                InlineKeyboardMarkup kb    = tb.createKeabordFromBets(bets, true);
                string jsonKb = JsonConvert.SerializeObject(kb);
                string text   = "";
                if (bets.Count > 0)
                {
                    text = "Ставки на " + curDt.ToString("dd.MM.yyyy");
                }
                else
                {
                    text = "Открытых ставок на " + curDt.ToString("dd.MM.yyyy") + " нет";
                }

                reply.ChannelData = new TelegramChannelData()
                {
                    method     = "sendMessage",
                    parameters = new TelegramParameters()
                    {
                        text         = text,
                        parse_mode   = "Markdown",
                        reply_markup = jsonKb
                    }
                };
                connector.Conversations.ReplyToActivity(reply);
            }
        }
Beispiel #2
0
        private void basicTelegramReminder(ConversationStarter cs)
        {
            ApplicationUser curUser = cs.ApplicationUser;


            var userAccount = new ChannelAccount(cs.ToId, cs.ToName);
            var botAccount  = new ChannelAccount(cs.FromId, cs.FromName);
            var connector   = new ConnectorClient(new Uri(cs.ServiceUrl));

            Activity activity = new Activity();

            activity.Type         = ActivityTypes.Message;
            activity.From         = botAccount;
            activity.Recipient    = userAccount;
            activity.Conversation = new ConversationAccount(id: cs.ConversationId);
            activity.Id           = "1";
            string text = "Нужно сделать ставки!";

            DateTime             curDate = (DateTime.UtcNow + MvcApplication.utcMoscowShift).Date;
            List <Bet>           bets    = db.Bets.Where(b => b.ApplicationUser.UserName == curUser.UserName & b.Program.TvDate == curDate & !b.IsLocked).ToList();
            TeleBot              tb      = new TeleBot();
            InlineKeyboardMarkup kb      = tb.createKeabordFromBets(bets, true);
            string jsonKb = JsonConvert.SerializeObject(kb);

            activity.ChannelData = new TelegramChannelData()
            {
                method     = "sendMessage",
                parameters = new TelegramParameters()
                {
                    text         = text,
                    parse_mode   = "Markdown",
                    reply_markup = jsonKb
                }
            };
            connector.Conversations.SendToConversation(activity);
        }
Beispiel #3
0
        public void manualTeleSend(string userName, Activity mainActivity, List <Bet> allbets)
        {
            DateTime now                   = DateTime.UtcNow + MvcApplication.utcMoscowShift;
            string   allbetsstr            = "";// allbets.Count().ToString() + "; ";
            List <ConversationStarter> css = db.CSs.ToList();

            if (css.Count() > 0)
            {
                foreach (ConversationStarter cs in css)
                {
                    if (cs.ChannelId == "telegram" & cs.ApplicationUser.TelegramUserName == userName)
                    {
                        ApplicationUser curUser = cs.ApplicationUser;


                        var userAccount = new ChannelAccount(cs.ToId, cs.ToName);
                        var botAccount  = new ChannelAccount(cs.FromId, cs.FromName);

                        MicrosoftAppCredentials.TrustServiceUrl(cs.ServiceUrl, DateTime.UtcNow.AddDays(7));
                        var account   = new MicrosoftAppCredentials("ed8d437a-c850-4738-a15f-534457ad8716", "jYAUUmDx1zWwfv3L1BpmOeR");
                        var connector = new ConnectorClient(new Uri(cs.ServiceUrl), account);
                        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                        Activity activity = new Activity();
                        activity.From         = botAccount;
                        activity.Recipient    = userAccount;
                        activity.Conversation = new ConversationAccount(id: cs.ConversationId);
                        activity.Type         = ActivityTypes.Message;
                        activity.Id           = "1";

                        string  text            = "Нужно сделать ставки!";
                        TeleBot tb              = new TeleBot();
                        InlineKeyboardMarkup kb = tb.createKeabordFromBets(allbets, true);
                        string jsonKb           = JsonConvert.SerializeObject(kb);
                        activity.ChannelData = new TelegramChannelData()
                        {
                            method     = "sendMessage",
                            parameters = new TelegramParameters()
                            {
                                text         = text,
                                parse_mode   = "Markdown",
                                reply_markup = jsonKb
                            }
                        };

                        allbetsstr += activity.Recipient.Name.ToString() + "-" + activity.Recipient.Id.ToString() + ". ";
                        try
                        {
                            connector.Conversations.SendToConversation(activity);
                        }
                        catch (Exception ex)
                        {
                            if (cs.ApplicationUser.TelegramUserName == "amosendz")
                            {
                                allbetsstr = "The error is: " + ex.Message;
                                var      connector2 = new ConnectorClient(new Uri(mainActivity.ServiceUrl), account);
                                Activity reply      = mainActivity.CreateReply("");

                                reply.ChannelData = new TelegramChannelData()
                                {
                                    method     = "sendMessage",
                                    parameters = new TelegramParameters()
                                    {
                                        text = allbetsstr
                                    }
                                };
                                connector2.Conversations.ReplyToActivity(reply);
                            }
                        }
                    }
                }
            }
        }