├── .gitignore
├── LICENSE
├── NetTelegramBotApi.Tests
├── InlineKeyboardButtonTest.cs
└── NetTelegramBotApi.Tests.csproj
├── NetTelegramBotApi.sln
├── NetTelegramBotApi
├── BotRequestException.cs
├── BotResponse.cs
├── GlobalSuppressions.cs
├── IPostProcessingRequired.cs
├── ITelegramBot.cs
├── NetTelegramBotApi.csproj
├── Requests
│ ├── AnswerCallbackQuery.cs
│ ├── DeleteWebhook.cs
│ ├── EditMessageCaption.cs
│ ├── EditMessageReplyMarkup.cs
│ ├── EditMessageText.cs
│ ├── FileToSend.cs
│ ├── ForwardMessage.cs
│ ├── GetChat.cs
│ ├── GetChatAdministrators.cs
│ ├── GetChatMember.cs
│ ├── GetChatMembersCount.cs
│ ├── GetFile.cs
│ ├── GetGameHighScores.cs
│ ├── GetMe.cs
│ ├── GetUpdates.cs
│ ├── GetUserProfilePhotos.cs
│ ├── GetWebhookInfo.cs
│ ├── KickChatMember.cs
│ ├── LeaveChat.cs
│ ├── RequestBase.cs
│ ├── SendAudio.cs
│ ├── SendChatAction.cs
│ ├── SendContact.cs
│ ├── SendDocument.cs
│ ├── SendFileRequestBase.cs
│ ├── SendGame.cs
│ ├── SendLocation.cs
│ ├── SendMessage.cs
│ ├── SendPhoto.cs
│ ├── SendSticker.cs
│ ├── SendVenue.cs
│ ├── SendVideo.cs
│ ├── SendVoice.cs
│ ├── SetGameScore.cs
│ ├── SetWebhook.cs
│ ├── UnbanChatMember.cs
│ └── _Classes.cd
├── StringExtensions.cs
├── TelegramBot.cs
├── Types
│ ├── Animation.cs
│ ├── Audio.cs
│ ├── CallbackGame.cs
│ ├── CallbackQuery.cs
│ ├── Chat.cs
│ ├── ChatMember.cs
│ ├── ChatMemberStatus.cs
│ ├── ChatType.cs
│ ├── ChosenInlineResult.cs
│ ├── Contact.cs
│ ├── Document.cs
│ ├── File.cs
│ ├── ForceReply.cs
│ ├── Game.cs
│ ├── GameHighScore.cs
│ ├── InlineKeyboardButton.cs
│ ├── InlineKeyboardMarkup.cs
│ ├── InlineQuery.cs
│ ├── KeyboardButton.cs
│ ├── Location.cs
│ ├── Message.cs
│ ├── MessageEntity.cs
│ ├── MessageEntityType.cs
│ ├── PhotoSize.cs
│ ├── ReplyKeyboardMarkup.cs
│ ├── ReplyKeyboardRemove.cs
│ ├── ReplyMarkupBase.cs
│ ├── ResponseParameters.cs
│ ├── Sticker.cs
│ ├── Update.cs
│ ├── User.cs
│ ├── UserProfilePhotos.cs
│ ├── Venue.cs
│ ├── Video.cs
│ ├── Voice.cs
│ ├── WebAppInfo.cs
│ └── WebhookInfo.cs
└── Util
│ └── UnixdateTimeConverter.cs
├── README.md
├── Settings.StyleCop
├── TelegramBotDemo-vNext
├── Program.cs
├── Properties
│ └── launchSettings.json
├── TelegramBotDemo-vNext.csproj
├── Telegram_Bot_API.htm
├── config.json
├── t_logo.png
└── Пример_UTF8_filename.txt
├── appveyor.yml
├── package-icon.gif
└── package-icon.png
/.gitignore:
--------------------------------------------------------------------------------
1 | /packages
2 | /NetTelegramBotApi.v12.suo
3 | bin
4 | obj
5 | *.user
6 | StyleCop.Cache
7 | /*.nupkg
8 | /.vs
9 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2015 Dmitry Popov
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/NetTelegramBotApi.Tests/InlineKeyboardButtonTest.cs:
--------------------------------------------------------------------------------
1 | namespace NetTelegramBotApi
2 | {
3 | using System.Net;
4 | using System.Threading.Tasks;
5 | using NetTelegramBotApi.Requests;
6 | using NetTelegramBotApi.Types;
7 | using Xunit;
8 |
9 | public class InlineKeyboardButtonTest
10 | {
11 | ///
12 | /// Test for Issue #46
13 | ///
14 | [Fact]
15 | public async Task CallbackData_SerializedOk()
16 | {
17 | var keyb = new InlineKeyboardMarkup()
18 | {
19 | InlineKeyboard = [[new InlineKeyboardButton { Text = "test", CallbackData = "123" }]],
20 | };
21 | var reqAction = new SendMessage(123, "Hello") { ReplyMarkup = keyb };
22 |
23 | var submitText = await reqAction.CreateHttpContent().ReadAsStringAsync();
24 |
25 | var encoded = WebUtility.UrlEncode("{\"inline_keyboard\":[[{\"text\":\"test\",\"callback_data\":\"123\"}]]}");
26 | Assert.Equal($"chat_id=123&text=Hello&reply_markup={encoded}", submitText);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/NetTelegramBotApi.Tests/NetTelegramBotApi.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | NetTelegramBotApi
6 |
7 |
8 |
9 |
10 |
11 |
12 | all
13 | runtime; build; native; contentfiles; analyzers; buildtransitive
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/NetTelegramBotApi.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio Version 16
3 | VisualStudioVersion = 16.0.31313.79
4 | MinimumVisualStudioVersion = 10.0.40219.1
5 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{ABC2A4CB-9443-434E-B2EA-E739D288F330}"
6 | ProjectSection(SolutionItems) = preProject
7 | appveyor.yml = appveyor.yml
8 | LICENSE = LICENSE
9 | README.md = README.md
10 | EndProjectSection
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetTelegramBotApi", "NetTelegramBotApi\NetTelegramBotApi.csproj", "{0CA802AD-0F85-4314-8D70-2C5F182C9F42}"
13 | EndProject
14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TelegramBotDemo-vNext", "TelegramBotDemo-vNext\TelegramBotDemo-vNext.csproj", "{0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}"
15 | EndProject
16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetTelegramBotApi.Tests", "NetTelegramBotApi.Tests\NetTelegramBotApi.Tests.csproj", "{82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}"
17 | EndProject
18 | Global
19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
20 | Debug|Any CPU = Debug|Any CPU
21 | Debug|x64 = Debug|x64
22 | Debug|x86 = Debug|x86
23 | Release|Any CPU = Release|Any CPU
24 | Release|x64 = Release|x64
25 | Release|x86 = Release|x86
26 | EndGlobalSection
27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
28 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Debug|x64.ActiveCfg = Debug|Any CPU
31 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Debug|x64.Build.0 = Debug|Any CPU
32 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Debug|x86.ActiveCfg = Debug|Any CPU
33 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Debug|x86.Build.0 = Debug|Any CPU
34 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Release|x64.ActiveCfg = Release|Any CPU
37 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Release|x64.Build.0 = Release|Any CPU
38 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Release|x86.ActiveCfg = Release|Any CPU
39 | {0CA802AD-0F85-4314-8D70-2C5F182C9F42}.Release|x86.Build.0 = Release|Any CPU
40 | {0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}.Debug|x64.ActiveCfg = Debug|Any CPU
43 | {0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}.Debug|x64.Build.0 = Debug|Any CPU
44 | {0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}.Debug|x86.ActiveCfg = Debug|Any CPU
45 | {0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}.Debug|x86.Build.0 = Debug|Any CPU
46 | {0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}.Release|x64.ActiveCfg = Release|Any CPU
49 | {0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}.Release|x64.Build.0 = Release|Any CPU
50 | {0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}.Release|x86.ActiveCfg = Release|Any CPU
51 | {0A5DF37F-F6E0-412E-8B84-AE7120B4D8C5}.Release|x86.Build.0 = Release|Any CPU
52 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Debug|x64.ActiveCfg = Debug|Any CPU
55 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Debug|x64.Build.0 = Debug|Any CPU
56 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Debug|x86.ActiveCfg = Debug|Any CPU
57 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Debug|x86.Build.0 = Debug|Any CPU
58 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
59 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Release|Any CPU.Build.0 = Release|Any CPU
60 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Release|x64.ActiveCfg = Release|Any CPU
61 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Release|x64.Build.0 = Release|Any CPU
62 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Release|x86.ActiveCfg = Release|Any CPU
63 | {82AAECA1-D92F-4C7D-9CA8-B9EBACCCCCAF}.Release|x86.Build.0 = Release|Any CPU
64 | EndGlobalSection
65 | GlobalSection(SolutionProperties) = preSolution
66 | HideSolutionNode = FALSE
67 | EndGlobalSection
68 | GlobalSection(ExtensibilityGlobals) = postSolution
69 | SolutionGuid = {1AE94356-8779-4DAE-A0A5-7F6DE8FC7E48}
70 | EndGlobalSection
71 | EndGlobal
72 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/BotRequestException.cs:
--------------------------------------------------------------------------------
1 | namespace NetTelegramBotApi
2 | {
3 | using System;
4 | using System.Net;
5 | using NetTelegramBotApi.Types;
6 |
7 | public class BotRequestException : Exception
8 | {
9 | public BotRequestException()
10 | : base()
11 | {
12 | // Nothing
13 | }
14 |
15 | public BotRequestException(string message)
16 | : base(message)
17 | {
18 | // Nothing
19 | }
20 |
21 | public BotRequestException(string message, Exception inner)
22 | : base(message, inner)
23 | {
24 | // Nothing
25 | }
26 |
27 | ///
28 | /// HTTP Status Code retuned by server.
29 | ///
30 | public HttpStatusCode StatusCode { get; set; }
31 |
32 | ///
33 | /// Response body text.
34 | ///
35 | public string ResponseBody { get; set; }
36 |
37 | ///
38 | /// Optional. Human-readable description of the result (by Telegram).
39 | ///
40 | public string Description { get; set; }
41 |
42 | ///
43 | /// Contents are subject to change in the future (by Telegram).
44 | ///
45 | public long? ErrorCode { get; set; }
46 |
47 | ///
48 | /// Optional. Can help to automatically handle the error.
49 | ///
50 | public ResponseParameters Parameters { get; set; }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/BotResponse.cs:
--------------------------------------------------------------------------------
1 | using NetTelegramBotApi.Types;
2 |
3 | namespace NetTelegramBotApi
4 | {
5 | public class BotResponse
6 | {
7 | public bool Ok { get; set; }
8 |
9 | public string Description { get; set; }
10 |
11 | public T Result { get; set; }
12 |
13 | public long? ErrorCode { get; set; }
14 |
15 | public ResponseParameters Parameters { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
1 | // This file is used by Code Analysis to maintain SuppressMessage
2 | // attributes that are applied to this project.
3 | // Project-level suppressions either have no target or are given
4 | // a specific target and scoped to a namespace, type, member, etc.
5 |
6 | using System.Diagnostics.CodeAnalysis;
7 |
8 | [assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this", Justification = "Sorry, no")]
9 |
10 | [assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:Using directives should be placed correctly", Justification = "I'm lazy")]
11 |
12 | [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "I'm lazy")]
13 | [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:Enumeration items should be documented", Justification = "I'm lazy")]
14 | [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1615:Element return value should be documented", Justification = "I'm lazy")]
15 | [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:Property summary documentation should match accessors", Justification = "I'm lazy")]
16 | [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "I'm lazy")]
17 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/IPostProcessingRequired.cs:
--------------------------------------------------------------------------------
1 | namespace NetTelegramBotApi
2 | {
3 | ///
4 | /// Implemented by Types, which require additional post-processing after receiving from server.
5 | ///
6 | public interface IPostProcessingRequired
7 | {
8 | void PostProcess(string accessToken);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/ITelegramBot.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using NetTelegramBotApi.Requests;
3 | using NetTelegramBotApi.Types;
4 |
5 | namespace NetTelegramBotApi
6 | {
7 | public interface ITelegramBot
8 | {
9 | Task MakeRequestAsync(RequestBase request);
10 |
11 | Update DeserializeUpdate(string json);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/NetTelegramBotApi.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Telegram Bot API library
5 | NetTelegramBotApi
6 | 6.0.1
7 | net8.0
8 | NetTelegramBotApi
9 | NetTelegramBotApi
10 | telegram;bot;api
11 | Some internal refacatoring and optimizations.
12 | package-icon.png
13 | https://github.com/justdmitry/NetTelegramBotApi
14 | git
15 | https://github.com/justdmitry/NetTelegramBotApi.git
16 | Dmitry Popov
17 |
18 | Copyright © Dmitry Popov, 2015-2024
19 | True
20 | MIT
21 | README.md
22 |
23 |
24 |
25 |
26 | all
27 | runtime; build; native; contentfiles; analyzers; buildtransitive
28 |
29 |
30 |
31 |
32 |
33 |
34 | True
35 |
36 |
37 |
38 | True
39 | \
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/AnswerCallbackQuery.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Globalization;
3 | using System.Net.Http;
4 |
5 | namespace NetTelegramBotApi.Requests
6 | {
7 | ///
8 | /// Use this method to send answers to callback queries sent from inline keyboards.
9 | /// The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
10 | /// On success, True is returned.
11 | ///
12 | public class AnswerCallbackQuery : RequestBase
13 | {
14 | public AnswerCallbackQuery(string callbackQueryId)
15 | : base("answerCallbackQuery")
16 | {
17 | this.CallbackQueryId = callbackQueryId;
18 | }
19 |
20 | ///
21 | /// Unique identifier for the query to be answered.
22 | ///
23 | public string CallbackQueryId { get; protected set; }
24 |
25 | ///
26 | /// Optional. Text of the notification. If not specified, nothing will be shown to the user.
27 | ///
28 | public string Text { get; set; }
29 |
30 | ///
31 | /// Optional. If true, an alert will be shown by the client instead of a notification at the top of the chat screen.
32 | /// Defaults to false.
33 | ///
34 | public bool? ShowAlert { get; set; }
35 |
36 | ///
37 | /// Optional. URL that will be opened by the user's client.
38 | /// If you have created a Game and accepted the conditions via @Botfather,
39 | /// specify the URL that opens your game – note that this will only work if the query comes from a callback_game button.
40 | /// Otherwise, you may use links like telegram.me/your_bot?start=XXXX that open your bot with a parameter.
41 | ///
42 | public string Url { get; set; }
43 |
44 | ///
45 | /// The maximum amount of time in seconds that the result of the callback query may be cached client-side.
46 | /// Telegram apps will support caching starting in version 3.14. Defaults to 0.
47 | ///
48 | public long CacheTime { get; set; }
49 |
50 | public override HttpContent CreateHttpContent()
51 | {
52 | var dic = new Dictionary();
53 | dic.Add("callback_query_id", CallbackQueryId);
54 | if (!string.IsNullOrEmpty(Text))
55 | {
56 | dic.Add("text", Text);
57 | }
58 |
59 | if (ShowAlert.HasValue)
60 | {
61 | dic.Add("show_alert", ShowAlert.Value.ToString());
62 | }
63 |
64 | if (!string.IsNullOrEmpty(Url))
65 | {
66 | dic.Add("url", Url);
67 | }
68 |
69 | dic.Add("cache_time", CacheTime.ToString(CultureInfo.InvariantCulture));
70 |
71 | return new FormUrlEncodedContent(dic);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/DeleteWebhook.cs:
--------------------------------------------------------------------------------
1 | namespace NetTelegramBotApi.Requests
2 | {
3 | using System.Net.Http;
4 |
5 | public class DeleteWebhook : RequestBase
6 | {
7 | public DeleteWebhook()
8 | : base("deleteWebhook")
9 | {
10 | // Nothing
11 | }
12 |
13 | public override HttpContent CreateHttpContent()
14 | {
15 | return null;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/EditMessageCaption.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Net.Http;
5 | using NetTelegramBotApi.Types;
6 |
7 | namespace NetTelegramBotApi.Requests
8 | {
9 | ///
10 | /// Use this method to edit captions of messages sent by the bot or via the bot (for inline bots).
11 | /// On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
12 | ///
13 | public class EditMessageCaption : RequestBase
14 | {
15 | public EditMessageCaption(long chatId, long messageId, string caption)
16 | : base("editMessageCaption")
17 | {
18 | this.ChatId = chatId;
19 | this.MessageId = messageId;
20 | this.Caption = caption;
21 | }
22 |
23 | public EditMessageCaption(string channelName, long messageId, string caption)
24 | : base("editMessageCaption")
25 | {
26 | this.ChannelName = channelName;
27 | this.MessageId = messageId;
28 | this.Caption = caption;
29 | }
30 |
31 | public EditMessageCaption(long inlineMessageId, string caption)
32 | : base("editMessageCaption")
33 | {
34 | this.InlineMessageId = inlineMessageId;
35 | this.Caption = caption;
36 | }
37 |
38 | ///
39 | /// Optional. Required if inline_message_id is not specified. Unique identifier for the target chat.
40 | ///
41 | public long? ChatId { get; protected set; }
42 |
43 | ///
44 | /// Optional. Required if inline_message_id is not specified. Username of the target channel.
45 | ///
46 | public string ChannelName { get; protected set; }
47 |
48 | ///
49 | /// Optional. Required if inline_message_id is not specified. Identifier of the sent message.
50 | ///
51 | public long? MessageId { get; protected set; }
52 |
53 | ///
54 | /// Optional. Required if chat_id and message_id are not specified. Identifier of the inline message.
55 | ///
56 | public long? InlineMessageId { get; protected set; }
57 |
58 | ///
59 | /// Optional. New caption of the message.
60 | ///
61 | public string Caption { get; set; }
62 |
63 | ///
64 | /// Optional. A JSON-serialized object for an inline keyboard.
65 | ///
66 | public InlineKeyboardMarkup ReplyMarkup { get; set; }
67 |
68 | public override HttpContent CreateHttpContent()
69 | {
70 | if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
71 | {
72 | throw new InvalidOperationException("Use ChatId or ChannelName, not both.");
73 | }
74 |
75 | var dic = new Dictionary();
76 |
77 | if (ChatId.HasValue)
78 | {
79 | dic.Add("chat_id", ChatId.Value.ToString(CultureInfo.InvariantCulture));
80 | }
81 |
82 | if (!string.IsNullOrEmpty(ChannelName))
83 | {
84 | dic.Add("chat_id", ChannelName);
85 | }
86 |
87 | if (MessageId.HasValue)
88 | {
89 | dic.Add("message_id", MessageId.Value.ToString(CultureInfo.InvariantCulture));
90 | }
91 |
92 | if (InlineMessageId.HasValue)
93 | {
94 | dic.Add("inline_message_id", InlineMessageId.Value.ToString(CultureInfo.InvariantCulture));
95 | }
96 |
97 | dic.Add("caption", Caption);
98 |
99 | if (ReplyMarkup != null)
100 | {
101 | dic.Add("reply_markup", JsonSerialize(ReplyMarkup));
102 | }
103 |
104 | return new FormUrlEncodedContent(dic);
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/EditMessageReplyMarkup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Net.Http;
5 | using NetTelegramBotApi.Types;
6 |
7 | namespace NetTelegramBotApi.Requests
8 | {
9 | ///
10 | /// Use this method to edit captions of messages sent by the bot or via the bot (for inline bots).
11 | /// On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
12 | ///
13 | public class EditMessageReplyMarkup : RequestBase
14 | {
15 | public EditMessageReplyMarkup(long chatId, long messageId, InlineKeyboardMarkup replyMarkup)
16 | : base("editMessageReplyMarkup")
17 | {
18 | this.ChatId = chatId;
19 | this.MessageId = messageId;
20 | this.ReplyMarkup = replyMarkup;
21 | }
22 |
23 | public EditMessageReplyMarkup(string channelName, long messageId, InlineKeyboardMarkup replyMarkup)
24 | : base("editMessageReplyMarkup")
25 | {
26 | this.ChannelName = channelName;
27 | this.MessageId = messageId;
28 | this.ReplyMarkup = replyMarkup;
29 | }
30 |
31 | public EditMessageReplyMarkup(long inlineMessageId, InlineKeyboardMarkup replyMarkup)
32 | : base("editMessageReplyMarkup")
33 | {
34 | this.InlineMessageId = inlineMessageId;
35 | this.ReplyMarkup = replyMarkup;
36 | }
37 |
38 | ///
39 | /// Optional. Required if inline_message_id is not specified. Unique identifier for the target chat.
40 | ///
41 | public long? ChatId { get; protected set; }
42 |
43 | ///
44 | /// Optional. Required if inline_message_id is not specified. Username of the target channel.
45 | ///
46 | public string ChannelName { get; protected set; }
47 |
48 | ///
49 | /// Optional. Required if inline_message_id is not specified. Identifier of the sent message.
50 | ///
51 | public long? MessageId { get; protected set; }
52 |
53 | ///
54 | /// Optional. Required if chat_id and message_id are not specified. Identifier of the inline message.
55 | ///
56 | public long? InlineMessageId { get; protected set; }
57 |
58 | ///
59 | /// Optional. A JSON-serialized object for an inline keyboard.
60 | ///
61 | public InlineKeyboardMarkup ReplyMarkup { get; set; }
62 |
63 | public override HttpContent CreateHttpContent()
64 | {
65 | if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
66 | {
67 | throw new InvalidOperationException("Use ChatId or ChannelName, not both.");
68 | }
69 |
70 | var dic = new Dictionary();
71 |
72 | if (ChatId.HasValue)
73 | {
74 | dic.Add("chat_id", ChatId.Value.ToString(CultureInfo.InvariantCulture));
75 | }
76 |
77 | if (!string.IsNullOrEmpty(ChannelName))
78 | {
79 | dic.Add("chat_id", ChannelName);
80 | }
81 |
82 | if (MessageId.HasValue)
83 | {
84 | dic.Add("message_id", MessageId.Value.ToString(CultureInfo.InvariantCulture));
85 | }
86 |
87 | if (InlineMessageId.HasValue)
88 | {
89 | dic.Add("inline_message_id", InlineMessageId.Value.ToString(CultureInfo.InvariantCulture));
90 | }
91 |
92 | if (ReplyMarkup != null)
93 | {
94 | dic.Add("reply_markup", JsonSerialize(ReplyMarkup));
95 | }
96 |
97 | return new FormUrlEncodedContent(dic);
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/EditMessageText.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Net.Http;
5 | using NetTelegramBotApi.Types;
6 |
7 | namespace NetTelegramBotApi.Requests
8 | {
9 | ///
10 | /// Use this method to edit text and game messages sent by the bot or via the bot (for inline bots).
11 | /// On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
12 | ///
13 | public class EditMessageText : RequestBase
14 | {
15 | public EditMessageText(long chatId, long messageId, string text)
16 | : base("editMessageText")
17 | {
18 | this.ChatId = chatId;
19 | this.MessageId = messageId;
20 | this.Text = text;
21 | }
22 |
23 | public EditMessageText(string channelName, long messageId, string text)
24 | : base("editMessageText")
25 | {
26 | this.ChannelName = channelName;
27 | this.MessageId = messageId;
28 | this.Text = text;
29 | }
30 |
31 | public EditMessageText(long inlineMessageId, string text)
32 | : base("editMessageText")
33 | {
34 | this.InlineMessageId = inlineMessageId;
35 | this.Text = text;
36 | }
37 |
38 | ///
39 | /// Optional. Required if inline_message_id is not specified. Unique identifier for the target chat.
40 | ///
41 | public long? ChatId { get; protected set; }
42 |
43 | ///
44 | /// Optional. Required if inline_message_id is not specified. Username of the target channel.
45 | ///
46 | public string ChannelName { get; protected set; }
47 |
48 | ///
49 | /// Optional. Required if inline_message_id is not specified. Identifier of the sent message.
50 | ///
51 | public long? MessageId { get; protected set; }
52 |
53 | ///
54 | /// Optional. Required if chat_id and message_id are not specified. Identifier of the inline message.
55 | ///
56 | public long? InlineMessageId { get; protected set; }
57 |
58 | ///
59 | /// New text of the message.
60 | ///
61 | public string Text { get; set; }
62 |
63 | ///
64 | /// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or
65 | /// inline URLs in your bot's message.
66 | ///
67 | public SendMessage.ParseModes ParseMode { get; set; }
68 |
69 | ///
70 | /// Optional. Disables link previews for links in this message.
71 | ///
72 | public bool? DisableWebPagePreview { get; set; }
73 |
74 | ///
75 | /// Optional. A JSON-serialized object for an inline keyboard.
76 | ///
77 | public InlineKeyboardMarkup ReplyMarkup { get; set; }
78 |
79 | public override HttpContent CreateHttpContent()
80 | {
81 | if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
82 | {
83 | throw new InvalidOperationException("Use ChatId or ChannelName, not both.");
84 | }
85 |
86 | var dic = new Dictionary();
87 |
88 | if (ChatId.HasValue)
89 | {
90 | dic.Add("chat_id", ChatId.Value.ToString(CultureInfo.InvariantCulture));
91 | }
92 |
93 | if (!string.IsNullOrEmpty(ChannelName))
94 | {
95 | dic.Add("chat_id", ChannelName);
96 | }
97 |
98 | if (MessageId.HasValue)
99 | {
100 | dic.Add("message_id", MessageId.Value.ToString(CultureInfo.InvariantCulture));
101 | }
102 |
103 | if (InlineMessageId.HasValue)
104 | {
105 | dic.Add("inline_message_id", InlineMessageId.Value.ToString(CultureInfo.InvariantCulture));
106 | }
107 |
108 | dic.Add("text", Text);
109 |
110 | if (ParseMode == SendMessage.ParseModes.Markdown)
111 | {
112 | dic.Add("parse_mode", "Markdown");
113 | }
114 |
115 | if (ParseMode == SendMessage.ParseModes.HTML)
116 | {
117 | dic.Add("parse_mode", "HTML");
118 | }
119 |
120 | if (DisableWebPagePreview.HasValue)
121 | {
122 | dic.Add("disable_web_page_preview", DisableWebPagePreview.Value.ToString());
123 | }
124 |
125 | if (ReplyMarkup != null)
126 | {
127 | dic.Add("reply_markup", JsonSerialize(ReplyMarkup));
128 | }
129 |
130 | return new FormUrlEncodedContent(dic);
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/FileToSend.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace NetTelegramBotApi.Requests
4 | {
5 | public class FileToSend
6 | {
7 | ///
8 | /// If the file is already stored somewhere on the Telegram servers, you don't need to reupload it:
9 | /// each file object has a file_id field, simply pass this file_id as a parameter instead of uploading.
10 | /// There are no limits for files sent this way.
11 | ///
12 | ///
13 | /// Since October 2016, provide Telegram with an HTTP URL for the file to be sent.
14 | /// Telegram will download and send the file. 5 MB max size for photos and 20 MB max for other types of content.
15 | ///
16 | public FileToSend(string existingFileId)
17 | {
18 | this.AlreadyUploaded = true;
19 | this.ExistingFileId = existingFileId;
20 | }
21 |
22 | ///
23 | /// Post the file using multipart/form-data in the usual way that files are uploaded via the browser.
24 | /// 10 MB max size for photos, 50 MB for other files.
25 | ///
26 | public FileToSend(Stream fileContent, string fileName)
27 | {
28 | this.AlreadyUploaded = false;
29 | this.NewFileContent = fileContent;
30 | this.NewFileName = fileName;
31 | }
32 |
33 | ///
34 | /// True, if file is already uploaded to server, only is used.
35 | /// Otherwise, and are used.
36 | ///
37 | public bool AlreadyUploaded { get; private set; }
38 |
39 | public string ExistingFileId { get; private set; }
40 |
41 | public Stream NewFileContent { get; private set; }
42 |
43 | public string NewFileName { get; private set; }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/ForwardMessage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Net.Http;
5 | using NetTelegramBotApi.Types;
6 |
7 | namespace NetTelegramBotApi.Requests
8 | {
9 | ///
10 | /// Use this method to forward messages of any kind. On success, the sent Message is returned.
11 | ///
12 | public class ForwardMessage : RequestBase
13 | {
14 | public ForwardMessage(long chatId, long fromChatId, long messageId)
15 | : base("forwardMessage")
16 | {
17 | this.ChatId = chatId;
18 | this.FromChatId = fromChatId;
19 | this.MessageId = messageId;
20 | }
21 |
22 | public ForwardMessage(long chatId, string fromChannelName, long messageId)
23 | : base("forwardMessage")
24 | {
25 | this.ChatId = chatId;
26 | this.FromChannelName = fromChannelName;
27 | this.MessageId = messageId;
28 | }
29 |
30 | public ForwardMessage(string channelName, long fromChatId, long messageId)
31 | : base("forwardMessage")
32 | {
33 | this.ChannelName = channelName;
34 | this.FromChatId = fromChatId;
35 | this.MessageId = messageId;
36 | }
37 |
38 | public ForwardMessage(string channelName, string fromChannelName, long messageId)
39 | : base("forwardMessage")
40 | {
41 | this.ChannelName = channelName;
42 | this.FromChannelName = fromChannelName;
43 | this.MessageId = messageId;
44 | }
45 |
46 | ///
47 | /// Unique identifier for the target chat.
48 | ///
49 | public long? ChatId { get; set; }
50 |
51 | ///
52 | /// Unique identifier for target channel (in the format @channelusername).
53 | ///
54 | public string ChannelName { get; set; }
55 |
56 | ///
57 | /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only.
58 | ///
59 | public long? MessageThreadId { get; set; }
60 |
61 | ///
62 | /// Unique identifier for the chat where the original message was sent — User or GroupChat id.
63 | ///
64 | public long? FromChatId { get; set; }
65 |
66 | ///
67 | /// Unique identifier for the chat where the original message was sent - channel username in the format @channelusername).
68 | ///
69 | public string FromChannelName { get; set; }
70 |
71 | ///
72 | /// Sends the message silently.
73 | /// iOS users will not receive a notification, Android users will receive a notification with no sound.
74 | ///
75 | public bool? DisableNotification { get; set; }
76 |
77 | ///
78 | /// Unique message identifier.
79 | ///
80 | public long MessageId { get; set; }
81 |
82 | public override HttpContent CreateHttpContent()
83 | {
84 | if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
85 | {
86 | throw new InvalidOperationException("Use ChatId or ChannelName, not both.");
87 | }
88 |
89 | if (FromChatId.HasValue && !string.IsNullOrEmpty(FromChannelName))
90 | {
91 | throw new InvalidOperationException("Use FromChatId or FromChannelName, not both.");
92 | }
93 |
94 | var dic = new Dictionary();
95 |
96 | if (ChatId.HasValue)
97 | {
98 | dic.Add("chat_id", ChatId.Value.ToString(CultureInfo.InvariantCulture));
99 | }
100 |
101 | if (!string.IsNullOrEmpty(ChannelName))
102 | {
103 | dic.Add("chat_id", ChannelName);
104 | }
105 |
106 | if (MessageThreadId.HasValue)
107 | {
108 | dic.Add("message_thread_id", MessageThreadId.Value.ToString(CultureInfo.InvariantCulture));
109 | }
110 |
111 | if (FromChatId.HasValue)
112 | {
113 | dic.Add("from_chat_id", FromChatId.Value.ToString(CultureInfo.InvariantCulture));
114 | }
115 |
116 | if (!string.IsNullOrEmpty(FromChannelName))
117 | {
118 | dic.Add("from_chat_id", FromChannelName);
119 | }
120 |
121 | if (DisableNotification.HasValue)
122 | {
123 | dic.Add("disable_notification", DisableNotification.Value.ToString());
124 | }
125 |
126 | dic.Add("message_id", MessageId.ToString(CultureInfo.InvariantCulture));
127 |
128 | return new FormUrlEncodedContent(dic);
129 | }
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/GetChat.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Net.Http;
5 | using NetTelegramBotApi.Types;
6 |
7 | namespace NetTelegramBotApi.Requests
8 | {
9 | ///
10 | /// Use this method to get up to date information about the chat
11 | /// (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).
12 | ///
13 | public class GetChat : RequestBase
14 | {
15 | public GetChat(long chatId)
16 | : base("getChat")
17 | {
18 | this.ChatId = chatId;
19 | }
20 |
21 | public GetChat(string channelName)
22 | : base("getChat")
23 | {
24 | this.ChannelName = channelName;
25 | }
26 |
27 | ///
28 | /// Unique identifier for the target chat.
29 | ///
30 | public long? ChatId { get; protected set; }
31 |
32 | ///
33 | /// Username of the target supergroup or channel (in the format @channelusername).
34 | ///
35 | public string ChannelName { get; set; }
36 |
37 | public override HttpContent CreateHttpContent()
38 | {
39 | if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
40 | {
41 | throw new InvalidOperationException("Use ChatId or ChannelName, not both.");
42 | }
43 |
44 | var dic = new Dictionary();
45 |
46 | if (ChatId.HasValue)
47 | {
48 | dic.Add("chat_id", ChatId.Value.ToString(CultureInfo.InvariantCulture));
49 | }
50 |
51 | if (!string.IsNullOrEmpty(ChannelName))
52 | {
53 | dic.Add("chat_id", ChannelName);
54 | }
55 |
56 | return new FormUrlEncodedContent(dic);
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/GetChatAdministrators.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Net.Http;
5 | using NetTelegramBotApi.Types;
6 |
7 | namespace NetTelegramBotApi.Requests
8 | {
9 | ///
10 | /// Use this method to get a list of administrators in a chat.
11 | /// On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots.
12 | /// If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.
13 | ///
14 | public class GetChatAdministrators : RequestBase
15 | {
16 | public GetChatAdministrators(long chatId)
17 | : base("getChatAdministrators")
18 | {
19 | this.ChatId = chatId;
20 | }
21 |
22 | public GetChatAdministrators(string channelName)
23 | : base("getChatAdministrators")
24 | {
25 | this.ChannelName = channelName;
26 | }
27 |
28 | ///
29 | /// Unique identifier for the target chat.
30 | ///
31 | public long? ChatId { get; protected set; }
32 |
33 | ///
34 | /// Username of the target supergroup or channel (in the format @channelusername).
35 | ///
36 | public string ChannelName { get; set; }
37 |
38 | public override HttpContent CreateHttpContent()
39 | {
40 | if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
41 | {
42 | throw new InvalidOperationException("Use ChatId or ChannelName, not both.");
43 | }
44 |
45 | var dic = new Dictionary();
46 |
47 | if (ChatId.HasValue)
48 | {
49 | dic.Add("chat_id", ChatId.Value.ToString(CultureInfo.InvariantCulture));
50 | }
51 |
52 | if (!string.IsNullOrEmpty(ChannelName))
53 | {
54 | dic.Add("chat_id", ChannelName);
55 | }
56 |
57 | return new FormUrlEncodedContent(dic);
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/GetChatMember.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Net.Http;
5 | using NetTelegramBotApi.Types;
6 |
7 | namespace NetTelegramBotApi.Requests
8 | {
9 | ///
10 | /// Use this method to get information about a member of a chat. Returns a ChatMember object on success.
11 | ///
12 | public class GetChatMember : RequestBase
13 | {
14 | public GetChatMember(long chatId, long userId)
15 | : base("getChatMember")
16 | {
17 | this.ChatId = chatId;
18 | this.UserId = userId;
19 | }
20 |
21 | public GetChatMember(string channelName, long userId)
22 | : base("getChatMember")
23 | {
24 | this.ChannelName = channelName;
25 | this.UserId = userId;
26 | }
27 |
28 | ///
29 | /// Unique identifier for the target chat.
30 | ///
31 | public long? ChatId { get; protected set; }
32 |
33 | ///
34 | /// Username of the target channel (in the format @channelusername).
35 | ///
36 | public string ChannelName { get; set; }
37 |
38 | ///
39 | /// Unique identifier of the target user.
40 | ///
41 | public long UserId { get; set; }
42 |
43 | public override HttpContent CreateHttpContent()
44 | {
45 | if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
46 | {
47 | throw new InvalidOperationException("Use ChatId or ChannelName, not both.");
48 | }
49 |
50 | var dic = new Dictionary();
51 |
52 | if (ChatId.HasValue)
53 | {
54 | dic.Add("chat_id", ChatId.Value.ToString(CultureInfo.InvariantCulture));
55 | }
56 |
57 | if (!string.IsNullOrEmpty(ChannelName))
58 | {
59 | dic.Add("chat_id", ChannelName);
60 | }
61 |
62 | dic.Add("user_id", UserId.ToString(CultureInfo.InvariantCulture));
63 |
64 | return new FormUrlEncodedContent(dic);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/GetChatMembersCount.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Net.Http;
5 |
6 | namespace NetTelegramBotApi.Requests
7 | {
8 | ///
9 | /// Use this method to get the number of members in a chat. Returns Int on success.
10 | ///
11 | public class GetChatMembersCount : RequestBase
12 | {
13 | public GetChatMembersCount(long chatId)
14 | : base("getChatMembersCount")
15 | {
16 | this.ChatId = chatId;
17 | }
18 |
19 | public GetChatMembersCount(string channelName)
20 | : base("getChatMembersCount")
21 | {
22 | this.ChannelName = channelName;
23 | }
24 |
25 | ///
26 | /// Unique identifier for the target chat.
27 | ///
28 | public long? ChatId { get; protected set; }
29 |
30 | ///
31 | /// Username of the target supergroup or channel (in the format @channelusername).
32 | ///
33 | public string ChannelName { get; set; }
34 |
35 | public override HttpContent CreateHttpContent()
36 | {
37 | if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
38 | {
39 | throw new InvalidOperationException("Use ChatId or ChannelName, not both.");
40 | }
41 |
42 | var dic = new Dictionary();
43 |
44 | if (ChatId.HasValue)
45 | {
46 | dic.Add("chat_id", ChatId.Value.ToString(CultureInfo.InvariantCulture));
47 | }
48 |
49 | if (!string.IsNullOrEmpty(ChannelName))
50 | {
51 | dic.Add("chat_id", ChannelName);
52 | }
53 |
54 | return new FormUrlEncodedContent(dic);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/GetFile.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Net.Http;
3 | using NetTelegramBotApi.Types;
4 |
5 | namespace NetTelegramBotApi.Requests
6 | {
7 | ///
8 | /// Use this method to get basic info about a file and prepare it for downloading.
9 | /// For the moment, bots can download files of up to 20MB in size.
10 | /// On success, a object is returned.
11 | /// The file can then be downloaded via the link https://api.telegram.org/file/bot/, where is taken from the response.
12 | /// It is guaranteed that the link will be valid for at least 1 hour.
13 | /// When the link expires, a new one can be requested by calling getFile again.
14 | ///
15 | public class GetFile : RequestBase
16 | {
17 | public GetFile(string fileId)
18 | : base("getFile")
19 | {
20 | this.FileId = fileId;
21 | }
22 |
23 | ///
24 | /// File identifier to get info about
25 | ///
26 | public string FileId { get; set; }
27 |
28 | public override HttpContent CreateHttpContent()
29 | {
30 | var values = new[]
31 | {
32 | new KeyValuePair("file_id", FileId),
33 | };
34 | return new FormUrlEncodedContent(values);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/GetGameHighScores.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Net.Http;
5 | using NetTelegramBotApi.Types;
6 |
7 | namespace NetTelegramBotApi.Requests
8 | {
9 | ///
10 | /// Use this method to get data for high score tables.
11 | /// Will return the score of the specified user and several of his neighbors in a game.
12 | /// On success, returns an Array of GameHighScore objects.
13 | ///
14 | ///
15 | /// This method will currently return scores for the target user, plus two of his closest neighbors on each side.
16 | /// Will also return the top three users if the user and his neighbors are not among them.
17 | /// Please note that this behavior is subject to change.
18 | ///
19 | public class GetGameHighScores : RequestBase
20 | {
21 | public GetGameHighScores(long userId)
22 | : base("getGameHighScores")
23 | {
24 | this.UserId = userId;
25 | }
26 |
27 | ///
28 | /// Target user id.
29 | ///
30 | public long UserId { get; protected set; }
31 |
32 | ///
33 | /// Required if inline_message_id is not specified. Unique identifier for the target chat.
34 | ///
35 | public long? ChatId { get; protected set; }
36 |
37 | ///
38 | /// Required if inline_message_id is not specified. Unique identifier for the target chat.
39 | ///
40 | public string ChannelName { get; set; }
41 |
42 | ///
43 | /// Required if inline_message_id is not specified. Identifier of the sent message.
44 | ///
45 | public long? MessageId { get; set; }
46 |
47 | ///
48 | /// Required if chat_id and message_id are not specified. Identifier of the inline message.
49 | ///
50 | public string InlineMessageId { get; set; }
51 |
52 | public override HttpContent CreateHttpContent()
53 | {
54 | if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
55 | {
56 | throw new InvalidOperationException("Use ChatId or ChannelName, not both.");
57 | }
58 |
59 | var dic = new Dictionary();
60 |
61 | dic.Add("user_id", UserId.ToString(CultureInfo.InvariantCulture));
62 |
63 | if (ChatId.HasValue)
64 | {
65 | dic.Add("chat_id", ChatId.Value.ToString(CultureInfo.InvariantCulture));
66 | }
67 |
68 | if (!string.IsNullOrEmpty(ChannelName))
69 | {
70 | dic.Add("chat_id", ChannelName);
71 | }
72 |
73 | if (MessageId.HasValue)
74 | {
75 | dic.Add("message_id", MessageId.Value.ToString(CultureInfo.InvariantCulture));
76 | }
77 |
78 | if (!string.IsNullOrEmpty(InlineMessageId))
79 | {
80 | dic.Add("inline_message_id", InlineMessageId);
81 | }
82 |
83 | return new FormUrlEncodedContent(dic);
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/GetMe.cs:
--------------------------------------------------------------------------------
1 | using System.Net.Http;
2 | using NetTelegramBotApi.Types;
3 |
4 | namespace NetTelegramBotApi.Requests
5 | {
6 | ///
7 | /// A simple method for testing your bot's auth token. Requires no parameters.
8 | /// Returns basic information about the bot in form of a User object.
9 | ///
10 | public class GetMe : RequestBase
11 | {
12 | public GetMe()
13 | : base("getMe")
14 | {
15 | // Nothing
16 | }
17 |
18 | public override HttpContent CreateHttpContent()
19 | {
20 | return null;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/GetUpdates.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Globalization;
3 | using System.Net.Http;
4 | using NetTelegramBotApi.Types;
5 |
6 | namespace NetTelegramBotApi.Requests
7 | {
8 | ///
9 | /// Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned.
10 | ///
11 | public class GetUpdates : RequestBase
12 | {
13 | public GetUpdates()
14 | : base("getUpdates")
15 | {
16 | // Nothing
17 | }
18 |
19 | ///
20 | /// Identifier of the first update to be returned.
21 | /// Must be greater by one than the highest among the identifiers of previously received updates.
22 | /// By default, updates starting with the earliest unconfirmed update are returned.
23 | /// An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id.
24 | ///
25 | public long? Offset { get; set; }
26 |
27 | ///
28 | /// Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100.
29 | ///
30 | public int? Limit { get; set; }
31 |
32 | ///
33 | /// Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling.
34 | ///
35 | public int? Timeout { get; set; }
36 |
37 | public override HttpContent CreateHttpContent()
38 | {
39 | if (!Offset.HasValue && !Limit.HasValue && !Timeout.HasValue)
40 | {
41 | return null;
42 | }
43 |
44 | var dic = new Dictionary();
45 |
46 | if (Offset.HasValue)
47 | {
48 | dic.Add("offset", Offset.Value.ToString(CultureInfo.InvariantCulture));
49 | }
50 |
51 | if (Limit.HasValue)
52 | {
53 | dic.Add("limit", Limit.Value.ToString(CultureInfo.InvariantCulture));
54 | }
55 |
56 | if (Timeout.HasValue)
57 | {
58 | dic.Add("timeout", Timeout.Value.ToString(CultureInfo.InvariantCulture));
59 | }
60 |
61 | return new FormUrlEncodedContent(dic);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/GetUserProfilePhotos.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Globalization;
3 | using System.Net.Http;
4 | using NetTelegramBotApi.Types;
5 |
6 | namespace NetTelegramBotApi.Requests
7 | {
8 | ///
9 | /// Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
10 | ///
11 | public class GetUserProfilePhotos : RequestBase
12 | {
13 | public GetUserProfilePhotos(long userId)
14 | : base("getUserProfilePhotos")
15 | {
16 | this.UserId = userId;
17 | }
18 |
19 | ///
20 | /// Unique identifier of the target user.
21 | ///
22 | public long UserId { get; set; }
23 |
24 | ///
25 | /// Sequential number of the first photo to be returned. By default, all photos are returned.
26 | ///
27 | public int? Offset { get; set; }
28 |
29 | ///
30 | /// Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100.
31 | ///
32 | public int? Limit { get; set; }
33 |
34 | public override HttpContent CreateHttpContent()
35 | {
36 | var dic = new Dictionary();
37 | dic.Add("user_id", UserId.ToString(CultureInfo.InvariantCulture));
38 | if (Offset.HasValue)
39 | {
40 | dic.Add("offset", Offset.Value.ToString(CultureInfo.InvariantCulture));
41 | }
42 |
43 | if (Limit.HasValue)
44 | {
45 | dic.Add("limit", Limit.Value.ToString(CultureInfo.InvariantCulture));
46 | }
47 |
48 | return new FormUrlEncodedContent(dic);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/GetWebhookInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Net.Http;
2 | using NetTelegramBotApi.Types;
3 |
4 | namespace NetTelegramBotApi.Requests
5 | {
6 | ///
7 | /// Use this method to get current webhook status. Requires no parameters.
8 | /// On success, returns a WebhookInfo object.
9 | /// If the bot is using getUpdates, will return an object with the url field empty.
10 | ///
11 | public class GetWebhookInfo : RequestBase
12 | {
13 | public GetWebhookInfo()
14 | : base("getWebhookInfo")
15 | {
16 | // Nothing
17 | }
18 |
19 | public override HttpContent CreateHttpContent()
20 | {
21 | return null;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/KickChatMember.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Net.Http;
5 |
6 | namespace NetTelegramBotApi.Requests
7 | {
8 | ///
9 | /// Use this method to kick a user from a group or a supergroup.
10 | ///
11 | ///
12 | /// Note: This will method only work if the ‘All Members Are Admins’ setting is off in the target group.
13 | /// Otherwise members may only be removed by the group's creator or by the member that added them.
14 | ///
15 | /// In the case of supergroups, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first.
16 | /// The bot must be an administrator in the group for this to work.
17 | /// Returns True on success.
18 | ///
19 | public class KickChatMember : RequestBase
20 | {
21 | public KickChatMember(long chatId, long userId)
22 | : base("kickChatMember")
23 | {
24 | this.ChatId = chatId;
25 | this.UserId = userId;
26 | }
27 |
28 | public KickChatMember(string channelName, long userId)
29 | : base("kickChatMember")
30 | {
31 | this.ChannelName = channelName;
32 | this.UserId = userId;
33 | }
34 |
35 | ///
36 | /// Unique identifier for the target chat.
37 | ///
38 | public long? ChatId { get; protected set; }
39 |
40 | ///
41 | /// Username of the target channel (in the format @channelusername).
42 | ///
43 | public string ChannelName { get; set; }
44 |
45 | ///
46 | /// Unique identifier of the target user.
47 | ///
48 | public long UserId { get; set; }
49 |
50 | public override HttpContent CreateHttpContent()
51 | {
52 | if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
53 | {
54 | throw new InvalidOperationException("Use ChatId or ChannelName, not both.");
55 | }
56 |
57 | var dic = new Dictionary();
58 |
59 | if (ChatId.HasValue)
60 | {
61 | dic.Add("chat_id", ChatId.Value.ToString(CultureInfo.InvariantCulture));
62 | }
63 |
64 | if (!string.IsNullOrEmpty(ChannelName))
65 | {
66 | dic.Add("chat_id", ChannelName);
67 | }
68 |
69 | dic.Add("user_id", UserId.ToString(CultureInfo.InvariantCulture));
70 |
71 | return new FormUrlEncodedContent(dic);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/LeaveChat.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Net.Http;
5 |
6 | namespace NetTelegramBotApi.Requests
7 | {
8 | ///
9 | /// Use this method for your bot to leave a group, supergroup or channel. Returns True on success.
10 | ///
11 | public class LeaveChat : RequestBase
12 | {
13 | public LeaveChat(long chatId)
14 | : base("leaveChat")
15 | {
16 | this.ChatId = chatId;
17 | }
18 |
19 | public LeaveChat(string channelName)
20 | : base("leaveChat")
21 | {
22 | this.ChannelName = channelName;
23 | }
24 |
25 | ///
26 | /// Unique identifier for the target chat.
27 | ///
28 | public long? ChatId { get; protected set; }
29 |
30 | ///
31 | /// Username of the target channel (in the format @channelusername).
32 | ///
33 | public string ChannelName { get; set; }
34 |
35 | public override HttpContent CreateHttpContent()
36 | {
37 | if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
38 | {
39 | throw new InvalidOperationException("Use ChatId or ChannelName, not both.");
40 | }
41 |
42 | var dic = new Dictionary();
43 |
44 | if (ChatId.HasValue)
45 | {
46 | dic.Add("chat_id", ChatId.Value.ToString(CultureInfo.InvariantCulture));
47 | }
48 |
49 | if (!string.IsNullOrEmpty(ChannelName))
50 | {
51 | dic.Add("chat_id", ChannelName);
52 | }
53 |
54 | return new FormUrlEncodedContent(dic);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/RequestBase.cs:
--------------------------------------------------------------------------------
1 | using System.Net.Http;
2 | using System.Text.Json;
3 |
4 | namespace NetTelegramBotApi.Requests
5 | {
6 | public abstract class RequestBase
7 | {
8 | protected RequestBase(string methodName)
9 | {
10 | this.MethodName = methodName;
11 | }
12 |
13 | public string MethodName { get; protected set; }
14 |
15 | public abstract HttpContent CreateHttpContent();
16 |
17 | protected static string JsonSerialize(object value)
18 | {
19 | return JsonSerializer.Serialize(value, TelegramBot.JsonOptions);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/SendAudio.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using NetTelegramBotApi.Types;
4 |
5 | namespace NetTelegramBotApi.Requests
6 | {
7 | ///
8 | /// Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message.
9 | /// For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document).
10 | /// On success, the sent Message is returned.
11 | /// Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
12 | ///
13 | public class SendAudio : SendFileRequestBase
14 | {
15 | public SendAudio(long chatId, FileToSend audio)
16 | : base(chatId, "sendAudio", "audio")
17 | {
18 | this.File = audio;
19 | }
20 |
21 | public SendAudio(string channelName, FileToSend audio)
22 | : base(channelName, "sendAudio", "audio")
23 | {
24 | this.File = audio;
25 | }
26 |
27 | ///
28 | /// Audio caption, 0-200 characters.
29 | ///
30 | public string Caption { get; set; }
31 |
32 | ///
33 | /// Duration of sent audio in seconds.
34 | ///
35 | public int? Duration { get; set; }
36 |
37 | ///
38 | /// Performer of sent audio.
39 | ///
40 | public string Performer { get; set; }
41 |
42 | ///
43 | /// Title of sent audio.
44 | ///
45 | public string Title { get; set; }
46 |
47 | protected override void AppendParameters(Action appendCallback)
48 | {
49 | if (!string.IsNullOrEmpty(Caption))
50 | {
51 | appendCallback("caption", Caption);
52 | }
53 |
54 | if (Duration.HasValue)
55 | {
56 | appendCallback("duration", Duration.Value.ToString(CultureInfo.InvariantCulture));
57 | }
58 |
59 | if (!string.IsNullOrEmpty(Performer))
60 | {
61 | appendCallback("performer", Performer);
62 | }
63 |
64 | if (!string.IsNullOrEmpty(Title))
65 | {
66 | appendCallback("title", Title);
67 | }
68 |
69 | base.AppendParameters(appendCallback);
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/NetTelegramBotApi/Requests/SendChatAction.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Net.Http;
5 |
6 | namespace NetTelegramBotApi.Requests
7 | {
8 | ///
9 | /// Use this method when you need to tell the user that something is happening on the bot's side.
10 | /// The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
11 | ///
12 | ///
13 | /// We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
14 | ///
15 | public class SendChatAction : RequestBase