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

Parsing html or markup in message.sendMessage not working #216

Closed meth0xy closed 2 years ago

meth0xy commented 2 years ago

Describe the bug I am trying to send a message with styled format, unfortuntley nothing seems to work, the messages are all send as a string only

Code example

api.call("messages.sendMessage", {
    clear_draft: true,
    parse_mode: "html",
    peer: {
      _: "inputPeerSelf",
    },
    message: "<b>Test</b>",
    entities: [
      {
        _: "messageEntityBold",
        offset: 6,
        length: 13,
      },
    ],

    random_id:
      Math.ceil(Math.random() * 0xffffff) + Math.ceil(Math.random() * 0xffffff),
  });

Expected behavior A Message with a bold text.

Context:

Additional context Same happens when i use parse_mode: "markup".

meth0xy commented 2 years ago

Okay i found out that i have to use the MessageEnitys and specify each word with an entity.

VityaSchel commented 2 years ago

Okay i found out that i have to use the MessageEnitys and specify each word with an entity.

Could you share an example of code?

meth0xy commented 2 years ago

Okay i found out that i have to use the MessageEnitys and specify each word with an entity.

Could you share an example of code?

So the code example on the docs is what I used for the message.

`api.call('messages.sendMessage', { clear_draft: true,

peer: { _: 'inputPeerSelf', }, message: 'Hello @mtprotocore', entities: [ { : 'messageEntityBold', offset: 6, length: 13, }, ],

random_id: Math.ceil(Math.random() 0xffffff) + Math.ceil(Math.random() 0xffffff), });`

So the entities Array :

entities: [ { _: 'messageEntityBold', offset: 6, length: 13, }, ],

is for the formatting you can add a second object in that array for example messageEntityCode and set the offset to the specific letter in your message and the length of the word. Here are all possible message entities https://core.telegram.org/type/MessageEntity