question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple connections

See original GitHub issue

I have code like this.

const { StringSession } = require('telegram/sessions')
const input = require('input') // npm i input

const apiId = 111111
const apiHash = 'fcf............................'
const stringSession = new StringSession(''); // fill this later with the value from session.save()
(async () => {
    console.log('Loading interactive example...')
    const client = new TelegramClient(stringSession, apiId, apiHash, { connectionRetries: 5 })
    await client.start({
        phoneNumber: async () => await input.text('number ?'),
        password: async () => await input.text('password?'),
        phoneCode: async () => await input.text('Code ?'),
        onError: (err) => console.log(err),
    });
    console.log('You should now be connected.')
    console.log(client.session.save()) // Save this string to avoid logging in again
  async function eventPrint(event: NewMessageEvent) {
  console.log(event.message);
  };
  client.addEventHandler(eventPrint, new NewMessage({ chats: [chatId] }));
})()

When i run this code on express server in different por only work last telegram. That is, the last running one always works, the previous ones do not work. It feels like the new connection is killing the old one. How to solve the problem with multi-connection?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
painorcommented, Nov 14, 2021

you can’t run the same session multiple times. Telegram will only send updates to the latest running client.

if you want to receive updates you’ll need a new session for each client (even if it’s the same account).

1reaction
painorcommented, Nov 17, 2021

GramJS returns a SessionString that you can save in your DB if you want.

you can use the same session string in the same IP to send messages

You would need a different session string if you want to receive messages/updates. it’s a telegram limitation

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows: Fix 'Multiple connections to a server or shared ...
Multiple connections to a server or shared resource by the same user, using more than one user name are not allowed.
Read more >
Multiple connections to a server or shared resource by the ...
On our server we get this error: "Multiple connections to a server or shared resource by the same user, using more than one...
Read more >
Multiple Connections - Mothers of Multiples - Home - Facebook
Founded in 1961, Multiple Connections, Inc. has been educating and supporting mothers, and expecting mothers, of multiples (twins, triplets and other ...
Read more >
Multiple Connection to a server or shared resource
“Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed.
Read more >
Multiple connections to a server or shared resource by the ...
Multiple connections to a server or shard resource by the same user, using more than one user name, are not allowed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found