alik0211 / mtproto-core

Telegram API JS (MTProto) client library for Node.js and browser
https://mtproto-core.js.org
GNU General Public License v3.0
630 stars 113 forks source link

invalid peer id #238

Closed danielehrhardt closed 2 years ago

danielehrhardt commented 2 years ago

Describe the bug I try to send a message to a User from a Group that i have never messaged before. If i try, i get invalid peer id. It works when i started a chat with the person in telegram before.

Code example

const fullChat = await this.api.call('messages.getFullChat', {
        chat_id: this.selectedChat,
      });

      console.log('fullChat', fullChat);

      if (fullChat) {
        await Promise.all(
          fullChat.users.map(async (_) => {
            console.log('sendMessage -> ', _, this.message);
            await this.api.call('messages.sendMessage', {
              clear_draft: true,
              peer: {
                _: 'inputPeerUser',
                user_id: _.id,
              },
              message: this.message,
              random_id:
                Math.ceil(Math.random() * 0xffffff) +
                Math.ceil(Math.random() * 0xffffff),
            });
            await this.sleep((Math.floor(Math.random() * 10) + 1) * 100);
            return _;
          })
        );
      }

Expected behavior Send Message to User without a existing Chat.

danielehrhardt commented 2 years ago

Added access_hash to the sendMessage