<p><ahref="https://gitter.im/TLSharp/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><imgsrc="https://badges.gitter.im/TLSharp/Lobby.svg"alt="Join the chat at https://gitter.im/TLSharp/Lobby"></a>
<p>It's a perfect fit for any developer who would like to send data directly to Telegram users or write own custom Telegram client.</p>
<p><g-emojialias="star2"fallback-src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f31f.png"ios-version="6.0">🌟</g-emoji> If you <g-emojialias="heart"fallback-src="https://assets-cdn.github.com/images/icons/emoji/unicode/2764.png"ios-version="6.0">❤️</g-emoji> library, please star it! <g-emojialias="star2"fallback-src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f31f.png"ios-version="6.0">🌟</g-emoji></p>
<h1>
<aid="table-of-contents"class="anchor"href="#table-of-contents"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>Table of contents?</h1>
<ul>
<li><ahref="#how-do-i-add-this-to-my-project">How do I add this to my project?</a></li>
<aid="how-do-i-add-this-to-my-project"class="anchor"href="#how-do-i-add-this-to-my-project"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>How do I add this to my project?</h1>
<p>Telegram API isn't that easy to start. You need to do some configuration first.</p>
<ol>
<li>Create a <ahref="https://my.telegram.org/">developer account</a> in Telegram. </li>
<li>Goto <ahref="https://my.telegram.org/apps">API development tools</a> and copy <strong>API_ID</strong> and <strong>API_HASH</strong> from your account. You'll need it later.</li>
<p>Now you can work with Telegram API, but -></p>
<blockquote>
<p>Only a small portion of the API methods are available to unauthorized users. (<ahref="https://core.telegram.org/api/auth">full description</a>) </p>
</blockquote>
<p>For authentication you need to run following code</p>
<spanclass="pl-k">var</span> code = <spanclass="pl-s"><spanclass="pl-pds">"</span><code_from_telegram><spanclass="pl-pds">"</span></span>; <spanclass="pl-c">// you can change code in debugger</span>
<spanclass="pl-k">var</span> user = <spanclass="pl-k">await</span> client.MakeAuthAsync(<spanclass="pl-s"><spanclass="pl-pds">"</span><user_number><spanclass="pl-pds">"</span></span>, hash, code);</pre></div>
<p>Full code you can see at <ahref="https://github.com/sochix/TLSharp/blob/master/TLSharp.Tests/TLSharpTests.cs#L70">AuthUser test</a></p>
<p>When user is authenticated, TLSharp creates special file called <em>session.dat</em>. In this file TLSharp store all information needed for user session. So you need to authenticate user every time the <em>session.dat</em> file is corrupted or removed.</p>
<p>You can call any method on authenticated user. For example, let's send message to a friend by his phone number:</p>
<divclass="highlight highlight-source-cs"><pre><spanclass="pl-c">//get available contacts</span>
<spanclass="pl-k">var</span> result = <spanclass="pl-k">await</span> client.GetContactsAsync();
<spanclass="pl-c">//find recipient in contacts</span>
<spanclass="pl-k">var</span> user = result.users.lists
<p>Full code you can see at <ahref="https://github.com/sochix/TLSharp/blob/master/TLSharp.Tests/TLSharpTests.cs#L107">SendMessageToChannel test</a></p>
<aid="working-with-files"class="anchor"href="#working-with-files"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>Working with files</h2>
<p>Telegram separate files to two categories -> big file and small file. File is Big if its size more than 10 Mb. TLSharp tries to hide this complexity from you, thats why we provide one method to upload files <strong>UploadFile</strong>.</p>
<spanclass="pl-k">new</span> TLVector<TLAbsDocumentAttribute>()); <spanclass="pl-c">//document attributes, such as file name</span></pre></div>
<p>Full code you can see at <ahref="https://github.com/sochix/TLSharp/blob/master/TLSharp.Tests/TLSharpTests.cs#L125">SendPhotoToContactTest</a> and <ahref="https://github.com/sochix/TLSharp/blob/master/TLSharp.Tests/TLSharpTests.cs#L143">SendBigFileToContactTest</a></p>
<p>To download file you should call <strong>GetFile</strong> method</p>
document.size); <spanclass="pl-c">//size of fileChunk you want to retrieve</span></pre></div>
<p>Full code you can see at <ahref="https://github.com/sochix/TLSharp/blob/master/TLSharp.Tests/TLSharpTests.cs#L167">DownloadFileFromContactTest</a></p>
<aid="what-things-can-i-implement-project-roadmap"class="anchor"href="#what-things-can-i-implement-project-roadmap"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>What things can I Implement (Project Roadmap)?</h2>
<aid="what-api-layer-is-supported"class="anchor"href="#what-api-layer-is-supported"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>What API layer is supported?</h4>
<aid="i-get-an-error-migrate_x"class="anchor"href="#i-get-an-error-migrate_x"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>I get an error MIGRATE_X?</h4>
<p>TLSharp library should automatically handle this errors. If you see such errors, pls create a new issue.</p>
<h4>
<aid="i-get-an-exception-systemioendofstreamexception-unable-to-read-beyond-the-end-of-the-stream-all-test-methos-except-that-authenticationworks-and-testconnection-return-same-error-i-did-every-thing-including-setting-api-id-and-hash-and-setting-server-address-"class="anchor"href="#i-get-an-exception-systemioendofstreamexception-unable-to-read-beyond-the-end-of-the-stream-all-test-methos-except-that-authenticationworks-and-testconnection-return-same-error-i-did-every-thing-including-setting-api-id-and-hash-and-setting-server-address-"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>I get an exception: System.IO.EndOfStreamException: Unable to read beyond the end of the stream. All test methos except that AuthenticationWorks and TestConnection return same error. I did every thing including setting api id and hash, and setting server address.-</h4>
<p>You should create a Telegram session. See <ahref="#sending-messages-set-up">configuration guide</a></p>
<h4>
<aid="why-i-get-flood_wait-error"class="anchor"href="#why-i-get-flood_wait-error"aria-hidden="true"><spanaria-hidden="true"class="octicon octicon-link"></span></a>Why I get FLOOD_WAIT error?</h4>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
<spanclass="site-footer-owner"><ahref="https://github.com/sochix/TLSharp">TLSharp</a> is maintained by <ahref="https://github.com/sochix">sochix</a>.</span>
<spanclass="site-footer-credits">This page was generated by <ahref="https://pages.github.com">GitHub Pages</a> using the <ahref="https://github.com/jasonlong/cayman-theme">Cayman theme</a> by <ahref="https://twitter.com/jasonlong">Jason Long</a>.</span>