예제 #1
0
        public override InlineQueryResult[] GetResult()
        {
            db = new MarketBotDbContext();

            var ProductList = GetProductList().Take(MaxResult).ToList();

            InputTextMessageContent[]  textcontent = new InputTextMessageContent[ProductList.Count];
            InlineQueryResultArticle[] article     = new InlineQueryResultArticle[ProductList.Count];
            InlineQueryResult[]        result      = new InlineQueryResult[ProductList.Count];

            int i = 0;

            foreach (Product prod in ProductList)
            {
                textcontent[i]                       = new InputTextMessageContent();
                textcontent[i].ParseMode             = Telegram.Bot.Types.Enums.ParseMode.Html;
                textcontent[i].DisableWebPagePreview = true;
                textcontent[i].MessageText           = "/adminproduct" + prod.Id.ToString();

                article[i]             = new InlineQueryResultArticle();
                article[i].HideUrl     = true;
                article[i].Id          = prod.Id.ToString();
                article[i].Title       = prod.Name;
                article[i].Description = "Категория:" + prod.Category.Name + BotMessage.NewLine() + "Цена:" + prod.CurrentPrice.Value;

                article[i].ThumbUrl            = "https://cdn2.iconfinder.com/data/icons/shop-payment-vol-6/128/shop-07-256.png";
                article[i].InputMessageContent = textcontent[i];
                result[i] = article[i];
                i++;
            }


            db.Dispose();
            return(result);
        }
        public override InlineQueryResult[] GetResult()
        {
            var Orders = FollowerFunction.FollowerOrder(FollowerId).Take(MaxResult).ToList();

            InputTextMessageContent[]  textcontent = new InputTextMessageContent[Orders.Count];
            InlineQueryResultArticle[] article     = new InlineQueryResultArticle[Orders.Count];
            InlineQueryResult[]        result      = new InlineQueryResult[Orders.Count];

            int i = 0;

            foreach (var order in Orders)
            {
                textcontent[i]                       = new InputTextMessageContent();
                textcontent[i].ParseMode             = Telegram.Bot.Types.Enums.ParseMode.Html;
                textcontent[i].DisableWebPagePreview = true;
                textcontent[i].MessageText           = "/order" + order.Number.ToString();

                article[i]             = new InlineQueryResultArticle();
                article[i].HideUrl     = false;
                article[i].Id          = order.Id.ToString();
                article[i].Title       = "Заказ №" + order.Number.ToString();
                article[i].Description = "Время:" + order.DateAdd.ToString() + BotMessage.NewLine();

                article[i].ThumbUrl            = "https://cdn2.iconfinder.com/data/icons/shop-payment-vol-6/128/shop-19-256.png";
                article[i].InputMessageContent = textcontent[i];

                result[i] = new InlineQueryResult();
                result[i] = article[i];

                i++;
            }

            return(result);
        }
예제 #3
0
        public async Task Should_Answer_Inline_Query_With_Article()
        {
            // ToDo: add exception: Bad Request: QUERY_ID_INVALID
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldAnswerInlineQueryWithArticle,
                                                         startInlineQuery : true);

            Update update = await _fixture.UpdateReceiver.GetInlineQueryUpdateAsync();

            InputMessageContent inputMessageContent = new InputTextMessageContent
            {
                MessageText = "https://core.telegram.org/bots/api",
            };

            InlineQueryResultBase[] results =
            {
                new InlineQueryResultArticle(
                    id: "bot-api",
                    title: "Telegram Bot API",
                    inputMessageContent: inputMessageContent)
                {
                    Description = "The Bot API is an HTTP-based interface created for developers",
                },
            };

            await BotClient.AnswerInlineQueryAsync(
                inlineQueryId : update.InlineQuery.Id,
                results : results,
                cacheTime : 0
                );
        }
예제 #4
0
        internal static async Task AnswerInlineQueryAsync(ExtendedUser user, string inlineQueryId, IReadOnlyList <YoutubeExplode.Models.Video> videos)
        {
            var results = new List <InlineQueryResultArticle>();

            for (int i = 0; i < Math.Min(50, videos.Count); i++)
            {
                var video = videos.ElementAt(i);

                var message = $"*{video.Author}*" + "\n\r" +
                              $"[{video.Title}](https://www.youtube.com/watch?v={video.Id})";

                var thumbnail = video.Thumbnails.LowResUrl;
                var url       = "https://www.youtube.com/watch?v=" + video.Id;
                InputTextMessageContent content = new InputTextMessageContent(message);
                content.ParseMode = ParseMode.Markdown;
                InlineQueryResultArticle result = new InlineQueryResultArticle(inlineQueryId + i * 123, video.Title, content);
                result.ThumbUrl = thumbnail;
                result.Url      = url;
                result.HideUrl  = true;

                result.ReplyMarkup = GetMarkup(user, video);
                result.Description = $@"👁️ {ShortenNumber(video.Statistics.ViewCount)} | {ShortenNumber(video.Statistics.LikeCount)} 👍 \ 👎 {ShortenNumber(video.Statistics.DislikeCount)}";

                results.Add(result);
            }

            await botClient.AnswerInlineQueryAsync(inlineQueryId, results, 100, true);

            //cacheTime  - The maximum amount of time the result of the inline query may be cached on the server
            //isPersonal - Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query
            //offset     - Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes.
            //pmText     - clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switchPmParameter
        }
예제 #5
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);
        }
예제 #6
0
        public InlineQueryResultArticle Result(Strings strings, string apikey, bool channel)
        {
            if (closed)
            {
                return(null);
            }
            ContentParts content = GetContent(strings, apikey, channel);

            return(InlineQueryResultArticle.Create(chatId + ":" + pollId, pollText, InputTextMessageContent.Create(content.Text, disableWebPagePreview: true), content.InlineKeyboard, description: content.Description, thumbUrl: "https://bots.wjclub.tk/groupagreebot/res/" + pollType.ToString() + "_" + anony.ToString() + ".png", thumbWidth: 256, thumbHeight: 256));
        }
        public override InlineQueryResult[] GetResult()
        {
            db = new MarketBotDbContext();

            this.FollowerList = GetFollower().Take(MaxResult).ToList();

            InputTextMessageContent[]  textcontent = new InputTextMessageContent[FollowerList.Count];
            InlineQueryResultArticle[] article     = new InlineQueryResultArticle[FollowerList.Count];
            InlineQueryResult[]        result      = new InlineQueryResult[FollowerList.Count];

            int i = 0;

            foreach (var follower in FollowerList)
            {
                string telephoneLine = "";

                FollowerControlMessage followerControlMessage = new FollowerControlMessage(follower.Id);
                var message = followerControlMessage.BuildMsg();

                if (follower.Telephone != null && follower.Telephone != "")
                {
                    telephoneLine = BotMessage.NewLine() + "Телефон: " + follower.Telephone;
                }


                textcontent[i]                       = new InputTextMessageContent();
                textcontent[i].ParseMode             = Telegram.Bot.Types.Enums.ParseMode.Html;
                textcontent[i].DisableWebPagePreview = true;
                textcontent[i].MessageText           = message.TextMessage;

                article[i]             = new InlineQueryResultArticle();
                article[i].HideUrl     = false;
                article[i].Id          = follower.Id.ToString();
                article[i].Title       = follower.FirstName + " " + follower.LastName;
                article[i].Description = telephoneLine;
                article[i].ReplyMarkup = followerControlMessage.SetInline();

                article[i].ThumbUrl            = "https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-11-2-256.png";
                article[i].Url                 = "https://t.me/" + follower.UserName;
                article[i].InputMessageContent = textcontent[i];

                result[i] = new InlineQueryResult();
                result[i] = article[i];

                i++;
            }

            return(result);
        }
예제 #8
0
        public InlineQueryResult[] ProductInlineSearch()
        {
            List <Product> product = new List <MyTelegramBot.Product>();
            SqlParameter   param   = new SqlParameter("@name", "%" + Query + "%");

            product = db.Product.FromSql("SELECT * FROM Product WHERE Name LIKE @name and Enable=1", param).
                      Include(p => p.ProductPrice).Include(p => p.Stock).Include(p => p.ProductPrice).Include(p => p.Unit).ToList();


            InputTextMessageContent[]  textcontent = new InputTextMessageContent[product.Count];
            InlineQueryResultArticle[] article     = new InlineQueryResultArticle[product.Count];
            InlineQueryResult[]        result      = new InlineQueryResult[product.Count];


            for (int i = 0; i < product.Count; i++)
            {
                textcontent[i] = new InputTextMessageContent();
                textcontent[i].DisableWebPagePreview = true;
                textcontent[i].MessageText           = product[i].ToString();

                product[i].ProductPrice.Where(p => p.Enabled).FirstOrDefault().Currency
                    = db.Currency.Where(c => c.Id == product[i].ProductPrice.Where(p => p.Enabled).FirstOrDefault().CurrencyId).FirstOrDefault();

                article[i]             = new InlineQueryResultArticle();
                article[i].HideUrl     = true;
                article[i].Id          = product[i].Id.ToString();
                article[i].Title       = product[i].Name;
                article[i].Description = product[i].Name + " "
                                         + product[i].ProductPrice.Where(p => p.Enabled).FirstOrDefault().Value.ToString() + " "
                                         + product[i].ProductPrice.Where(p => p.Enabled).FirstOrDefault().Currency.ShortName
                                         + "\r\nНажмите сюда";

                article[i].ThumbUrl            = product[i].PhotoUrl;
                article[i].Url                 = product[i].TelegraphUrl;
                article[i].InputMessageContent = textcontent[i];
                article[i].ReplyMarkup         = new InlineKeyboardMarkup(
                    new[] {
                    new[]
                    {
                        OpenBtn = new InlineKeyboardCallbackButton("Открыть", BuildCallData("GetProduct", product[i].Id))
                    }
                });
                result[i] = new InlineQueryResult();
                result[i] = article[i];
            }
            return(result);
        }
예제 #9
0
        public async Task Should_Edit_Inline_Message_Markup()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldEditInlineMessageMarkup,
                                                         startInlineQuery : true);

            #region Answer Inline Query with an Article

            Update inlineQUpdate = await _fixture.UpdateReceiver.GetInlineQueryUpdateAsync();

            string data = "change-me" + new Random().Next(2_000);
            InlineKeyboardMarkup initialMarkup = new InlineKeyboardMarkup(new[]
            {
                InlineKeyboardButton.WithCallbackData("Click here to change this button", data)
            });

            InputMessageContent inputMessageContent = new InputTextMessageContent
            {
                MessageText = "https://core.telegram.org/bots/api"
            };

            InlineQueryResultBase[] inlineQueryResults =
            {
                new InlineQueryResultArticle(
                    id: "bot-api",
                    title: "Telegram Bot API",
                    inputMessageContent: inputMessageContent)
                {
                    Description = "The Bot API is an HTTP-based interface created for developers",
                    ReplyMarkup = initialMarkup,
                },
            };

            await BotClient.AnswerInlineQueryAsync(inlineQUpdate.InlineQuery.Id, inlineQueryResults, 0);

            #endregion

            Update callbackQUpdate = await _fixture.UpdateReceiver
                                     .GetCallbackQueryUpdateAsync(data : data);

            await BotClient.EditMessageReplyMarkupAsync(
                inlineMessageId : callbackQUpdate.CallbackQuery.InlineMessageId,
                replyMarkup : "✌ Edited 👌"
                );

            Assert.Equal(data, callbackQUpdate.CallbackQuery.Data);
        }
예제 #10
0
        /// <summary>
        /// combines Id of message, Title of message, Text of message into a Message (InlineQueryResult), also called an "Article".
        /// </summary>
        /// <param name="id">id of article</param>
        /// <param name="title">title - what user sees even before submitting to send that QueryResult</param>
        /// <param name="text">text - what will be send to a chat</param>
        /// <returns></returns>
        public static async Task <IEnumerable <InlineQueryResultBase> > ArticleToQueryResultAsync(string id, string title, string text = "")
        {
            return(await Task.Run(() =>
            {
                if (text == null)
                {
                    text = string.Empty;
                }

                var content = new InputTextMessageContent(text);

                InlineQueryResultBase[] results =
                {
                    new InlineQueryResultArticle(id, title, content)
                };

                return results;
            }));
        }
예제 #11
0
        /// <summary>
        /// Build inline query result from price position
        /// </summary>
        /// <param name="p"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        public static InlineQueryResultBase ToInlineResult(
            this PricePosition p,
            int i,
            string query,
            decimal rate,
            string userName)
        {
            var message = string.Format(
                ResultsTemplate,
                query,
                rate,
                string.Format("{0}:\n\n{1}", p.Category, p.ToFindResult()),
                userName);

            var content = new InputTextMessageContent(message)
            {
                ParseMode = ParseMode.Markdown
            };

            return(new InlineQueryResultArticle(i.ToString(), p.Name, content));
        }
        public override InlineQueryResult[] GetResult()
        {
            db = new MarketBotDbContext();

            var Follower = db.Follower.Where(f => f.ChatId == ChatId).FirstOrDefault();

            if (Follower != null)
            {
                OrderList = db.Orders.Where(o => o.FollowerId == Follower.Id).OrderByDescending(o => o.Id).Take(MaxResult).ToList();

                int i = 0;

                InputTextMessageContent[]  textcontent = new InputTextMessageContent[OrderList.Count];
                InlineQueryResultArticle[] article     = new InlineQueryResultArticle[OrderList.Count];
                InlineQueryResult[]        result      = new InlineQueryResult[OrderList.Count];

                foreach (Orders order in OrderList)
                {
                    textcontent[i]                       = new InputTextMessageContent();
                    textcontent[i].ParseMode             = Telegram.Bot.Types.Enums.ParseMode.Html;
                    textcontent[i].DisableWebPagePreview = true;
                    textcontent[i].MessageText           = "/myorder" + order.Number.ToString();

                    article[i]             = new InlineQueryResultArticle();
                    article[i].HideUrl     = true;
                    article[i].Id          = order.Id.ToString();
                    article[i].Title       = order.Number.ToString();
                    article[i].Description = "№:" + order.Number.ToString() + BotMessage.NewLine() + "Дата:" + order.DateAdd.ToString();

                    article[i].ThumbUrl            = "https://cdn2.iconfinder.com/data/icons/shop-payment-vol-6/128/shop-04-256.png";
                    article[i].InputMessageContent = textcontent[i];
                    result[i] = article[i];
                    i++;
                }
                db.Dispose();
                return(result);
            }

            return(null);
        }
        public override InlineQueryResult[] GetResult()
        {
            var list = PaymentsFunction.GetPaymentsList().Take(MaxResult).ToList();


            InputTextMessageContent[]  textcontent = new InputTextMessageContent[list.Count];
            InlineQueryResultArticle[] article     = new InlineQueryResultArticle[list.Count];
            InlineQueryResult[]        result      = new InlineQueryResult[list.Count];

            int i = 0;

            foreach (var payment in list)
            {
                //PaymentViewMsg = new Messages.Admin.PaymentViewMessage(payment);
                //BotMessage mess = PaymentViewMsg.BuildMsg();

                textcontent[i]                       = new InputTextMessageContent();
                textcontent[i].ParseMode             = Telegram.Bot.Types.Enums.ParseMode.Html;
                textcontent[i].DisableWebPagePreview = true;
                textcontent[i].MessageText           = "/payment" + payment.Id.ToString();

                article[i]             = new InlineQueryResultArticle();
                article[i].HideUrl     = false;
                article[i].Id          = payment.Id.ToString();
                article[i].Title       = "Платеж №" + payment.Id.ToString();
                article[i].Description = payment.TimestampDataAdd.ToString();

                article[i].ThumbUrl = "https://cdn2.iconfinder.com/data/icons/shop-payment-vol-6/128/shop-01-256.png";
                //article[i].ReplyMarkup = mess.MessageReplyMarkup;
                article[i].InputMessageContent = textcontent[i];


                result[i] = new InlineQueryResult();
                result[i] = article[i];

                i++;
            }

            return(result);
        }
    private async void OnFinishSearch(List <Film> filmsFound, Update update)
    {
        if (filmsFound.Count > 0)
        {
            var results = new InlineQueryResultBase[filmsFound.Count];

            for (int i = 0; i < filmsFound.Count; i++)
            {
                InputTextMessageContent aux = new InputTextMessageContent(filmsFound[i].title);

                //@TODO color to rating
                // float rating = float.Parse(filmsFound[i].rating);
                //string emojiRating = rating > 6.9f ?TelegramEmoji.Emojis.Symbols.Other_Symbol.: rating > 4.9 ?:;

                results[i] = new InlineQueryResultArticle(i.ToString(), filmsFound[i].title, aux);

                results[i].ReplyMarkup = new InlineKeyboardMarkup(InlineKeyboardButton.WithUrl(filmsFound[i].rating, filmsFound[i].link));
            }

            await botClient.AnswerInlineQueryAsync(update.InlineQuery.Id, results);
        }
    }
예제 #15
0
    public async Task Execute(TelegramBotClient botClient, Update update)
    {
        InputTextMessageContent aux = new InputTextMessageContent(
            Emojis.Symbols.Other_Symbol.double_exclamation_mark +
            Emojis.Symbols.Other_Symbol.double_exclamation_mark +
            Emojis.Symbols.Other_Symbol.double_exclamation_mark +
            Emojis.Symbols.Other_Symbol.double_exclamation_mark +
            Emojis.Symbols.Other_Symbol.double_exclamation_mark +
            Emojis.Symbols.Other_Symbol.double_exclamation_mark +
            Emojis.Symbols.Other_Symbol.double_exclamation_mark
            );

        var articleResult = new InlineQueryResultArticle("A", "Spoiler", aux);

        articleResult.ThumbUrl = "https://cdn.pixabay.com/photo/2012/04/12/22/25/warning-sign-30915_960_720.png";

        var results = new InlineQueryResultBase[] { articleResult };

        results[0].ReplyMarkup = new InlineKeyboardMarkup(InlineKeyboardButton.WithCallbackData("Spoiler", update.InlineQuery.Query.Remove(0, 9)));

        await botClient.AnswerInlineQueryAsync(update.InlineQuery.Id, results);
    }
        public override InlineQueryResult[] GetResult()
        {
            this.Orders = GetOrder();
            InputTextMessageContent[]  textcontent = new InputTextMessageContent[Orders.Count];
            InlineQueryResultArticle[] article     = new InlineQueryResultArticle[Orders.Count];
            InlineQueryResult[]        result      = new InlineQueryResult[Orders.Count];


            for (int i = 0; i < Orders.Count; i++)
            {
                string StatusOrderLine = "";

                if (Orders[i].CurrentStatusNavigation != null)
                {
                    StatusOrderLine = "\r\nСтатус: " + db.Status.Find(Orders[i].CurrentStatusNavigation.StatusId).Name;
                }

                textcontent[i] = new InputTextMessageContent();
                textcontent[i].DisableWebPagePreview = true;
                textcontent[i].MessageText           = "/order" + Orders[i].Number.ToString();

                article[i]             = new InlineQueryResultArticle();
                article[i].HideUrl     = true;
                article[i].Id          = Orders[i].Number.ToString();
                article[i].Title       = Orders[i].Number.ToString();
                article[i].Description = "№" + Orders[i].Number.ToString() + "\r\nДата:" + Orders[i].DateAdd.ToString()
                                         + StatusOrderLine;

                article[i].ThumbUrl            = "https://cdn2.iconfinder.com/data/icons/shop-payment-vol-6/128/shop-19-256.png";
                article[i].InputMessageContent = textcontent[i];


                result[i] = new InlineQueryResult();
                result[i] = article[i];
            }
            db.Dispose();
            return(result);
        }
예제 #17
0
        public async Task Should_Answer_Inline_Query_With_Article()
        {
            // ToDo: add exception: Bad Request: QUERY_ID_INVALID
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldAnswerInlineQueryWithArticle,
                                                         startInlineQuery : true);

            Update queryUpdate = await _fixture.UpdateReceiver.GetInlineQueryUpdateAsync();

            const string            resultId            = "article:bot-api";
            InputMessageContentBase inputMessageContent =
                new InputTextMessageContent("https://core.telegram.org/bots/api");

            InlineQueryResultBase[] results =
            {
                new InlineQueryResultArticle(
                    id: resultId,
                    title: "Telegram Bot API",
                    inputMessageContent: inputMessageContent)
                {
                    Description = "The Bot API is an HTTP-based interface created for developers",
                },
            };

            await BotClient.AnswerInlineQueryAsync(
                inlineQueryId : queryUpdate.InlineQuery.Id,
                results : results,
                cacheTime : 0
                );

            var inlieQueryUpdates = await GetInlineQueryResultUpdates(MessageType.Text);

            Update             resultUpdate = inlieQueryUpdates.ChosenResultUpdate;
            ChosenInlineResult chosenResult = resultUpdate.ChosenInlineResult;

            Assert.Equal(UpdateType.ChosenInlineResult, resultUpdate.Type);
            Assert.Equal(resultId, chosenResult.ResultId);
            Assert.Empty(chosenResult.Query);
        }
예제 #18
0
        private void Bot_OnInlineQuery(object sender, InlineQueryEventArgs e)
        {
            List <InlineQueryResultBase> inlineQueryResults = new List <InlineQueryResultBase>();

            if (e.InlineQuery.Query != string.Empty)
            {
                List <TolokaResult>          tolokaResults = Searcher.search(e.InlineQuery.Query);
                List <InlineQueryResultBase> inlineResults = new List <InlineQueryResultBase>();

                if (tolokaResults.Count > 0)
                {
                    foreach (var result in tolokaResults)
                    {
                        var inputContent = new InputTextMessageContent(result.ToString());
                        var article      = new InlineQueryResultArticle(tolokaResults.IndexOf(result).ToString(), result.title, inputContent)
                        {
                            Description = $"{result.seeders}/{result.leechers}/{result.complete} ({result.size})"
                        };

                        inlineResults.Add(article);
                    }
                }

                else
                {
                    var inputContent = new InputTextMessageContent($"No results found for {e.InlineQuery.Query}.");
                    var article      = new InlineQueryResultArticle("1", "Not found", inputContent)
                    {
                        Description = $"Nothing found by {e.InlineQuery.Query}"
                    };

                    inlineResults.Add(article);
                }

                bot.AnswerInlineQueryAsync(e.InlineQuery.Id, inlineResults);
            }
        }
예제 #19
0
        public async Task ProcessUpdateAsync(Update update, CancellationToken cancellationToken)
        {
            if (update.Type == TB.Enums.UpdateType.InlineQuery)
            {
                var companies = this.GetCompaniesFromQuery(update);
                var quotes    = await this.stockProvider.GetQuotesAsync(companies.Select(c => c.Symbol), cancellationToken);

                var results = new List <InlineQueryResultArticle>();
                foreach (var company in companies)
                {
                    var quote   = quotes[company.Symbol].Quote;
                    var logoUrl = this.stockProvider.GetLogo(company.Symbol);
                    var title   = $"{company.Name} ({company.Symbol})";

                    var us          = CultureInfo.GetCultureInfo("en-US");
                    var description = new StringBuilder();
                    description.AppendLine($"*{quote.LatestPrice?.ToString("C", us)}* {(quote.Change > 0 ? "+" : "") + quote.Change?.ToString("C", us)} ({(quote.ChangePercent > 0 ? "+" : "") + quote.ChangePercent?.ToString("P")})");
                    description.AppendLine($"*High:* {quote.High?.ToString("C", us)}");
                    description.AppendLine($"*Low:* {quote.Low?.ToString("C", us)}");
                    description.AppendLine($"*52w high:* {quote.Week52High?.ToString("C", us)}");
                    description.Append($"*52w low:* {quote.Week52Low?.ToString("C", us)}");

                    var textContent        = $"*{title}*\n{description}";
                    var testMessageContent = new InputTextMessageContent(textContent)
                    {
                        ParseMode = TB.Enums.ParseMode.Markdown
                    };
                    var result = new InlineQueryResultArticle(company.Symbol, title, testMessageContent)
                    {
                        Description = description.ToString(),
                        ThumbUrl    = logoUrl
                    };
                    results.Add(result);
                }
                await this.telegramBot.ReplyAsync(update.InlineQuery.Id, results, cancellationToken);
            }
        }
예제 #20
0
        public override InlineQueryResult[] GetResult()
        {
            list = HelpDeskFunction.GetHelpDeskList(Number).Take(MaxResult).ToList();


            InputTextMessageContent[]  textcontent = new InputTextMessageContent[list.Count];
            InlineQueryResultArticle[] article     = new InlineQueryResultArticle[list.Count];
            InlineQueryResult[]        result      = new InlineQueryResult[list.Count];

            int i = 0;

            foreach (var help in list)
            {
                textcontent[i]                       = new InputTextMessageContent();
                textcontent[i].ParseMode             = Telegram.Bot.Types.Enums.ParseMode.Html;
                textcontent[i].DisableWebPagePreview = true;
                textcontent[i].MessageText           = "/ticket" + help.Number.ToString();

                article[i]             = new InlineQueryResultArticle();
                article[i].HideUrl     = false;
                article[i].Id          = help.Id.ToString();
                article[i].Title       = "Заявка №" + help.Number.ToString();
                article[i].Description = help.Number + BotMessage.NewLine() +
                                         "Время:" + help.Timestamp;

                article[i].ThumbUrl            = "https://cdn2.iconfinder.com/data/icons/shop-payment-vol-6/128/shop-10-256.png";
                article[i].InputMessageContent = textcontent[i];

                result[i] = new InlineQueryResult();
                result[i] = article[i];

                i++;
            }

            return(result);
        }
예제 #21
0
        public InlineQueryResultArticle Result(Strings strings, string apikey, bool channel)
        {
            if (closed)
            {
                return(null);
            }
            ContentParts content = GetContent(strings, apikey, noApproximation: true /*TODO Request handler here*/, channel: channel);

            return(InlineQueryResultArticle.Create(chatId + ":" + pollId, content.InlineTitle, InputTextMessageContent.Create(content.Text, disableWebPagePreview: true), content.InlineKeyboard, description: content.InlineDescription, thumbUrl: "https://wjclub.capella.uberspace.de/groupagreebot/res/" + pollType.ToString() + "_" + anony.ToString() + ".png", thumbWidth: 256, thumbHeight: 256));
        }
예제 #22
0
        public HurtomBot(string TelegramApiToken)
        {
            bot = new TelegramBotClient(TelegramApiToken);

            bot.SetWebhookAsync("");

            bot.OnInlineQuery += async(object updobj, InlineQueryEventArgs iqea) =>
            {
                if (string.IsNullOrEmpty(iqea.InlineQuery.Query) || string.IsNullOrWhiteSpace(iqea.InlineQuery.Query))
                {
                    return;
                }

                var toloka = new TolokaHurtom.Toloka(iqea.InlineQuery.Query).ToArray();

                if (toloka.Length > 0)
                {
                    var inline = new InlineQueryResultArticle[toloka.Length];

                    for (int i = 0; i < toloka.Length; i++)
                    {
                        var content = new InputTextMessageContent($"<b>{toloka[i].title}</b>\n\n{toloka[i].size} | Роздають: {toloka[i].seeders} | Завантажують: {toloka[i].leechers}\n\n<i>{toloka[i].forum_parent} / {toloka[i].forum_name}</i>\n\n{toloka[i].link}");
                        content.ParseMode = ParseMode.Html;

                        inline[i] = new InlineQueryResultArticle(
                            i.ToString(),
                            toloka[i].title,
                            content);

                        inline[i].Description =
                            toloka[i].size + " | Роздають: " + toloka[i].seeders + " | Завантажують: " + toloka[i].leechers;

                        inline[i].ThumbUrl = toloka[i].link;
                    }

                    await bot.AnswerInlineQueryAsync(iqea.InlineQuery.Id, inline);
                }
            };

            bot.OnMessage += async(object updobj, MessageEventArgs mea) =>
            {
                var message = mea.Message;

                if (mea.Message.Type == MessageType.Text)
                {
                    if (message.Text == null)
                    {
                        return;
                    }

                    var ChatId = message.Chat.Id;

                    string command = message.Text.ToLower().Replace("@hurtombot", "").Replace("/", "");

                    switch (command)
                    {
                    case "start":
                        await bot.SendTextMessageAsync(ChatId, "Вітаю! Я @HurtomBot!\nНапишіть, що ви хочете знайти на Гуртом, і я знайду для вас українські торренти.\nНатисніть '/', щоби обрати команду.");

                        break;

                    case "sendtorrent":
                        await bot.SendTextMessageAsync(ChatId, "Оберіть чат, до якого хочете надіслати торрент.", replyMarkup : new InlineKeyboardMarkup(new[] { InlineKeyboardButton.WithSwitchInlineQuery("Надіслати") }));

                        break;

                    default:
                        foreach (var torrent in new TolokaHurtom.Toloka(command).ToArray())
                        {
                            bot.SendTextMessageAsync(ChatId, $"<b>{torrent.title}</b>\n\n{torrent.size} | Роздають: {torrent.seeders} | Завантажують: {torrent.leechers}\n\n<i>{torrent.forum_parent} / {torrent.forum_name}</i>\n\n{torrent.link}", ParseMode.Html);
                        }
                        break;
                    }
                }
            };
        }
 public static ValidationResult <InputTextMessageContent> CreateValidation(this InputTextMessageContent value) =>
 new ValidationResult <InputTextMessageContent>(value).ValidateRequired(x => x.MessageText);