Пример #1
0
        public override InlineQueryResult[] GetResult()
        {
            db = new MarketBotDbContext();

            var product = db.Product.Where(p => p.Name == Query.Trim()).Include(p => p.ProductPhoto).FirstOrDefault();

            InputTextMessageContent[] textcontent = new InputTextMessageContent[product.ProductPhoto.Count];
            InlineQueryResultPhoto[]  ResultPhoto = new InlineQueryResultPhoto[product.ProductPhoto.Count];
            InlineQueryResult[]       result      = new InlineQueryResult[product.ProductPhoto.Count];

            if (product != null)
            {
                int i = 0;
                foreach (var photo in product.ProductPhoto)
                {
                    var attach = db.AttachmentFs.Find(photo.AttachmentFsId);


                    ResultPhoto[i]         = new InlineQueryResultPhoto();
                    ResultPhoto[i].Id      = (i + 1).ToString();
                    ResultPhoto[i].Caption = attach.Caption;
                    // ResultPhoto[i].Url = db.AttachmentTelegram.Where(a => a.AttachmentFsId == attach.Id && a.BotInfoId == this.BotInfo.Id).FirstOrDefault().FileId;
                    ResultPhoto[i].ThumbUrl = "https://groosha.gitbooks.io/telegram-bot-lessons/l9_2.png";
                    ResultPhoto[i].Url      = "https://groosha.gitbooks.io/telegram-bot-lessons/l9_2.png";
                    result[i] = new InlineQueryResult();

                    result[i] = ResultPhoto[i];
                    i++;
                }
            }

            return(result);
        }
Пример #2
0
        private static async Task CheckInlineQueryAsync(Update update)
        {
            // Telebot will support all 19 types of InlineQueryResult.
            // To see available inline query results:
            // https://core.telegram.org/bots/api#answerinlinequery
            var articleResult = new InlineQueryResultArticle
            {
                Id    = Guid.NewGuid().ToString("N"),
                Title = "This is a title",
                Url   = "https://core.telegram.org/bots/api#inlinequeryresultarticle"
            };

            var photoResult = new InlineQueryResultPhoto
            {
                Id           = Guid.NewGuid().ToString("N"),
                Url          = "https://telegram.org/file/811140636/1/hzUbyxse42w/4cd52d0464b44e1e5b",
                ThumbnailUrl = "https://telegram.org/file/811140636/1/hzUbyxse42w/4cd52d0464b44e1e5b"
            };


            var gifResult = new InlineQueryResultGif
            {
                Id           = Guid.NewGuid().ToString("N"),
                Url          = "http://i.giphy.com/ya4eevXU490Iw.gif",
                ThumbnailUrl = "http://i.giphy.com/ya4eevXU490Iw.gif"
            };

            var results = new InlineQueryResult[] { articleResult, photoResult, gifResult };
            await TelegramMessager._telebot.AnswerInlineQueryAsync(update.InlineQuery.Id, results).ConfigureAwait(false);
        }
        /// <param name="cardId">Card ID</param>
        /// <param name="colors"></param>
        /// <param name="colorInRgb">With this color ImageGenerator will generate picture</param>
        /// <param name="colorSpace">Color space that used for this color</param>
        /// <returns>Card with preview image, which should be replaced with FinalMessage after sending</returns>
        public (InlineQueryResultPhoto, FinalMessage) ProcessInlineCardForColorSpace(string cardId, float[] colors, Rgba32 colorInRgb, ColorSpace colorSpace)
        {
            string previewUrl = _imageGeneratorClient.GetLink(colorInRgb, 250, 150, colorSpace.Name);
            string finalUrl   = _imageGeneratorClient.GetLink(colorInRgb, 250, 150, null);
            string caption    = _captionGenerator.GenerateCaption(colorSpace, colors);

            var card = new InlineQueryResultPhoto(cardId, previewUrl, previewUrl)
            {
                Caption     = caption,
                PhotoWidth  = 250,
                PhotoHeight = 150,
                ReplyMarkup = new InlineKeyboardMarkup(new InlineKeyboardButton {
                    Text = "Loading...", CallbackData = "do-not-click-it"
                })
            };

            var finalMessage = new FinalMessage(finalUrl, caption);

            return(card, finalMessage);
        }
Пример #4
0
        private Task CheckInlineQueryAsync(Update update)
        {
            WriteLine(ConsoleColor.Green, "Received InlineQuery:");
            Dump(update, ConsoleColor.Green);

            var articleResult = new InlineQueryResultArticle
            {
                Id    = Guid.NewGuid().ToString("N"),
                Title = "This is a title",
                Url   = "https://core.telegram.org/bots/api#inlinequeryresultarticle"
            };

            var photoResult = new InlineQueryResultPhoto
            {
                Id           = Guid.NewGuid().ToString("N"),
                Url          = "https://telegram.org/file/811140636/1/hzUbyxse42w/4cd52d0464b44e1e5b",
                ThumbnailUrl = "https://telegram.org/file/811140636/1/hzUbyxse42w/4cd52d0464b44e1e5b"
            };


            var gifResult = new InlineQueryResultGif
            {
                Id           = Guid.NewGuid().ToString("N"),
                Url          = "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/200px-Rotating_earth_%28large%29.gif",
                ThumbnailUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/200px-Rotating_earth_%28large%29.gif"
            };

            var results = new InlineQueryResult[] { articleResult, photoResult, gifResult };

            var answerId = update.InlineQuery.Id;

            WriteLine(ConsoleColor.DarkGreen, "Sending: ");
            WriteLine(ConsoleColor.DarkGreen, $"Answer Id: {answerId}");
            Dump(results, ConsoleColor.DarkGreen);

            return(this._telebot.AnswerInlineQueryAsync(answerId, results));
        }
 public static ValidationResult <InlineQueryResultPhoto> CreateValidation(this InlineQueryResultPhoto value) =>
 new ValidationResult <InlineQueryResultPhoto>(value).ValidateRequired(x => x.Type)
 .ValidateRequired(x => x.Id)
 .ValidateRequired(x => x.PhotoUrl)
 .ValidateRequired(x => x.ThumbUrl);