Пример #1
0
        internal static async Task <MessageSentResult> SendMessageInPrivateOrAGroup(
            TelegramBotAbstract telegramBotClient,
            Language text, string lang, string username, int userId, string firstName, string lastName, long chatId,
            ChatType chatType, ParseMode parseMode = ParseMode.Html)
        {
            MessageSentResult r = null;

            try
            {
                r = await telegramBotClient.SendTextMessageAsync(userId,
                                                                 text, ChatType.Private, parseMode : parseMode,
                                                                 lang : lang, username : username,
                                                                 replyMarkupObject : new ReplyMarkupObject(ReplyMarkupEnum.REMOVE));

                if (r.IsSuccess())
                {
                    return(r);
                }
            }
            catch
            {
                // ignored
            }

            if (!(r == null || r.IsSuccess() == false))
            {
                return(r);
            }

            var messageTo = GetMessageTo(firstName, lastName, userId);
            var text3     = new Language(new Dictionary <string, string>
            {
                { "en", "[Message for " + messageTo + "]\n\n" + text.Select("en") },
                { "it", "[Messaggio per " + messageTo + "]\n\n" + text.Select("it") }
            });

            return(await telegramBotClient.SendTextMessageAsync(chatId, text3, chatType,
                                                                lang, parseMode, new ReplyMarkupObject(ReplyMarkupEnum.REMOVE), username));
        }
Пример #2
0
        internal static async Task <MessageSentResult> SendMessageInAGroup(TelegramBotAbstract telegramBotClient,
                                                                           string lang, Language text,
                                                                           long chatId, ChatType chatType, ParseMode parseMode, long?replyToMessageId,
                                                                           bool disablePreviewLink, int i = 0)
        {
            MessageSentResult r1 = null;

            if (telegramBotClient == null)
            {
                return(null);
            }

            if (i > 5)
            {
                return(null);
            }

            try
            {
                r1 = await telegramBotClient.SendTextMessageAsync(chatId,
                                                                  text,
                                                                  chatType,
                                                                  lang,
                                                                  parseMode,
                                                                  username : null,
                                                                  replyMarkupObject : null,
                                                                  replyToMessageId : replyToMessageId,
                                                                  disablePreviewLink : disablePreviewLink);
            }
            catch (Exception e1)
            {
                await NotifyUtil.NotifyOwners(e1, telegramBotClient, i + 1);
            }

            return(r1);
        }
Пример #3
0
        internal static async Task NotifyOwnersAsync(Tuple <List <ExceptionNumbered>, int> exceptions,
                                                     TelegramBotAbstract sender, string v, string langCode, long?replyToMessageId = null)
        {
            MessageSentResult m = null;

            try
            {
                var text = new Language(new Dictionary <string, string>
                {
                    { "en", v }
                });
                m = await NotifyOwners2Async(text, sender, 0, langCode, replyToMessageId);
            }
            catch
            {
                ;
            }

            try
            {
                var text = new Language(new Dictionary <string, string>
                {
                    { "en", "Number of exceptions: " + exceptions.Item2 + " - " + exceptions.Item1.Count }
                });
                _ = await NotifyOwners2Async(text, sender, 0, langCode, replyToMessageId);
            }
            catch
            {
                ;
            }

            try
            {
                foreach (var e1 in exceptions.Item1)
                {
                    try
                    {
                        await NotifyOwners(e1, sender);
                    }
                    catch
                    {
                        ;
                    }
                }
            }
            catch
            {
                ;
            }

            try
            {
                var text2 = new Language(new Dictionary <string, string>
                {
                    { "en", "---End---" }
                });

                long?replyto = null;
                ;

                if (m != null)
                {
                    replyto = m.GetMessageID();
                }
                await NotifyOwners2Async(text2, sender, 0, langCode, replyto);
            }
            catch
            {
                ;
            }
        }
Пример #4
0
        private static async Task <MessageSentResult> SendExtraInfoDbForThisMessage(MessageSentResult r1, DataRow dr,
                                                                                    int?chatIdToSendTo, ChatType?chatTypeToSendTo, TelegramBotAbstract telegramBotAbstract, int count)
        {
            if (r1 == null || r1.IsSuccess() == false)
            {
                return(r1);
            }

            if (chatIdToSendTo == null)
            {
                return(new MessageSentResult(false, null, chatTypeToSendTo));
            }

            var dto  = dr["sent_date"];
            var fieo = dr["from_id_entity"];
            var fipo = dr["from_id_person"];

            DateTime?dt             = null;
            int?     from_id_entity = null;
            int?     from_id_person = null;

            try
            {
                dt = (DateTime?)dto;
            }
            catch
            {
                ;
            }

            try
            {
                from_id_entity = (int?)fieo;
            }
            catch
            {
                ;
            }

            try
            {
                from_id_person = (int?)fipo;
            }
            catch
            {
                ;
            }

            var text1 = "📌 ID: " + count + "\n";

            if (dt != null)
            {
                text1 += "📅 " + DateTimeClass.DateTimeToItalianFormat(dt) + "\n";
            }
            if (from_id_entity != null)
            {
                var entity_name = Assoc.GetNameOfEntityFromItsID(from_id_entity.Value);
                text1 += "👥 " + entity_name + "\n";
            }

            if (from_id_person != null)
            {
                text1 += "✍ " + from_id_person + "\n";
            }

            var dict = new Dictionary <string, string>
            {
                { "en", text1 }
            };
            var text2 = new Language(dict);

            return(await telegramBotAbstract.SendTextMessageAsync(chatIdToSendTo.Value, text2, chatTypeToSendTo, "",
                                                                  ParseMode.Html,
                                                                  null, null, r1.GetMessageID(), true));
        }