Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

RecieveUpdates not working without SignIn #9

Open
TedevFR opened this issue May 1, 2018 · 9 comments
Open

RecieveUpdates not working without SignIn #9

TedevFR opened this issue May 1, 2018 · 9 comments
Labels

Comments

@TedevFR
Copy link

TedevFR commented May 1, 2018

I followed the quick start guide and managed to have the updates coming using the clientApi.UpdatesService.RecieveUpdates event

When starting my app again, the clientApi.AuthService.CurrentUserId is not null (which is a good thing) so i'm not asking telegram to send a phone code again and i'm not calling the SignInAsync method either. This time, the updates are not coming (and i double checked that i subscribed correctly to the event).

I think i'm missing something, maybe a SignIn method without phone code or something to initiate the connection with telegram but i can't find anything like that anywhere

My code looks like this :

            var settings = CreateFactorySettings();
            _clientApi = await ClientFactory.BuildClientAsync(settings).ConfigureAwait(false);
            _clientApi.UpdatesService.RecieveUpdates += UpdatesService_RecieveUpdates;

            if (!_clientApi.AuthService.CurrentUserId.HasValue)
            {
                var phone = "+XXXXX";
                var sentCode = await _clientApi.AuthService.SendCodeAsync(phone).ConfigureAwait(false);

                TUser user;
                try
                {
                    var msg = new AuthenticationCodeRequestMessage(this, "AuthenticateWithCodeRequest", async (code) =>
                    {
                        if (!string.IsNullOrWhiteSpace(code))
                        {
                            user = await _clientApi.AuthService.SignInAsync(phone, sentCode, code).ConfigureAwait(false);
                        }
                    });

                    Messenger.Default.Send(msg);
                }
                catch (CloudPasswordNeededException)
                {
                    user = await _clientApi.AuthService.CheckCloudPasswordAsync(passwordStr).ConfigureAwait(false);
                }
                catch (PhoneCodeInvalidException)
                {
                }
            }
...
        private Task UpdatesService_RecieveUpdates(IUpdates update)
        {
                return Task.CompletedTask;
        }

Please, what am i missing ?

@vik-borisov
Copy link
Member

Hello, @TedevFR
Show the method code of CreateFactorySettings

@TedevFR
Copy link
Author

TedevFR commented May 3, 2018

Sure, here it is :

private FactorySettings CreateFactorySettings()
{
	var properties = new ApplicationProperties();
	properties.AppVersion = "1.0.0";
	properties.DeviceModel = "PC";
	properties.LangCode = "en";
	properties.LangPack = "tdesktop";
	properties.SystemLangCode = "en";
	properties.SystemVersion = "Win 10 Pro";

	var settings = new FactorySettings();
	settings.AppHash = "X";
	settings.AppId = X;
	settings.ServerAddress = "149.154.167.50";
	settings.ServerPublicKey = @"-----BEGIN RSA PUBLIC KEY-----
X
X
X
X
X
X
-----END RSA PUBLIC KEY-----";
	settings.ServerPort = 443;
	settings.SessionTag = "session";
	settings.Properties = properties;

	return settings;
}

@hzexe
Copy link

hzexe commented May 4, 2018

Try to call _clientApi.KeepAliveConnection()

@vik-borisov
Copy link
Member

@TedevFR
try to attach the logger
https://github.com/OpenTl/OpenTl.ClientApi/wiki/How-to-attach-a-logger
and get me the logs

@TedevFR
Copy link
Author

TedevFR commented May 5, 2018

@hzexe Thank you, I just tried but this doesn't fix the problem

@vik-borisov The logs i get when initializing with above code :

2018-05-05 14:57:47,505 [1] DEBUG OpenTl.ClientApi.Settings.FileSessionStore.Load - Load session for sessionTag = [...]\session.dat
2018-05-05 14:57:47,763 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Top.Adapters.TopHandlerAdapter.ChannelActive - #1639866447174420602: Session was found.
2018-05-05 14:57:47,768 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Top.Adapters.TopHandlerAdapter.UserEventTriggered - #1639866447174420602: Handshake is complete
2018-05-05 14:57:47,777 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Top.Adapters.TopHandlerAdapter.MoveNext - #1639866447174420602: Send init connection request
2018-05-05 14:57:47,844 [8] DEBUG OpenTl.ClientApi.Settings.FileSessionStore.MoveNext - Save session into [...]\session.dat
2018-05-05 14:57:48,012 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Secure.Codecs.SecureRequestEncoder.Encode - #1639866447174420602: Send secure message OpenTl.Schema.RequestInvokeWithLayer with messageId = 6552080266834215100 and sequenceNumber = 43
2018-05-05 14:57:48,015 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Tcp.TcpLayerHandlerAdapter.WriteAsync - #1639866447174420602: Send the message with sequence number 0
2018-05-05 14:57:48,055 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Tcp.TcpLayerHandlerAdapter.ChannelRead - #1639866447174420602: Recieve the message with sequence number 0
2018-05-05 14:57:48,061 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Secure.Codecs.SecureRequestDecoder.Decode - #1639866447174420602: Recieve the secure message OpenTl.Schema.TBadServerSalt
2018-05-05 14:57:48,063 [8] INFO  OpenTl.ClientApi.MtProto.Layers.Messages.Adapters.BadServerSaltHandler.ChannelRead0 - #1639866447174420602: Bad server sault detected! message id = 6552080266834215100 
2018-05-05 14:57:48,065 [8] DEBUG OpenTl.ClientApi.Settings.FileSessionStore.MoveNext - Save session into [...]\session.dat
2018-05-05 14:57:48,071 [8] DEBUG OpenTl.ClientApi.Settings.FileSessionStore.MoveNext - Save session into [...]\session.dat
2018-05-05 14:57:48,078 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Secure.Codecs.SecureRequestEncoder.Encode - #1639866447174420602: Send secure message OpenTl.Schema.RequestInvokeWithLayer with messageId = 6552080267996037312 and sequenceNumber = 45
2018-05-05 14:57:48,078 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Tcp.TcpLayerHandlerAdapter.WriteAsync - #1639866447174420602: Send the message with sequence number 1
2018-05-05 14:57:48,097 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Tcp.TcpLayerHandlerAdapter.ChannelRead - #1639866447174420602: Recieve the message with sequence number 1
2018-05-05 14:57:48,100 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Secure.Codecs.SecureRequestDecoder.Decode - #1639866447174420602: Recieve the secure message OpenTl.Schema.MsgContainer
2018-05-05 14:57:48,101 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Messages.Adapters.MsgContainerHandler.Decode - #1639866447174420602: Process MsgContainer message with 2 items
2018-05-05 14:57:48,103 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Messages.Adapters.NewSessionCreatedHandler.ChannelRead0 - #1639866447174420602: Handle a new session was created
2018-05-05 14:57:48,107 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Messages.Adapters.MsgsAckHandler.ChannelRead0 - #1639866447174420602: Receiving confirmation of the messages: [6552080267996037312]
2018-05-05 14:57:48,145 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Tcp.TcpLayerHandlerAdapter.ChannelRead - #1639866447174420602: Recieve the message with sequence number 2
2018-05-05 14:57:48,146 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Secure.Codecs.SecureRequestDecoder.Decode - #1639866447174420602: Recieve the secure message OpenTl.Schema.TRpcResult
2018-05-05 14:57:48,147 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Messages.Adapters.RpcResultHandler.ChannelRead0 - #1639866447174420602: Process RpcResult  with request id = '6552080267996037312'
2018-05-05 14:57:48,150 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Messages.Adapters.RpcResultHandler.ChannelRead0 - {"PackedData":"X"}
2018-05-05 14:57:48,150 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Messages.Adapters.RpcResultHandler.ChannelRead0 - #1639866447174420602: Try unzip
2018-05-05 14:57:48,152 [8] DEBUG OpenTl.ClientApi.MtProto.Layers.Messages.Adapters.GZipPackedHandler.UnzipPackage - #1639866447174420602: Process TgZipPacked message

Bad Server Salt... Do you have an idea why it happens and what i can do to fix it ?

@vik-borisov
Copy link
Member

vik-borisov commented May 5, 2018

@TedevFR The session was found. All is well

@vik-borisov
Copy link
Member

@TedevFR Can you create a simple test with bug?

@parabola949
Copy link

I'm having this same issue. In my app startup, I configure the client and register my event handler.
I get zero events, unless I log in.

        internal static async Task ConfigureClient()
        {
            Log.WriteLine("Configuring settings");
            var settings = new FactorySettings
            {
                AppHash = Properties.Settings.Default.TelegramApiHash,
                AppId = Properties.Settings.Default.TelegramAppId,
                ServerAddress = Properties.Settings.Default.TelegramIp,
                ServerPublicKey = Properties.Settings.Default.PublicKey,
                ServerPort = 443,
                SessionTag = "telecord", // by defaut
                Properties = new ApplicationProperties
                {
                    AppVersion = "1.0.0", // You can leave as in the example
                    DeviceModel = "PC", // You can leave as in the example
                    LangCode = "en", // You can leave as in the example
                    LangPack = "tdesktop", // You can leave as in the example
                    SystemLangCode = "en", // You can leave as in the example
                    SystemVersion = "Win 10 Pro" // You can leave as in the example
                }
            };

            clientApi = await ClientFactory.BuildClientAsync(settings).ConfigureAwait(false);
            Log.WriteLine("Connected, creating event handler");
            clientApi.KeepAliveConnection();
            clientApi.UpdatesService.RecieveUpdates += UpdatesService_RecieveUpdates;
        }

@parabola949
Copy link

parabola949 commented May 27, 2018

Update:
I was finally able to get it to start receiving updates by change the last few lines to this:

            clientApi = await ClientFactory.BuildClientAsync(settings).ConfigureAwait(false);
            Log.WriteLine("Connected, creating event handler");
            clientApi.UpdatesService.RecieveUpdates += UpdatesService_RecieveUpdates;
            if (clientApi.AuthService.CurrentUserId.HasValue)
            {
                await clientApi.UsersService.GetCurrentUserFullAsync();
            }

Curious if this: ClientSettings.ConnectionWasInitialize() has something to do with it?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants