{"id":334017,"date":"2022-06-03T15:00:36","date_gmt":"2022-06-03T15:00:36","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=334017"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=334017","title":{"rendered":"<span>\u0411\u043e\u0442 \u043d\u0430 .NET. Telegram + Google API<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041e\u0447\u0435\u043d\u044c \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0441\u043b\u0443\u0448\u0430\u043b \u043c\u0443\u0437\u044b\u043a\u0443 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 Telegram. \u0422\u0430\u043c \u0438 \u043f\u043e\u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u043c\u043e\u0436\u043d\u043e \u0438 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0442\u0435\u043b\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439. \u041d\u043e \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e &#8212; \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u043a\u043e\u0433\u0434\u0430 \u0441\u0432\u043e\u0439 \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442 \u043d\u0430\u0434\u043e\u0435\u0434\u0430\u0435\u0442 \u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0447\u0435\u0433\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0433\u043e. \u0412 YouTube Music \u0435\u0441\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u043e\u0439 \u043c\u0443\u0437\u044b\u043a\u043e\u0439. \u0427\u0442\u043e \u044f \u0438\u043c\u0435\u044e \u0432\u0432\u0438\u0434\u0443? \u041f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043b\u044e\u0431\u043e\u0439 \u043f\u0435\u0441\u043d\u0438, \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0440\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u043d\u043e\u0432\u044b\u0435 \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u044b \ud83d\ude42<\/p>\n<p>\u0412 \u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c\u0435 \u0443 \u043c\u0435\u043d\u044f \u0431\u044b\u043b\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e \u0431\u043e\u043b\u0435\u0435 1000 \u043f\u0435\u0441\u0435\u043d. \u042f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0441\u043b\u0430\u043d\u043d\u0443\u044e \u043c\u0443\u0437\u044b\u043a\u0443 \u0438\u0437 \u0422\u0413, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442 \u0432 YouTube \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0435\u0441\u043d\u0438 \u0442\u0443\u0434\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438 \u0447\u0435\u043c\u0443-\u0442\u043e \u043d\u043e\u0432\u043e\u043c\u0443 \u043d\u0430\u0443\u0447\u0443\u0441\u044c \u0438 \u043f\u0435\u0441\u043d\u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0443(\u043d\u0443 \u0438 \u0435\u0441\u043b\u0438 \u043a\u043e\u043c\u0443-\u0442\u043e \u0438\u0437 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0445 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0443\u0441\u043b\u0443\u0433\u0438 \u043c\u043e\u0435\u0433\u043e \u0431\u043e\u0442\u0430, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0438\u043c \u0432\u0440\u0435\u043c\u044f, \u0445\u043e\u0442\u044f \u044f \u043c\u0430\u043b\u043e \u0432\u0435\u0440\u044e, \u0447\u0442\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f, \u044d\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u0443\u0447\u0435\u0431\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u043a). <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0439\u0442\u0438 \u0432 \u0442\u0433, \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/t.me\/BotFather\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0433\u043e \u0431\u043e\u0442\u0430<\/a>, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0435\u0433\u043e: <\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/2fb\/e4d\/ce6\/2fbe4dce63a2779e697a65eca69343b0.png\" alt=\"\u0417\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u043e\u0433\u043b\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430\" title=\"\u0417\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u043e\u0433\u043b\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430\" width=\"998\" height=\"1012\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2fb\/e4d\/ce6\/2fbe4dce63a2779e697a65eca69343b0.png\"\/><figcaption>\u0417\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u043e\u0433\u043b\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430<\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e, \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0440\u043e\u0435\u043a\u0442 .NET 5 \u0432 Visual Studio 2019. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f NuGet, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e, \u044d\u0442\u0438 4 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e85\/b76\/5e4\/e85b765e423928dac6f7f8e9a74a0506.png\" width=\"980\" height=\"536\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e85\/b76\/5e4\/e85b765e423928dac6f7f8e9a74a0506.png\"\/><figcaption><\/figcaption><\/figure>\n<p><code>Newtonsoft.Json<\/code> &#8212; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439, \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u0432 .NET: <br \/><code>using System.Text.Json;<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u043b \u043a\u043b\u0430\u0441\u0441 Brain, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435\u043c\u0438 <s>\u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u043c\u0438<\/s> \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u0431\u043e\u0442\u0430:<\/p>\n<pre><code>class Brain {  public static ITelegramBotClient Bot { get; set; } =  new TelegramBotClient(\"token\"); \/\/ \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u0441\u0432\u043e\u0439 \u0442\u043e\u043a\u0435\u043d  public static async Task HandleMessageAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) {   Console.WriteLine(JsonConvert.SerializeObject(update));    if (update.Type == Telegram.Bot.Types.Enums.UpdateType.Message)   {     var message = update.Message;     String queryString = \"\";      if (message.Text != null)     {       if (message.Text.ToLower() == \"\/start\")       {         \/\/ \u0422\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f, \u0438\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \/\/ \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0431\u043e\u0442\u0430, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u0430\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f         await botClient.SendTextMessageAsync(message.Chat, \"\u0414\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u043b\u043e\u0441\u0430\u0442\u044b\u0439\");         return;       }        queryString = message.Text;\/\/ \u0415\u0441\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0441\u043d\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u043c, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \/\/ \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0441\u043b\u0430\u0442\u044c \u0435\u0435. \u042d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0442\u043e\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c \u0442\u0435\u043a\u0441\u0442, \/\/ \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u044e\u0442 \u0431\u043e\u0442\u0443     }      if (message.Audio != null) \/\/\u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043c\u0443\u0437\u044b\u043a\u0430, \u0431\u0435\u0440\u0435\u043c \u0438\u043c\u044f \u0430\u0432\u0442\u043e\u0440\u0430 \u0438 \u043f\u0435\u0441\u043d\u0438     {       Audio audio = message.Audio;        queryString = audio.Performer;       queryString += \" - \" + audio.Title;     }         String url = \"https:\/\/music.youtube.com\/search?q=\";       queryString = queryString.Replace(\" \", \"+\");       Console.WriteLine(url += queryString);        await botClient.SendTextMessageAsync(message.Chat, url);       return;   } }  public static async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken) {   Console.WriteLine(JsonConvert.SerializeObject(exception)); } }<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 Program \u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c Main:<\/p>\n<pre><code>class Program  { static void Main(string[] args) {   Console.WriteLine($\"Bot has been started: {Brain.Bot.GetMeAsync().Result.FirstName}\");    var cts = new CancellationTokenSource();   var cancellationToken = cts.Token;   var receiverOptions = new ReceiverOptions   {     AllowedUpdates = { },   };    Brain.Bot.StartReceiving(       Brain.HandleMessageAsync,       Brain.HandleErrorAsync,       receiverOptions,       cancellationToken   );    Console.ReadLine(); } }<\/code><\/pre>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043d\u0430\u0448 \u0431\u043e\u0442 \u0443\u0436\u0435 \u0443\u043c\u0435\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043f\u0435\u0441\u043d\u0438. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043e\u043d \u0431\u0435\u0440\u0435\u0442 \u0438\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u0432 query string, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043a \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c\u0443 url&#8217;\u0443 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0432 \u043e\u0442\u0432\u0435\u0442. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<figure class=\"float full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1c2\/f2c\/4c5\/1c2f2c4c536303da804467012239be0d.png\" width=\"960\" height=\"478\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1c2\/f2c\/4c5\/1c2f2c4c536303da804467012239be0d.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0435\u043c\u0443 \u0443\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u0430\u0442\u044c \u043f\u0435\u0441\u043d\u0438 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c\u0438 \u043f\u0430\u0447\u043a\u0430\u043c\u0438, \u0432 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u0442 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u043d\u0438\u0445 \ud83d\ude42<br \/>\u042d\u0442\u043e \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u043d\u043e \u043c\u044b \u0443\u0436\u0435 \u0431\u043b\u0438\u0436\u0435 \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442, \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043f\u0435\u0441\u043d\u0438 \u0442\u0443\u0434\u0430. \u0427\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0433\u0443\u0433\u043b, \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c OAuth2. \u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438: \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0430\u043f\u0438 YouTube(YouTube Data API v3) \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b OAuth2 \u043b\u043e\u0433\u0438\u043d.<\/p>\n<p>\u041e\u043f\u0438\u0441\u0430\u043b \u043a\u043b\u0430\u0441\u0441 YTMusicController:<\/p>\n<pre><code>class YTMusicController  {  private static String client_id = \"your client id\";  private static String client_secret = \"your client secret\";   internal static UserCredential credential;  private static YouTubeService youTubeService = new YouTubeService(new BaseClientService.Initializer() {   ApiKey = \"your api key\", \/\/ \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0433\u0443\u0433\u043b \u043a\u043e\u043d\u0441\u043e\u043b\u0438   HttpClientInitializer = Brain.credential,   ApplicationName = \"YTMusic\" });  private static void Reinit()   {     youTubeService = new YouTubeService(new BaseClientService.Initializer()     {       ApiKey = \"AIzaSyDLk83ykqHtYOOjDwtvZvSf5S7wOIvGeGY\",       HttpClientInitializer = credential,       ApplicationName = \"YTMusic\"     });   }    public static async Task Login() \/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0438\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OAuth2   {                                \/\/ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0431\u043e\u0442\u0430     var client_secrets = new ClientSecrets();     client_secrets.ClientId = YTMusicController.client_id;     client_secrets.ClientSecret = YTMusicController.client_secret     credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(       client_secrets,       new[] { YouTubeService.Scope.Youtube },       \"user\",       CancellationToken.None,       new FileDataStore(\"YTMusicBrain\")       );        Reinit(); \/\/ \u043f\u0435\u0440\u0435\u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 YouTubeService \u0441 \u0423\u0416\u0415 \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0435\u043d\u043d\u044b\u043c \u044e\u0437\u0435\u0440\u043e\u043c   }      public static async Task CreateNewPlaylist(Chat chatId)   {     Playlist playlist = new Playlist();     playlist.Snippet = new PlaylistSnippet();     var t = Guid.NewGuid().ToString(); \/\/ \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442 \u0441 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435     playlist.Snippet.Title = t;     playlist.Snippet.Description = \"This playlist created automatically\";     playlist.Status = new PlaylistStatus();     playlist.Status.PrivacyStatus = \"public\";     playlist = await youTubeService.Playlists.Insert(playlist, \"snippet, status\").ExecuteAsync(); \/\/ \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442\u0430 \u044f \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u0435\u0433\u043e \u0432 \u043c\u0430\u043f\u0443 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0445\u0440\u0430\u043d\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \/\/ \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442\u0430 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0447\u0430\u0442     Brain.chat_playlist.Add(chatId.Id, playlist);      public static async Task&lt;SearchResult> Search(String searchQuery)   {     var searchListResult = youTubeService.Search.List(\"snippet\"); \/\/ \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f      searchListResult.Q = searchQuery;                    \/\/ \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u043f\u0435\u0441\u043d\u0438     searchListResult.MaxResults = 1     var response = await searchListResult.ExecuteAsync();\/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e     return response.Items[0];      public static async Task AddToTestPlaylist(Chat chatId, String searchQuery)   {     Playlist main = Brain.chat_playlist[chatId.Id];     var temp = new PlaylistItem()     var resultOfSearch = await Search(searchQuery); \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0443\u044e \u043f\u0435\u0441\u043d     temp.Snippet = new PlaylistItemSnippet();     temp.Snippet.PlaylistId = main.Id;     temp.Snippet.ResourceId = new ResourceId();     temp.Snippet.ResourceId.Kind = \"youtube#video\";     temp.Snippet.ResourceId.VideoId = resultOfSearch.Id.VideoId; \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432 \u043d\u0430\u0448 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439     await youTubeService.PlaylistItems.Insert(temp, \"snippet\").ExecuteAsync();     return;   } } <\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043b \u043a\u043e\u043c\u0430\u043d\u0434\u0443 &#171;\/create&#187; \u0447\u0435\u0440\u0435\u0437 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e\u0433\u043e \u0432\u044b\u0448\u0435 \u0431\u043e\u0442\u0430. \u041f\u043e\u0441\u043b\u0435 \u0435\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442 \u0432 YouTube.  \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e HandleMessageAsync \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c: <code> <\/code><\/p>\n<pre><code>if (YTMusicController.credential == null)    { await YTMusicController.Login();  } \/\/ ... ..... ... \/\/ if (message.Text.ToLower() == \"\/create\")   {     await YTMusicController.CreateNewPlaylist(message.Chat);   }    if ( chat_playlist != null &amp;&amp; chat_playlist.ContainsKey(message.Chat.Id))   {     await YTMusicController.AddToTestPlaylist(message.Chat, queryString);   } \/\/ \u0435\u0441\u043b\u0438 \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442 \u0435\u0441\u0442\u044c \u0432 \u0441\u043f\u0438\u0441\u043a\u0435, \u043c\u044b \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u0443\u044e \u043f\u0435\u0441\u043d\u044e \/\/ \u0438\u043d\u0430\u0447\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u0435\u0441\u043d\u044e   else   {     String url = \"https:\/\/music.youtube.com\/search?q=\";     queryString = queryString.Replace(\" \", \"+\");     Console.WriteLine(url += queryString);      await botClient.SendTextMessageAsync(message.Chat, url);     return;   }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 Brain:<\/p>\n<pre><code>class Brain  {  public static ITelegramBotClient Bot { get; set; } = new TelegramBotClient(\"Api Key\");  public static Dictionary&lt;long, Playlist> chat_playlist = new Dictionary&lt;long, Playlist>();  public static async Task HandleMessageAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) {   if (YTMusicController.credential == null)     await YTMusicController.Login();    Console.WriteLine(JsonConvert.SerializeObject(update));    if (update.Type == Telegram.Bot.Types.Enums.UpdateType.Message)   {     var message = update.Message;     String queryString = \"\";      if (message.Text != null)     {       if (message.Text.ToLower() == \"\/start\")       {         await botClient.SendTextMessageAsync(message.Chat, \"\u0414\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u043b\u043e\u0441\u0430\u0442\u044b\u0439\");         return;       }        if (message.Text.ToLower() == \"\/create\")       {         await YTMusicController.CreateNewPlaylist(message.Chat);       }        queryString = message.Text;       return;     }      if (message.Audio != null)     {       Audio audio = message.Audio;        queryString = audio.Performer;       queryString += \" - \" + audio.Title;     }      if ( chat_playlist != null &amp;&amp; chat_playlist.ContainsKey(message.Chat.Id))     {       await YTMusicController.AddToTestPlaylist(message.Chat, queryString);     }     else     {       String url = \"https:\/\/music.youtube.com\/search?q=\";       queryString = queryString.Replace(\" \", \"+\");       Console.WriteLine(url += queryString);        await botClient.SendTextMessageAsync(message.Chat, url);       return;     }   } }  public static async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken) {   Console.WriteLine(JsonConvert.SerializeObject(exception)); } }<\/code><\/pre>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0433\u043e\u0442\u043e\u0432\u043e. \u0412\u043e\u0442 \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<ol>\n<li>\n<p>\u0415\u0434\u0438\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u043e \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0431\u043e\u0442\u0430, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043b\u043e\u0433\u0438\u043d.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \/create, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e ID \u0447\u0430\u0442\u0430 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e(\u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \/create \u0431\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u0435\u0441\u043d\u044e).<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0431\u043e\u0442\u0443 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u0448\u044c \u043f\u0435\u0441\u043d\u044e, \u0438\u043b\u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0441\u043d\u0438, \u043e\u043d \u0438\u0449\u0435\u0442 \u0435\u0435 \u0432 YouTube, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442, \u0438 \u0442\u0430\u043c \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u0443 \u043f\u0435\u0441\u043d\u044e \u0432 \u043d\u0430\u0448 \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435, \u0432 \u0438\u0434\u0435\u0430\u043b\u0435, \u0431\u044b\u043b\u043e \u0431\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442\u043e\u0432 \u0432 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u043d\u0430 \u043e\u0431\u043b\u0430\u043a\u0435, \u0432 \u043a\u0440\u0430\u0439\u043d\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0445\u043e\u0442\u044f \u0431\u044b \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u0444\u0430\u0439\u043b(\u043e\u0434\u043d\u0430\u043a\u043e, \u044f \u043d\u0435 \u0437\u0430\u043c\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043b\u0441\u044f). <\/p>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e &#171;for fun&#187;, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0435 \u0441\u0443\u0434\u0438\u0442\u0435 \u0441\u0442\u0440\u043e\u0433\u043e:) <\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/669488\/\"> https:\/\/habr.com\/ru\/post\/669488\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041e\u0447\u0435\u043d\u044c \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0441\u043b\u0443\u0448\u0430\u043b \u043c\u0443\u0437\u044b\u043a\u0443 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 Telegram. \u0422\u0430\u043c \u0438 \u043f\u043e\u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u043c\u043e\u0436\u043d\u043e \u0438 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0442\u0435\u043b\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439. \u041d\u043e \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e &#8212; \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u043a\u043e\u0433\u0434\u0430 \u0441\u0432\u043e\u0439 \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442 \u043d\u0430\u0434\u043e\u0435\u0434\u0430\u0435\u0442 \u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0447\u0435\u0433\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0433\u043e. \u0412 YouTube Music \u0435\u0441\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u043e\u0439 \u043c\u0443\u0437\u044b\u043a\u043e\u0439. \u0427\u0442\u043e \u044f \u0438\u043c\u0435\u044e \u0432\u0432\u0438\u0434\u0443? \u041f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043b\u044e\u0431\u043e\u0439 \u043f\u0435\u0441\u043d\u0438, \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0440\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u043d\u043e\u0432\u044b\u0435 \u043c\u0443\u0437\u044b\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u044b \ud83d\ude42<\/p>\n<p>\u0412 \u0422\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c\u0435 \u0443 \u043c\u0435\u043d\u044f \u0431\u044b\u043b\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e \u0431\u043e\u043b\u0435\u0435 1000 \u043f\u0435\u0441\u0435\u043d. \u042f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0441\u043b\u0430\u043d\u043d\u0443\u044e \u043c\u0443\u0437\u044b\u043a\u0443 \u0438\u0437 \u0422\u0413, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442 \u0432 YouTube \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0435\u0441\u043d\u0438 \u0442\u0443\u0434\u0430. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438 \u0447\u0435\u043c\u0443-\u0442\u043e \u043d\u043e\u0432\u043e\u043c\u0443 \u043d\u0430\u0443\u0447\u0443\u0441\u044c \u0438 \u043f\u0435\u0441\u043d\u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0443(\u043d\u0443 \u0438 \u0435\u0441\u043b\u0438 \u043a\u043e\u043c\u0443-\u0442\u043e \u0438\u0437 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0445 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0443\u0441\u043b\u0443\u0433\u0438 \u043c\u043e\u0435\u0433\u043e \u0431\u043e\u0442\u0430, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0438\u043c \u0432\u0440\u0435\u043c\u044f, \u0445\u043e\u0442\u044f \u044f \u043c\u0430\u043b\u043e \u0432\u0435\u0440\u044e, \u0447\u0442\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f, \u044d\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u0443\u0447\u0435\u0431\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u043a). <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0439\u0442\u0438 \u0432 \u0442\u0433, \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/t.me\/BotFather\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0433\u043e \u0431\u043e\u0442\u0430<\/a>, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0435\u0433\u043e: <\/p>\n<figure class=\"bordered full-width\"><figcaption>\u0417\u0434\u0435\u0441\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043c\u043e\u0433\u043b\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430<\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e, \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0440\u043e\u0435\u043a\u0442 .NET 5 \u0432 Visual Studio 2019. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f NuGet, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e, \u044d\u0442\u0438 4 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><code>Newtonsoft.Json<\/code> &#8212; \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439, \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u0432 .NET: <br \/><code>using System.Text.Json;<\/code><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u043b \u043a\u043b\u0430\u0441\u0441 Brain, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435\u043c\u0438 <s>\u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u043c\u0438<\/s> \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u0431\u043e\u0442\u0430:<\/p>\n<pre><code>class Brain {  public static ITelegramBotClient Bot { get; set; } =  new TelegramBotClient(\"token\"); \/\/ \u0417\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u0441\u0432\u043e\u0439 \u0442\u043e\u043a\u0435\u043d  public static async Task HandleMessageAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) {   Console.WriteLine(JsonConvert.SerializeObject(update));    if (update.Type == Telegram.Bot.Types.Enums.UpdateType.Message)   {     var message = update.Message;     String queryString = \"\";      if (message.Text != null)     {       if (message.Text.ToLower() == \"\/start\")       {         \/\/ \u0422\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0443 \u0434\u043b\u044f \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f, \u0438\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \/\/ \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0431\u043e\u0442\u0430, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u0430\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f         await botClient.SendTextMessageAsync(message.Chat, \"\u0414\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u043b\u043e\u0441\u0430\u0442\u044b\u0439\");         return;       }        queryString = message.Text;\/\/ \u0415\u0441\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0441\u043d\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u043c, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \/\/ \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0441\u043b\u0430\u0442\u044c \u0435\u0435. \u042d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0442\u043e\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c \u0442\u0435\u043a\u0441\u0442, \/\/ \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u044e\u0442 \u0431\u043e\u0442\u0443     }      if (message.Audio != null) \/\/\u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043c\u0443\u0437\u044b\u043a\u0430, \u0431\u0435\u0440\u0435\u043c \u0438\u043c\u044f \u0430\u0432\u0442\u043e\u0440\u0430 \u0438 \u043f\u0435\u0441\u043d\u0438     {       Audio audio = message.Audio;        queryString = audio.Performer;       queryString += \" - \" + audio.Title;     }         String url = \"https:\/\/music.youtube.com\/search?q=\";       queryString = queryString.Replace(\" \", \"+\");       Console.WriteLine(url += queryString);        await botClient.SendTextMessageAsync(message.Chat, url);       return;   } }  public static async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken) {   Console.WriteLine(JsonConvert.SerializeObject(exception)); } }<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 Program \u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c Main:<\/p>\n<pre><code>class Program  { static void Main(string[] args) {   Console.WriteLine($\"Bot has been started: {Brain.Bot.GetMeAsync().Result.FirstName}\");    var cts = new CancellationTokenSource();   var cancellationToken = cts.Token;   var receiverOptions = new ReceiverOptions   {     AllowedUpdates = { },   };    Brain.Bot.StartReceiving(       Brain.HandleMessageAsync,       Brain.HandleErrorAsync,       receiverOptions,       cancellationToken   );    Console.ReadLine(); } }<\/code><\/pre>\n<p>\u0418\u0442\u0430\u043a, \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043d\u0430\u0448 \u0431\u043e\u0442 \u0443\u0436\u0435 \u0443\u043c\u0435\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0438 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043f\u0435\u0441\u043d\u0438. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043e\u043d \u0431\u0435\u0440\u0435\u0442 \u0438\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u0432 query string, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043a \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c\u0443 url&#8217;\u0443 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0432 \u043e\u0442\u0432\u0435\u0442. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<figure class=\"float full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0435\u043c\u0443 \u0443\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u0430\u0442\u044c \u043f\u0435\u0441\u043d\u0438 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c\u0438 \u043f\u0430\u0447\u043a\u0430\u043c\u0438, \u0432 \u043e\u0442\u0432\u0435\u0442 \u043e\u0442 \u043f\u0440\u0438\u0441\u044b\u043b\u0430\u0435\u0442 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u043d\u0438\u0445 \ud83d\ude42<br \/>\u042d\u0442\u043e \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u043d\u043e \u043c\u044b \u0443\u0436\u0435 \u0431\u043b\u0438\u0436\u0435 \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442, \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043f\u0435\u0441\u043d\u0438 \u0442\u0443\u0434\u0430. \u0427\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0433\u0443\u0433\u043b, \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c OAuth2. \u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438: \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0432\u044b\u0437\u043e\u0432\u0430 \u0430\u043f\u0438 YouTube(YouTube Data API v3) \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b OAuth2 \u043b\u043e\u0433\u0438\u043d.<\/p>\n<p>\u041e\u043f\u0438\u0441\u0430\u043b \u043a\u043b\u0430\u0441\u0441 YTMusicController:<\/p>\n<pre><code>class YTMusicController  {  private static String client_id = \"your client id\";  private static String client_secret = \"your client secret\";   internal static UserCredential credential;  private static YouTubeService youTubeService = new YouTubeService(new BaseClientService.Initializer() {   ApiKey = \"your api key\", \/\/ \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0433\u0443\u0433\u043b \u043a\u043e\u043d\u0441\u043e\u043b\u0438   HttpClientInitializer = Brain.credential,   ApplicationName = \"YTMusic\" });  private static void Reinit()   {     youTubeService = new YouTubeService(new BaseClientService.Initializer()     {       ApiKey = \"AIzaSyDLk83ykqHtYOOjDwtvZvSf5S7wOIvGeGY\",       HttpClientInitializer = credential,       ApplicationName = \"YTMusic\"     });   }    public static async Task Login() \/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0438\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OAuth2   {                                \/\/ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0431\u043e\u0442\u0430     var client_secrets = new ClientSecrets();     client_secrets.ClientId = YTMusicController.client_id;     client_secrets.ClientSecret = YTMusicController.client_secret     credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(       client_secrets,       new[] { YouTubeService.Scope.Youtube },       \"user\",       CancellationToken.None,       new FileDataStore(\"YTMusicBrain\")       );        Reinit(); \/\/ \u043f\u0435\u0440\u0435\u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 YouTubeService \u0441 \u0423\u0416\u0415 \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0435\u043d\u043d\u044b\u043c \u044e\u0437\u0435\u0440\u043e\u043c   }      public static async Task CreateNewPlaylist(Chat chatId)   {     Playlist playlist = new Playlist();     playlist.Snippet = new PlaylistSnippet();     var t = Guid.NewGuid().ToString(); \/\/ \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442 \u0441 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u0438\u043c\u0435\u043d\u0435     playlist.Snippet.Title = t;     playlist.Snippet.Description = \"This playlist created automatically\";     playlist.Status = new PlaylistStatus();     playlist.Status.PrivacyStatus = \"public\";     playlist = await youTubeService.Playlists.Insert(playlist, \"snippet, status\").ExecuteAsync(); \/\/ \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442\u0430 \u044f \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u0435\u0433\u043e \u0432 \u043c\u0430\u043f\u0443 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0445\u0440\u0430\u043d\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \/\/ \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442\u0430 \u043f\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0447\u0430\u0442     Brain.chat_playlist.Add(chatId.Id, playlist);      public static async Task&lt;SearchResult> Search(String searchQuery)   {     var searchListResult = youTubeService.Search.List(\"snippet\"); \/\/ \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043b\u044f      searchListResult.Q = searchQuery;                    \/\/ \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u043f\u0435\u0441\u043d\u0438     searchListResult.MaxResults = 1     var response = await searchListResult.ExecuteAsync();\/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e     return response.Items[0];      public static async Task AddToTestPlaylist(Chat chatId, String searchQuery)   {     Playlist main = Brain.chat_playlist[chatId.Id];     var temp = new PlaylistItem()     var resultOfSearch = await Search(searchQuery); \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0443\u044e \u043f\u0435\u0441\u043d     temp.Snippet = new PlaylistItemSnippet();     temp.Snippet.PlaylistId = main.Id;     temp.Snippet.ResourceId = new ResourceId();     temp.Snippet.ResourceId.Kind = \"youtube#video\";     temp.Snippet.ResourceId.VideoId = resultOfSearch.Id.VideoId; \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0432 \u043d\u0430\u0448 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439     await youTubeService.PlaylistItems.Insert(temp, \"snippet\").ExecuteAsync();     return;   } } <\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043b \u043a\u043e\u043c\u0430\u043d\u0434\u0443 &#171;\/create&#187; \u0447\u0435\u0440\u0435\u0437 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e\u0433\u043e \u0432\u044b\u0448\u0435 \u0431\u043e\u0442\u0430. \u041f\u043e\u0441\u043b\u0435 \u0435\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442 \u0432 YouTube.  \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e HandleMessageAsync \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c: <code> <\/code><\/p>\n<pre><code>if (YTMusicController.credential == null)    { await YTMusicController.Login();  } \/\/ ... ..... ... \/\/ if (message.Text.ToLower() == \"\/create\")   {     await YTMusicController.CreateNewPlaylist(message.Chat);   }    if ( chat_playlist != null &amp;&amp; chat_playlist.ContainsKey(message.Chat.Id))   {     await YTMusicController.AddToTestPlaylist(message.Chat, queryString);   } \/\/ \u0435\u0441\u043b\u0438 \u043f\u043b\u0435\u0439\u043b\u0438\u0441\u0442 \u0435\u0441\u0442\u044c \u0432 \u0441\u043f\u0438\u0441\u043a\u0435, \u043c\u044b \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u0443\u044e \u043f\u0435\u0441\u043d\u044e \/\/ \u0438\u043d\u0430\u0447\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u0435\u0441\u043d\u044e   else   {     String url = \"https:\/\/music.youtube.com\/search?q=\";     queryString = queryString.Replace(\" \", \"+\");     Console.WriteLine(url += queryString);      await botClient.SendTextMessageAsync(message.Chat, url);     return;   }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 Brain:<\/p>\n<pre><code>class Brain  {  public static ITelegramBotClient Bot { get; set; } = new TelegramBotClient(\"Api Key\");  public static Dictionary&lt;long, Playlist> chat_playlist = new Dictionary&lt;long, Playlist>();  public static async Task HandleMessageAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) {   if (YTMusicController.credential == null)     await YTMusicController.Login();    Console.WriteLine(JsonConvert.SerializeObject(update));    if (update.Type == Telegram.Bot.Types.Enums.UpdateType.Message)   {     var message = update.Message;     String queryString = \"\";      if (message.Text != null)     {       if (message.Text.ToLower() == \"\/start\")       {         await botClient.SendTextMessageAsync(message.Chat, \"\u0414\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c, \u043f\u043e\u043b\u043e\u0441\u0430\u0442\u044b\u0439\");         return;       }        if (message.Text.ToLower() == \"\/create\")       {         await YTMusicController.CreateNewPlaylist(message.Chat);       }        queryString = message.Text;       return;     }      if (message.Audio != null)     {       Audio audio = message.Audio;        queryString = audio.Performer;       queryString += \" - \" + audio.Title;     }      if ( chat_playlist != null &amp;&amp; chat_playlist.ContainsKey(message.Chat.Id))     {       await YTMusicController.AddToTestPlaylist(message.Chat, queryString);     }     else     {       String url = \"https:\/\/music.youtube.com\/search?q=\";       queryString = queryString.Replace(\" \", \"+\");       Console.WriteLine(url += queryString);        await botClient.SendTextMessageAsync(message.Chat, url);       return;     }   } }  public static async Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-334017","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=334017"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334017\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=334017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=334017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=334017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}