Skip to content

Commit 6363d00

Browse files
committed
Merge branch 'api_updates'
2 parents a1e4345 + e03e95b commit 6363d00

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2635
-211
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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() : base() { }
10+
11+
public BotRequestException(string message) : base(message) { }
12+
13+
public BotRequestException(string message, Exception inner) : base(message, inner) { }
14+
15+
/// <summary>
16+
/// HTTP Status Code retuned by server
17+
/// </summary>
18+
public HttpStatusCode StatusCode { get; set; }
19+
20+
/// <summary>
21+
/// Response body text
22+
/// </summary>
23+
public string ResponseBody { get; set; }
24+
25+
/// <summary>
26+
/// Optional. Human-readable description of the result (by Telegram)
27+
/// </summary>
28+
public string Description { get; set; }
29+
30+
/// <summary>
31+
/// Contents are subject to change in the future (by Telegram)
32+
/// </summary>
33+
public long? ErrorCode { get; set; }
34+
35+
/// <summary>
36+
/// Optional. Can help to automatically handle the error
37+
/// </summary>
38+
public ResponseParameters Parameters { get; set; }
39+
}
40+
}

NetTelegramBotApi/BotResponse.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using NetTelegramBotApi.Types;
23

34
namespace NetTelegramBotApi
45
{
@@ -9,5 +10,9 @@ public class BotResponse<T>
910
public string Description { get; set; }
1011

1112
public T Result { get; set; }
13+
14+
public long? ErrorCode { get; set; }
15+
16+
public ResponseParameters Parameters { get; set; }
1217
}
1318
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Net.Http;
5+
6+
namespace NetTelegramBotApi.Requests
7+
{
8+
/// <summary>
9+
/// Use this method to send answers to callback queries sent from inline keyboards.
10+
/// The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
11+
/// On success, True is returned.
12+
/// </summary>
13+
public class AnswerCallbackQuery : RequestBase<bool>
14+
{
15+
public AnswerCallbackQuery(string callbackQueryId)
16+
: base("answerCallbackQuery")
17+
{
18+
this.CallbackQueryId = callbackQueryId;
19+
}
20+
21+
/// <summary>
22+
/// Unique identifier for the query to be answered
23+
/// </summary>
24+
public string CallbackQueryId { get; protected set; }
25+
26+
/// <summary>
27+
/// Optional. Text of the notification. If not specified, nothing will be shown to the user
28+
/// </summary>
29+
public string Text { get; set; }
30+
31+
/// <summary>
32+
/// Optional. If true, an alert will be shown by the client instead of a notification at the top of the chat screen.
33+
/// Defaults to false.
34+
/// </summary>
35+
public bool? ShowAlert { get; set; }
36+
37+
/// <summary>
38+
/// Optional. URL that will be opened by the user's client.
39+
/// If you have created a Game and accepted the conditions via @Botfather,
40+
/// specify the URL that opens your game – note that this will only work if the query comes from a callback_game button.
41+
/// Otherwise, you may use links like telegram.me/your_bot?start=XXXX that open your bot with a parameter.
42+
/// </summary>
43+
public string Url { get; set; }
44+
45+
/// <summary>
46+
/// The maximum amount of time in seconds that the result of the callback query may be cached client-side.
47+
/// Telegram apps will support caching starting in version 3.14. Defaults to 0.
48+
/// </summary>
49+
public long CacheTime { get; set; }
50+
51+
public override HttpContent CreateHttpContent()
52+
{
53+
var dic = new Dictionary<string, string>();
54+
dic.Add("callback_query_id", CallbackQueryId);
55+
if (!string.IsNullOrEmpty(Text))
56+
{
57+
dic.Add("text", Text);
58+
}
59+
60+
if (ShowAlert.HasValue)
61+
{
62+
dic.Add("show_alert", ShowAlert.Value.ToString());
63+
}
64+
65+
if (!string.IsNullOrEmpty(Url))
66+
{
67+
dic.Add("url", Url);
68+
}
69+
70+
dic.Add("cache_time", CacheTime.ToString(CultureInfo.InvariantCulture));
71+
72+
return new FormUrlEncodedContent(dic);
73+
}
74+
}
75+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
/// <summary>
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+
/// </summary>
13+
public class EditMessageCaption : RequestBase<Message>
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+
/// <summary>
39+
/// Optional. Required if inline_message_id is not specified. Unique identifier for the target chat
40+
/// </summary>
41+
public long? ChatId { get; protected set; }
42+
43+
/// <summary>
44+
/// Optional. Required if inline_message_id is not specified. Username of the target channel
45+
/// </summary>
46+
public string ChannelName { get; protected set; }
47+
48+
/// <summary>
49+
/// Optional. Required if inline_message_id is not specified. Identifier of the sent message
50+
/// </summary>
51+
public long? MessageId { get; protected set; }
52+
53+
/// <summary>
54+
/// Optional. Required if chat_id and message_id are not specified. Identifier of the inline message
55+
/// </summary>
56+
public long? InlineMessageId { get; protected set; }
57+
58+
/// <summary>
59+
/// Optional. New caption of the message
60+
/// </summary>
61+
public string Caption { get; set; }
62+
63+
/// <summary>
64+
/// Optional. A JSON-serialized object for an inline keyboard.
65+
/// </summary>
66+
public InlineKeyboardMarkup ReplyMarkup { get; set; }
67+
68+
public override HttpContent CreateHttpContent()
69+
{
70+
if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
71+
{
72+
throw new Exception("Use ChatId or ChannelName, not both.");
73+
}
74+
75+
var dic = new Dictionary<string, string>();
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+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
/// <summary>
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+
/// </summary>
13+
public class EditMessageReplyMarkup : RequestBase<Message>
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+
/// <summary>
39+
/// Optional. Required if inline_message_id is not specified. Unique identifier for the target chat
40+
/// </summary>
41+
public long? ChatId { get; protected set; }
42+
43+
/// <summary>
44+
/// Optional. Required if inline_message_id is not specified. Username of the target channel
45+
/// </summary>
46+
public string ChannelName { get; protected set; }
47+
48+
/// <summary>
49+
/// Optional. Required if inline_message_id is not specified. Identifier of the sent message
50+
/// </summary>
51+
public long? MessageId { get; protected set; }
52+
53+
/// <summary>
54+
/// Optional. Required if chat_id and message_id are not specified. Identifier of the inline message
55+
/// </summary>
56+
public long? InlineMessageId { get; protected set; }
57+
58+
/// <summary>
59+
/// Optional. A JSON-serialized object for an inline keyboard.
60+
/// </summary>
61+
public InlineKeyboardMarkup ReplyMarkup { get; set; }
62+
63+
public override HttpContent CreateHttpContent()
64+
{
65+
if (ChatId.HasValue && !string.IsNullOrEmpty(ChannelName))
66+
{
67+
throw new Exception("Use ChatId or ChannelName, not both.");
68+
}
69+
70+
var dic = new Dictionary<string, string>();
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+
}

0 commit comments

Comments
 (0)