Пример #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
        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));
        }