Exemplo n.º 1
0
        public static async Task <Message> EditImage(this ITelegramClient bot, Message message, string imageUrl, string text = null, RequestItem item = null, InlineKeyboardMarkup replies = null)
        {
            var defaultPoster = Assembly.GetExecutingAssembly().GetResource("Assets.default_poster.png");
            var image         = await WebResource.Exists(imageUrl) ? new InputMedia(imageUrl) : new InputMedia(defaultPoster, "default_poster");

            if (message.Type == MessageType.Photo)
            {
                return(await bot.Client.EditMessageMediaAsync(
                           chatId : message.Chat,
                           messageId : message.MessageId,
                           media : new InputMediaPhoto(image)
                {
                    Caption = item?.AsString(text) ?? text ?? message.Caption
                },
                           replyMarkup : replies
                           ));
            }

            await bot.Client.DeleteMessageAsync(message.Chat, message.MessageId);

            return(await bot.Client.SendPhotoAsync(
                       chatId : message.Chat,
                       photo : image,
                       caption : item?.AsString(text) ?? text ?? message.Text,
                       replyMarkup : replies
                       ));
        }
Exemplo n.º 2
0
        public static async Task <Message> EditMessage(this ITelegramClient bot, Message message, string text = null, RequestItem item = null, InlineKeyboardMarkup replies = null)
        {
            if (message.Type == MessageType.Photo)
            {
                return(await bot.Client.EditMessageCaptionAsync(
                           chatId : message.Chat,
                           messageId : message.MessageId,
                           caption : item?.AsString(text) ?? text ?? message.Caption,
                           replyMarkup : replies
                           ));
            }

            return(await bot.Client.EditMessageTextAsync(
                       chatId : message.Chat,
                       messageId : message.MessageId,
                       text : item?.AsString(text) ?? text ?? message.Text,
                       replyMarkup : replies
                       ));
        }