Skip to content

Commit

Permalink
deploy: 97c86c2
Browse files Browse the repository at this point in the history
  • Loading branch information
wiz0u committed Jun 26, 2024
1 parent b3094e5 commit bb7911c
Show file tree
Hide file tree
Showing 45 changed files with 286 additions and 467 deletions.
15 changes: 6 additions & 9 deletions 1/example-bot.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<link rel="stylesheet" href="../ayu-highlight.css">

<!-- Custom theme stylesheets -->
<link rel="stylesheet" href="../theme/custom.css">

</head>
<body class="sidebar-visible no-js">
Expand Down Expand Up @@ -197,21 +198,20 @@ <h1 id="example---first-chat-bot"><a class="header" href="#example---first-chat-
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;

var botClient = new TelegramBotClient(&quot;{YOUR_ACCESS_TOKEN_HERE}&quot;);
using CancellationTokenSource cts = new();

using CancellationTokenSource cts = new ();
var botClient = new TelegramBotClient(&quot;{YOUR_ACCESS_TOKEN_HERE}&quot;, cancellationToken: cts.Token);

// StartReceiving does not block the caller thread. Receiving is done on the ThreadPool.
ReceiverOptions receiverOptions = new ()
var receiverOptions = new ReceiverOptions()
{
AllowedUpdates = Array.Empty&lt;UpdateType&gt;() // receive all update types except ChatMember related updates
};

botClient.StartReceiving(
updateHandler: HandleUpdateAsync,
pollingErrorHandler: HandlePollingErrorAsync,
receiverOptions: receiverOptions,
cancellationToken: cts.Token
receiverOptions: receiverOptions
);

var me = await botClient.GetMeAsync();
Expand All @@ -236,10 +236,7 @@ <h1 id="example---first-chat-bot"><a class="header" href="#example---first-chat-
Console.WriteLine($&quot;Received a '{messageText}' message in chat {chatId}.&quot;);

// Echo received message text
Message sentMessage = await botClient.SendTextMessageAsync(
chatId: chatId,
text: &quot;You said:\n&quot; + messageText,
cancellationToken: cancellationToken);
Message sentMessage = await botClient.SendTextMessageAsync(chatId, &quot;You said:\n&quot; + messageText);
}

Task HandlePollingErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)
Expand Down
1 change: 1 addition & 0 deletions 1/quickstart.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<link rel="stylesheet" href="../ayu-highlight.css">

<!-- Custom theme stylesheets -->
<link rel="stylesheet" href="../theme/custom.css">

</head>
<body class="sidebar-visible no-js">
Expand Down
1 change: 1 addition & 0 deletions 2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<link rel="stylesheet" href="../ayu-highlight.css">

<!-- Custom theme stylesheets -->
<link rel="stylesheet" href="../theme/custom.css">

</head>
<body class="sidebar-visible no-js">
Expand Down
110 changes: 40 additions & 70 deletions 2/reply-markup.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<link rel="stylesheet" href="../ayu-highlight.css">

<!-- Custom theme stylesheets -->
<link rel="stylesheet" href="../theme/custom.css">

</head>
<body class="sidebar-visible no-js">
Expand Down Expand Up @@ -194,19 +195,13 @@ <h3 id="single-row-keyboard-markup"><a class="header" href="#single-row-keyboard
<p>A <a href="https://core.telegram.org/bots/api/#replykeyboardmarkup"><code>ReplyKeyboardMarkup</code></a> with two buttons in a single row:</p>
<pre><code class="language-c#">// using Telegram.Bot.Types.ReplyMarkups;

ReplyKeyboardMarkup replyKeyboardMarkup = new(new[]
var buttons = new KeyboardButton[]
{
new KeyboardButton[] { &quot;Help me&quot;, &quot;Call me ☎️&quot; },
})
{
ResizeKeyboard = true
&quot;Help me&quot;, &quot;Call me ☎️&quot;,
};

Message sentMessage = await botClient.SendTextMessageAsync(
chatId: chatId,
text: &quot;Choose a response&quot;,
replyMarkup: replyKeyboardMarkup,
cancellationToken: cancellationToken);
var sent = await botClient.SendTextMessageAsync(chatId, &quot;Choose a response&quot;,
replyMarkup: new ReplyKeyboardMarkup(buttons) { ResizeKeyboard = true });
</code></pre>
<blockquote>
<p>We specify <code>ResizeKeyboard = true</code> here to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons).</p>
Expand All @@ -215,46 +210,35 @@ <h3 id="multi-row-keyboard-markup"><a class="header" href="#multi-row-keyboard-m
<p>A <a href="https://core.telegram.org/bots/api/#replykeyboardmarkup"><code>ReplyKeyboardMarkup</code></a> with two rows of buttons:</p>
<pre><code class="language-c#">// using Telegram.Bot.Types.ReplyMarkups;

ReplyKeyboardMarkup replyKeyboardMarkup = new(new[]
var buttons = new KeyboardButton[][]
{
new KeyboardButton[] { &quot;Help me&quot; },
new KeyboardButton[] { &quot;Call me ☎️&quot; },
})
{
ResizeKeyboard = true
new KeyboardButton[] { &quot;Call me ☎️&quot;, &quot;Write me ✉️&quot; },
};

Message sentMessage = await botClient.SendTextMessageAsync(
chatId: chatId,
text: &quot;Choose a response&quot;,
replyMarkup: replyKeyboardMarkup,
cancellationToken: cancellationToken);
var sent = await botClient.SendTextMessageAsync(chatId, &quot;Choose a response&quot;,
replyMarkup: new ReplyKeyboardMarkup(buttons) { ResizeKeyboard = true });
</code></pre>
<p>You can use <code>new List&lt;List&lt;KeyboardButton&gt;&gt;</code> instead of <code>KeyboardButton[][]</code> if you prefer to build the list dynamically.</p>
<h3 id="request-information"><a class="header" href="#request-information">Request information</a></h3>
<p><a href="https://core.telegram.org/bots/api/#replykeyboardmarkup"><code>ReplyKeyboardMarkup</code></a> containing buttons for contact and location requests using helper methods <code>KeyboardButton.WithRequestLocation</code> and <code>KeyboardButton.WithRequestContact</code>:</p>
<pre><code class="language-c#">// using Telegram.Bot.Types.ReplyMarkups;

ReplyKeyboardMarkup replyKeyboardMarkup = new(new[]
var buttons = new[]
{
KeyboardButton.WithRequestLocation(&quot;Share Location&quot;),
KeyboardButton.WithRequestContact(&quot;Share Contact&quot;),
});
};

Message sentMessage = await botClient.SendTextMessageAsync(
chatId: chatId,
text: &quot;Who or Where are you?&quot;,
replyMarkup: replyKeyboardMarkup,
cancellationToken: cancellationToken);
var sent = await botClient.SendTextMessageAsync(chatId, &quot;Who or Where are you?&quot;,
replyMarkup: new ReplyKeyboardMarkup(buttons));
</code></pre>
<h3 id="remove-keyboard"><a class="header" href="#remove-keyboard">Remove keyboard</a></h3>
<p>To remove keyboard you have to send an instance of <a href="https://core.telegram.org/bots/api#replykeyboardremove"><code>ReplyKeyboardRemove</code></a> object:</p>
<pre><code class="language-c#">// using Telegram.Bot.Types.ReplyMarkups;

Message sentMessage = await botClient.SendTextMessageAsync(
chatId: chatId,
text: &quot;Removing keyboard&quot;,
replyMarkup: new ReplyKeyboardRemove(),
cancellationToken: cancellationToken);
var sent = await botClient.SendTextMessageAsync(chatId, &quot;Removing keyboard&quot;,
replyMarkup: new ReplyKeyboardRemove());
</code></pre>
<h2 id="inline-keyboards"><a class="header" href="#inline-keyboards">Inline keyboards</a></h2>
<p>There are times when you'd prefer to do things without sending any messages to the chat. For example, when your user is changing settings or flipping through search results. In such cases you can use <a href="https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating">Inline Keyboards</a> that are integrated directly into the messages they belong to.</p>
Expand All @@ -263,62 +247,48 @@ <h3 id="callback-buttons"><a class="header" href="#callback-buttons">Callback bu
<p>When a user presses a <a href="https://core.telegram.org/bots/2-0-intro#callback-buttons">callback button</a>, no messages are sent to the chat. Instead, your bot simply receives the relevant query. Upon receiving the query, your bot can display some result in a notification at the top of the chat screen or in an alert. In this example we use <code>InlineKeyboardButton.WithCallbackData</code> helper method to create a button with a text and callback data.</p>
<pre><code class="language-c#">// using Telegram.Bot.Types.ReplyMarkups;

InlineKeyboardMarkup inlineKeyboard = new(new[]
var buttons = new InlineKeyboardButton[][]
{
// first row
new []
new[] // first row
{
InlineKeyboardButton.WithCallbackData(text: &quot;1.1&quot;, callbackData: &quot;11&quot;),
InlineKeyboardButton.WithCallbackData(text: &quot;1.2&quot;, callbackData: &quot;12&quot;),
InlineKeyboardButton.WithCallbackData(&quot;1.1&quot;, &quot;11&quot;),
InlineKeyboardButton.WithCallbackData(&quot;1.2&quot;, &quot;12&quot;),
},
// second row
new []
new[] // second row
{
InlineKeyboardButton.WithCallbackData(text: &quot;2.1&quot;, callbackData: &quot;21&quot;),
InlineKeyboardButton.WithCallbackData(text: &quot;2.2&quot;, callbackData: &quot;22&quot;),
InlineKeyboardButton.WithCallbackData(&quot;2.1&quot;, &quot;21&quot;),
InlineKeyboardButton.WithCallbackData(&quot;2.2&quot;, &quot;22&quot;),
},
});
};

Message sentMessage = await botClient.SendTextMessageAsync(
chatId: chatId,
text: &quot;A message with an inline keyboard markup&quot;,
replyMarkup: inlineKeyboard,
cancellationToken: cancellationToken);
var sent = await botClient.SendTextMessageAsync(chatId, &quot;A message with an inline keyboard markup&quot;,
replyMarkup: new InlineKeyboardMarkup(buttons));
</code></pre>
<p>You can use <code>new List&lt;List&lt;InlineKeyboardButton&gt;&gt;</code> instead of <code>InlineKeyboardButton[][]</code> if you prefer to build the list dynamically.</p>
<h3 id="url-buttons"><a class="header" href="#url-buttons">URL buttons</a></h3>
<p>Buttons of this type have a small arrow icon to help the user understand that tapping on a <a href="https://core.telegram.org/bots/2-0-intro#url-buttons">URL button</a> will open an external link. In this example we use <code>InlineKeyboardButton.WithUrl</code> helper method to create a button with a text and url.</p>
<pre><code class="language-c#">// using Telegram.Bot.Types.ReplyMarkups;

InlineKeyboardMarkup inlineKeyboard = new(new[]
var buttons = new[]
{
InlineKeyboardButton.WithUrl(
text: &quot;Link to the Repository&quot;,
url: &quot;https://github.com/TelegramBots/Telegram.Bot&quot;)
});

Message sentMessage = await botClient.SendTextMessageAsync(
chatId: chatId,
text: &quot;A message with an inline keyboard markup&quot;,
replyMarkup: inlineKeyboard,
cancellationToken: cancellationToken);
InlineKeyboardButton.WithUrl(&quot;Repositoy Link&quot;, &quot;https://github.com/TelegramBots/Telegram.Bot&quot;)
};

var sent = await botClient.SendTextMessageAsync(chatId, &quot;A message with an inline keyboard markup&quot;,
replyMarkup: new InlineKeyboardMarkup(buttons));
</code></pre>
<h3 id="switch-to-inline-buttons"><a class="header" href="#switch-to-inline-buttons">Switch to Inline buttons</a></h3>
<p>Pressing a <a href="https://core.telegram.org/bots/2-0-intro#switch-to-inline-buttons">switch to inline button</a> prompts the user to select a chat, opens it and inserts the bot's username into the input field. You can also pass a query that will be inserted along with the username – this way your users will immediately get some inline results they can share. In this example we use <code>InlineKeyboardButton.WithSwitchInlineQuery</code> and <code>InlineKeyboardButton.WithSwitchInlineQueryCurrentChat</code> helper methods to create buttons which will insert the bot's username in the chat's input field.</p>
<pre><code class="language-c#">// using Telegram.Bot.Types.ReplyMarkups;

InlineKeyboardMarkup inlineKeyboard = new(new[]
var buttons = new[]
{
InlineKeyboardButton.WithSwitchInlineQuery(
text: &quot;switch_inline_query&quot;),
InlineKeyboardButton.WithSwitchInlineQueryCurrentChat(
text: &quot;switch_inline_query_current_chat&quot;),
});

Message sentMessage = await botClient.SendTextMessageAsync(
chatId: chatId,
text: &quot;A message with an inline keyboard markup&quot;,
replyMarkup: inlineKeyboard,
cancellationToken: cancellationToken);
InlineKeyboardButton.WithSwitchInlineQuery(&quot;switch_inline_query&quot;),
InlineKeyboardButton.WithSwitchInlineQueryCurrentChat(&quot;switch_inline_query_current_chat&quot;),
};

var sent = await botClient.SendTextMessageAsync(chatId, &quot;A message with an inline keyboard markup&quot;,
replyMarkup: new InlineKeyboardMarkup(buttons));
</code></pre>

</main>
Expand Down
14 changes: 5 additions & 9 deletions 2/send-msg/album-msg.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<link rel="stylesheet" href="../../ayu-highlight.css">

<!-- Custom theme stylesheets -->
<link rel="stylesheet" href="../../theme/custom.css">

</head>
<body class="sidebar-visible no-js">
Expand Down Expand Up @@ -187,16 +188,11 @@ <h1 id="album-messages"><a class="header" href="#album-messages">Album Messages<
<p><a href="https://core.telegram.org/bots/api#sendmediagroup"><img src="https://img.shields.io/badge/Bot_API_method-sendMediaGroup-blue.svg?style=flat-square" alt="send media group method" /></a>
<a href="https://github.com/TelegramBots/Telegram.Bot/blob/master/test/Telegram.Bot.Tests.Integ/Sending%20Messages/AlbumMessageTests.cs"><img src="https://img.shields.io/badge/Examples-Album_Messages-green.svg?style=flat-square" alt="tests" /></a></p>
<p>Using <a href="https://core.telegram.org/bots/api#sendmediagroup"><code>sendMediaGroup</code></a> method you can send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type.</p>
<pre><code class="language-c#">Message[] messages = await botClient.SendMediaGroupAsync(
chatId: chatId,
media: new IAlbumInputMedia[]
<pre><code class="language-c#">var messages = await botClient.SendMediaGroupAsync(chatId, new IAlbumInputMedia[]
{
new InputMediaPhoto(
InputFile.FromUri(&quot;https://cdn.pixabay.com/photo/2017/06/20/19/22/fuchs-2424369_640.jpg&quot;)),
new InputMediaPhoto(
InputFile.FromUri(&quot;https://cdn.pixabay.com/photo/2017/04/11/21/34/giraffe-2222908_640.jpg&quot;)),
},
cancellationToken: cancellationToken);
new InputMediaPhoto(&quot;https://cdn.pixabay.com/photo/2017/06/20/19/22/fuchs-2424369_640.jpg&quot;),
new InputMediaPhoto(&quot;https://cdn.pixabay.com/photo/2017/04/11/21/34/giraffe-2222908_640.jpg&quot;),
});
</code></pre>

</main>
Expand Down
21 changes: 6 additions & 15 deletions 2/send-msg/audio-voice-msg.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<link rel="stylesheet" href="../../ayu-highlight.css">

<!-- Custom theme stylesheets -->
<link rel="stylesheet" href="../../theme/custom.css">

</head>
<body class="sidebar-visible no-js">
Expand Down Expand Up @@ -191,15 +192,9 @@ <h2 id="audio"><a class="header" href="#audio">Audio</a></h2>
<p><a href="https://core.telegram.org/bots/api#sendaudio"><img src="https://img.shields.io/badge/Bot_API_method-sendAudio-blue.svg?style=flat-square" alt="send audio method" /></a></p>
<p>This is the code to send an MP3 soundtrack. You might be wondering why some parameters are commented out?
That's because this MP3 file has metadata on it and Telegram does a good job at reading it.</p>
<pre><code class="language-c#">Message message = await botClient.SendAudioAsync(
chatId: chatId,
audio: InputFile.FromUri(&quot;https://github.com/TelegramBots/book/raw/master/src/docs/audio-guitar.mp3&quot;),
/*
performer: &quot;Joel Thomas Hunger&quot;,
title: &quot;Fun Guitar and Ukulele&quot;,
duration: 91, // in seconds
*/
cancellationToken: cancellationToken);
<pre><code class="language-c#">var message = await botClient.SendAudioAsync(chatId, &quot;https://telegrambots.github.io/book/docs/audio-guitar.mp3&quot;
// , performer: &quot;Joel Thomas Hunger&quot;, title: &quot;Fun Guitar and Ukulele&quot;, duration: 91 // optional
);
</code></pre>
<p><img src="../docs/shot-audio_msg.jpg" alt="audio message" /></p>
<p>And a user can see the audio in Music Player:</p>
Expand All @@ -218,17 +213,13 @@ <h2 id="voice"><a class="header" href="#voice">Voice</a></h2>
<p><a href="https://core.telegram.org/bots/api#sendvoice"><img src="https://img.shields.io/badge/Bot_API_method-sendVoice-blue.svg?style=flat-square" alt="send voice method" /></a></p>
<p>A voice message is an OGG audio file.
Let's send it differently this time by uploading the file from disk alongside with an HTTP request.</p>
<p>To run this example, download the <a href="https://raw.githubusercontent.com/TelegramBots/book/master/src/docs/voice-nfl_commentary.ogg">NFL Commentary voice file</a> to your disk.</p>
<p>To run this example, download the <a href="https://telegrambots.github.io/book/docs/voice-nfl_commentary.ogg">NFL Commentary voice file</a> to your disk.</p>
<p>A value is passed for <code>duration</code> because Telegram can't figure that out from a file's metadata.</p>
<blockquote>
<p>⚠️ Replace <code>/path/to/voice-nfl_commentary.ogg</code> with an actual file path.</p>
</blockquote>
<pre><code class="language-c#">await using Stream stream = System.IO.File.OpenRead(&quot;/path/to/voice-nfl_commentary.ogg&quot;);
Message message = await botClient.SendVoiceAsync(
chatId: chatId,
voice: InputFile.FromStream(stream),
duration: 36,
cancellationToken: cancellationToken);
var message = await botClient.SendVoiceAsync(chatId, stream, duration: 36);
</code></pre>
<p><img src="../docs/shot-voice_msg.jpg" alt="voice message" /></p>
<p>A voice message is returned from the method. Inspect the <code>message.Voice</code> property to learn more.</p>
Expand Down
Loading

0 comments on commit bb7911c

Please sign in to comment.