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
625 stars 111 forks source link

sendReaction throws error "REACTION_INVALID" #280

Closed soberhacker closed 1 year ago

soberhacker commented 1 year ago

Hi man! Thanks for good library!

Describe the bug I tried this structure from layer 139: { peer: inputPeerUser, msg_id: msg_id, reaction: '👍'] } I tried also a lot of formats of "reaction" value. HUNDREDS :)

Than I updated layer in your code to 145 and upgraded types to 145 layer and tried new structure: { peer: inputPeerUser, msg_id: msgid, reaction: [{: 'reactionEmoji', emoticon: '\u{1f44d}'}], }

The error was the same. I think that problem is some where in converting unicode characters.

Code example

export async function sendReaction(msg_id: number) {  
  // Get the peer id of the user you want to send a reaction to
  const searchResult: any = await mtproto.call('contacts.resolveUsername', {
    username: 'ObsidianSyncBot',
  });

  const inputPeerUser = {
    _: 'inputPeerUser',
    user_id: searchResult.peer.user_id,
    access_hash: searchResult.users[0].access_hash,
  };
  const reactions = await mtproto.call('messages.getAvailableReactions', {
    hash: 0,    
  });

  const reaction = {
    peer: inputPeerUser,
    msg_id: msg_id,
    reaction: [{_: 'reactionEmoji', emoticon: "Thumbs Up"}]
  };
  // Send a like reaction to the last message of the user
  try {
    await mtproto.call('messages.sendReaction', reaction);
  } catch(e) {
    try {
      await mtproto.call('messages.sendReaction', {
        peer: inputPeerUser,
        msg_id: msg_id,
        reaction: [{_: 'reactionEmoji', emoticon: "Thumb Up"}],
      });
    } catch(e){
      try {
        await mtproto.call('messages.sendReaction', {
          peer: inputPeerUser,
          msg_id: msg_id,
          reaction: [{_: 'reactionEmoji', emoticon: '\u{1f44d}'}],
        });
      } catch(e) {
        null;
      }
    }
  }

Context:

Additional context Please, please, please help ))