예제 #1
0
        public async Task Should_Edit_Message_Text()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldEditMessageText);

            const string originalMessagePrefix = "original\n";

            (MessageEntityType Type, string Value)[] entityValueMappings =
예제 #2
0
        public async Task Should_Send_Text_Message()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldSendTextMessage);

            const string text = "Hello world!";

            Message message = await BotClient.SendTextMessageAsync(
                chatId : _fixture.SupergroupChat.Id,
                text : text
                );

            Assert.Equal(text, message.Text);
            Assert.Equal(MessageType.Text, message.Type);
            Assert.Equal(_fixture.SupergroupChat.Id.ToString(), message.Chat.Id.ToString());
            Assert.InRange(message.Date, DateTime.UtcNow.AddSeconds(-10), DateTime.UtcNow.AddSeconds(2));
            Assert.True(JToken.DeepEquals(
                            JToken.FromObject(_fixture.BotUser), JToken.FromObject(message.From)
                            ));
        }
예제 #3
0
        public async Task Should_Upload_2_Photos_Album()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldUploadPhotosInAlbum);

            string[] captions = { "Logo", "Bot" };

            Message[] messages;
            using (Stream
                   stream1 = System.IO.File.OpenRead(Constants.FileNames.Photos.Logo),
                   stream2 = System.IO.File.OpenRead(Constants.FileNames.Photos.Bot)
                   )
            {
                InputMediaBase[] inputMedia =
                {
                    new InputMediaPhoto
                    {
                        Media   = new InputMedia(stream1, "logo"),
                        Caption = captions[0]
                    },
                    new InputMediaPhoto
                    {
                        Media   = new InputMedia(stream2, "bot"),
                        Caption = captions[1]
                    },
                };

                messages = await BotClient.SendMediaGroupAsync(
                    chatId : _fixture.SupergroupChat.Id,
                    media : inputMedia,
                    disableNotification : true
                    );
            }

            Assert.Equal(2, messages.Length);
            Assert.All(messages, msg => Assert.Equal(MessageType.Photo, msg.Type));
            Assert.NotEmpty(messages.Select(m => m.MediaGroupId));
            Assert.True(messages.Select(msg => msg.MediaGroupId).Distinct().Count() == 1);
            Assert.Equal(captions[0], messages[0].Caption);
            Assert.Equal(captions[1], messages[1].Caption);

            _classFixture.Entities = messages.ToList();
        }
        public async Task Should_Edit_Inline_Message_Text()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldEditInlineMessageText,
                                                         startInlineQuery : true);

            #region Answer Inline Query with an Article

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

            const string originalMessagePrefix = "original\n";
            (MessageEntityType Type, string Value)[] entityValueMappings =
예제 #5
0
        public async Task Should_Set_Webhook()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldSetWebhook);

            await BotClient.SetWebhookAsync("https://www.telegram.org/");

            await BotClient.DeleteWebhookAsync();
        }
예제 #6
0
        public async Task Should_Send_Photo_File()
        {
            await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldSendPhotoFile);

            Message message;

            using (Stream stream = System.IO.File.OpenRead(Constants.FileNames.Photos.Bot))
            {
                message = await BotClient.SendPhotoAsync(
                    chatId : _fixture.SupergroupChat.Id,
                    photo : stream,
                    caption : "👆 This is a\n" +
                    "Telegram Bot"
                    );
            }

            Assert.Equal(MessageType.Photo, message.Type);
            Assert.NotEmpty(message.Photo);
            Assert.All(message.Photo.Select(ps => ps.FileId), Assert.NotEmpty);
            Assert.All(message.Photo.Select(ps => ps.Width), w => Assert.NotEqual(default, w));
예제 #7
0
 public Task <Message> SendTestCaseNotificationAsync(string testcase, string instructions = null)
 {
     return(TestsFixture.SendTestCaseNotificationAsync(testcase, instructions, TesterPrivateChatId));
 }
예제 #8
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);
        }