Exemplo n.º 1
0
        public Task SendBotInlineModeQuery(BubbleGroup group, Bots.UpdateBotInlineQuery query, Action <Bots.MessagesBotResults> results)
        {
            return(Task.Factory.StartNew(() =>
            {
                using (var client = new FullClientDisposable(this))
                {
                    var telegramBotContact = query.Bot as TelegramBotContact;
                    var user = telegramBotContact.User;

                    var args = new MessagesGetInlineBotResultsArgs
                    {
                        Bot = TelegramUtils.CastUserToInputUser(user),
                        Peer = GetInputPeer(group.Address, group.IsParty, group.IsExtendedParty),
                        Query = query.Query,
                        Offset = query.Offset
                    };

                    SharpTelegram.Schema.MessagesBotResults telegramMessageBotResults =
                        (SharpTelegram.Schema.MessagesBotResults)
                        TelegramUtils.RunSynchronously(
                            client.Client.Methods.MessagesGetInlineBotResultsAsync(args));

                    var messageBotResults = new Bots.MessagesBotResults
                    {
                        Gallery = telegramMessageBotResults.Gallery != null ? true : false,
                        QueryId = telegramMessageBotResults.QueryId.ToString(),
                        NextOffset = telegramMessageBotResults.NextOffset,
                        Results = new List <Bots.BotInlineResultBase>()
                    };

                    if (telegramMessageBotResults.Results != null)
                    {
                        foreach (var telegramMessageBotResult in telegramMessageBotResults.Results)
                        {
                            Bots.BotInlineResultBase item = null;
                            if (telegramMessageBotResult is SharpTelegram.Schema.BotInlineResult)
                            {
                                var telegramItem = telegramMessageBotResult as SharpTelegram.Schema.BotInlineResult;
                                item = new Bots.BotInlineResult
                                {
                                    Id = telegramItem.Id,
                                    QueryId = telegramMessageBotResults.QueryId.ToString(),
                                    Type = telegramItem.Type,
                                    Title = telegramItem.Title,
                                    Description = telegramItem.Description,
                                    Url = telegramItem.Url,
                                    ThumbUrl = telegramItem.ThumbUrl,
                                    ContentUrl = telegramItem.ContentUrl,
                                    ContentType = telegramItem.ContentType,
                                    W = telegramItem.W,
                                    H = telegramItem.H,
                                    Duration = telegramItem.Duration,
                                    SendMessage = HandleInlineModeSendMessage(telegramItem.SendMessage, group)
                                };
                            }
                            else if (telegramMessageBotResult is SharpTelegram.Schema.BotInlineMediaResult)
                            {
                                var telegramItem = telegramMessageBotResult as SharpTelegram.Schema.BotInlineMediaResult;
                                item = new Bots.BotInlineMediaResult
                                {
                                    Id = telegramItem.Id,
                                    QueryId = telegramMessageBotResults.QueryId.ToString(),
                                    Type = telegramItem.Type,
                                    Title = telegramItem.Title,
                                    Description = telegramItem.Description,
                                    SendMessage = HandleInlineModeSendMessage(telegramItem.SendMessage, group)
                                };

                                var botInlineMediaResult = item as Bots.BotInlineMediaResult;
                                botInlineMediaResult.Photo = HandleInlineModePhoto(telegramItem.Photo);

                                botInlineMediaResult.Document = HandleInlineModeDocument(telegramItem.Document);
                            }
                            else
                            {
                                continue;
                            }

                            messageBotResults.Results.Add(item);
                        }
                    }

                    results(messageBotResults);
                }
            }));
        }
Exemplo n.º 2
0
 public Task <IMessagesBotResults> MessagesGetInlineBotResultsAsync(MessagesGetInlineBotResultsArgs args)
 {
     return(_remoteProcedureCaller.RpcAsync <IMessagesBotResults>(args));
 }