This repository was archived by the owner on Mar 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Quick Start
Viktor Borisov edited this page Feb 17, 2018
·
9 revisions
var client = ClientFactory.BuildClient(new FactorySettings { Id = ApiId, Hash = ApiHash, ServerAddress = _ServerAddress, ServerPort = _ServerPort, StoreProvider = new TelegramClient.Core.Sessions.FileSessionStoreProvider("session")});Parameters ApiId, ApiHash, ServerAddress, ServerPort you can get on the official page Telegram
await client.ConnectService.ConnectAsync();Ask Telegram send us a phone authentication code
var hash= await client.AuthService.SendCodeRequestAsync(NumberToAuthenticate);We write the code from the SMS into the variable code
Sending to Telegram authenticate request
var user = await client.AuthService.MakeAuthAsync(NumberToAuthenticate, hash, code);If user have two factor authentification, then code must be
TUser user;
try
{
user = await client.AuthService.MakeAuthAsync(NumberToAuthenticate, hash, code);
}
catch (CloudPasswordNeededException)
{
var password = (TPassword) await client.AuthService.GetPasswordSetting();
var passwordStr = PasswordToAuthenticate;
user = await client.AuthService.MakeAuthWithPasswordAsync(password, passwordStr);
}The Telegram client saves the session in the bin folder of your application after successful authentication. The default name is session.dat. Authentication is performed once, the next time a session file is used.
Check passed authentication through method
var isAuthorized = client.AuthService.IsUserAuthorized();client.Updates.RecieveUpdates += update =>
{
// handle updates
};await client.MessagesService.SendMessageAsync(new TInputPeerUser{ UserId = userId}, messsage);