OpenTl.ClientApi icon indicating copy to clipboard operation
OpenTl.ClientApi copied to clipboard

RecieveUpdates not working without SignIn

Open TedevFR opened this issue 6 years ago • 9 comments

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 ?

TedevFR avatar May 01 '18 13:05 TedevFR

Hello, @TedevFR Show the method code of CreateFactorySettings

vik-borisov avatar May 03 '18 03:05 vik-borisov

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;
}

TedevFR avatar May 03 '18 16:05 TedevFR

Try to call _clientApi.KeepAliveConnection()

hzexe avatar May 04 '18 08:05 hzexe

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

vik-borisov avatar May 04 '18 13:05 vik-borisov

@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 ?

TedevFR avatar May 05 '18 13:05 TedevFR

@TedevFR The session was found. All is well

vik-borisov avatar May 05 '18 14:05 vik-borisov

@TedevFR Can you create a simple test with bug?

vik-borisov avatar May 06 '18 05:05 vik-borisov

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 avatar May 27 '18 19:05 parabola949

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?

parabola949 avatar May 27 '18 19:05 parabola949