{"id":13486049,"url":"https://github.com/navaei/TeleNet","last_synced_at":"2025-03-27T20:32:04.076Z","repository":{"id":55054436,"uuid":"521852315","full_name":"navaei/TeleNet","owner":"navaei","description":"Telegram MTProto API Client Library for .Net","archived":false,"fork":false,"pushed_at":"2023-06-20T06:57:14.000Z","size":704,"stargazers_count":24,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-01T18:25:26.700Z","etag":null,"topics":["csharp","dotnet","mtproto","telegram","telegram-api","telenet","tlsharp"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/navaei.png","metadata":{"files":{"readme":"ReadMe.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-06T05:07:13.000Z","updated_at":"2024-07-09T11:24:06.000Z","dependencies_parsed_at":"2022-08-14T10:20:17.660Z","dependency_job_id":null,"html_url":"https://github.com/navaei/TeleNet","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/navaei%2FTeleNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/navaei%2FTeleNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/navaei%2FTeleNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/navaei%2FTeleNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/navaei","download_url":"https://codeload.github.com/navaei/TeleNet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222313549,"owners_count":16965322,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","mtproto","telegram","telegram-api","telenet","tlsharp"],"created_at":"2024-07-31T18:00:38.614Z","updated_at":"2024-10-30T21:30:41.766Z","avatar_url":"https://github.com/navaei.png","language":"C#","readme":"TeleNet(Telegram + .Net)\n-------------------------------\n\nA simple _Unofficial_ Telegram (http://telegram.org) MTProto client implemented in C#.\nThe Api client library that implements the MtProto 2.0 protocol is supported by .Net \u003e= 6\n\n\n# Starter Guide\n\n\n## Telegram API and MTPROTO:\nIf you want more information about Telegram API, you can go [here](https://core.telegram.org/api#telegram-api). And [here](https://core.telegram.org/mtproto) you will find extra information about mtproto.\n\n## Quick Configuration\nYou need to do some configuration first.\n\n1. Create a [developer account](https://my.telegram.org/) in Telegram. \n1. Goto [API development tools](https://my.telegram.org/apps) and copy **API_ID** and **API_HASH** from your account. You'll need it later.\n\n\n## First requests\n\nTo start work, create an instance of TelegramClient and establish connection:\n\n```csharp \n    var client = new TelegramClient(apiId, apiHash);\n    await client.ConnectAsync();\n```\n\nNow you can work with Telegram API, but -\u003e\n\n\u003e Only a small portion of the API methods are available to unauthorized users. ([full description](https://core.telegram.org/api/auth)) \n\nFor authentication you need to run following code:\n\n```csharp\n    var hash = await client.SendCodeRequestAsync(\"\u003cuser_number\u003e\");\n    var code = \"\u003ccode_from_telegram\u003e\"; // you can change code in debugger\n\n    var user = await client.MakeAuthAsync(\"\u003cuser_number\u003e\", hash, code);\n``` \n\nWhen the user is authenticated, TeleNet creates special file called _session.dat_. In this file TeleNet stores all information needed for the user's session. So you need to authenticate user every time the _session.dat_ file is corrupted or removed.\n\nYou can call any method on authenticated users. For example, let's send message to a friend by his phone number:\n\n```csharp\n    //get available contacts\n    var result = await client.GetContactsAsync();\n\n    //find recipient in contacts\n    var user = result.Users\n                     .OfType\u003cTLUser\u003e()\n                     .FirstOrDefault(x =\u003e x.Phone == \"\u003crecipient_phone\u003e\");\n\n    //send message\n    await client.SendMessageAsync(new TLInputPeerUser() { UserId = user.Id }, \"OUR_MESSAGE\");\n```\n\nTo send a message to a channel you could use the following code:\n\n```csharp\n    //get user dialogs\n    var dialogs = (TLDialogsSlice) await client.GetUserDialogsAsync();\n\n    //find channel by title\n    var chat = dialogs.Chats\n                      .OfType\u003cTLChannel\u003e()\n                      .FirstOrDefault(c =\u003e c.Title == \"\u003cchannel_title\u003e\");\n\n    //send message\n    await client.SendMessageAsync(new TLInputPeerChannel() { ChannelId = chat.Id, AccessHash = chat.AccessHash.Value }, \"OUR_MESSAGE\");\n```\n\n\n## Working with files\n\nTelegram separate files to two categories -\u003e big file and small file. File is Big if its size more than 10 Mb. TeleNet tries to hide this complexity from you, thats why we provide one method to upload files **UploadFile**.\n\n```csharp\n    var fileResult = await client.UploadFile(\"cat.jpg\", new StreamReader(\"data/cat.jpg\"));\n```\n\nTeleNet provides two wrappers for sending photo and document:\n\n```csharp\n    await client.SendUploadedPhoto(new TLInputPeerUser() { UserId = user.Id }, fileResult, \"kitty\");\n    await client.SendUploadedDocument(new TLInputPeerUser() { UserId = user.Id },\n                                      fileResult,\n                                      \"application/zip\", //mime-type\n\n                                      //document attributes, such as file name\n                                      new TLVector\u003cTLAbsDocumentAttribute\u003e());\n```\n\n\nTo download a file you should call the **GetFile** method:\n\n```csharp\n    await client.GetFile(new TLInputDocumentFileLocation()\n                         {\n                             AccessHash = document.AccessHash,\n                             Id = document.Id,\n                             FileReference = document.FileReference,\n                             ThumbSize = \"250x250\"\n                         },\n\n                         //size of fileChunk you want to retrieve\n                         document.Size);\n```\n\n\n# Available Methods\n\nFor your convenience TeleNet have wrappers for several Telegram API methods. You could add your own, see details below.\n\n1. SendCodeRequestAsync\n1. MakeAuthAsync\n1. GetContactsAsync\n1. SendMessageAsync\n1. SendTypingAsync\n1. GetUserDialogsAsync\n1. SendUploadedPhoto\n1. SendUploadedDocument\n1. GetFile\n1. UploadFile\n1. SendPingAsync\n1. GetHistoryAsync\n1. UpdateStatusAsync\n1. SearchUserAsync\n1. SignUpAsync\n\n\n**What if you can't find needed method at the list?**\n\nDon't panic. You can call any method with help of `SendRequestAsync` function. For example, send user typing method:\n\n```csharp\n    //Create request\n    var req = new TLRequestSetTyping()\n    {\n        Action = new TLSendMessageTypingAction(),\n        Peer = new TLInputPeerUser() { UserId = user.Id }\n    };\n\n    //run request, and deserialize response to Boolean\n    return await client.SendRequestAsync\u003cBoolean\u003e(req);\n``` \n\n\n**Where can you find a list of requests and its parameters?**\n\nThe only way is [Telegram API docs](https://core.telegram.org/methods). Yes, it's no longer outdated.\nLatest scheme in JSON format you can find [here](https://core.telegram.org/schema/json)\n\n\n# Special Thanks\n\n* [sochix](https://github.com/sochix) - Original TLSharp author\n* [Afshin Arani](http://aarani.ir) - TLGenerator, and a lot of other usefull things\n\n\n## License\nPlease, provide link to the original authors when using library\n\nThe project is released under the [Mit License](./LICENSE)\n\nCopyright (c) 2015 Ilya Pirozhenko ([sochix](https://github.com/sochix))\n\nCopyright (c) 2015-2020 TLSharp/TgSharp contributors\n","funding_links":[],"categories":["C#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnavaei%2FTeleNet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnavaei%2FTeleNet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnavaei%2FTeleNet/lists"}