📜 ⬆️ ⬇️

Emoticons for API Vkontakte

Earlier, I wrote about Informer Vkontakte - a browser extension for quick reading and reply to a message. In the process of creating, I ran into a problem - smiles in messages, namely: how to display them?
The fact is that when a text message is received by the methods of the Vkontakte API, smiles are inserted in it characters:

response: { count: 1, items: [{ id: 370892, body: 'Hello World 😊', user_id: 45421694, from_id: 45421694, date: 1437721570, read_state: 1, out: 0, emoji: 1 }] } 

The question arose: how to replace all the specials. characters on relevant images?

The solution was found in the very Vkontakte - Script which itself VK parsit smiles.
')
However, as you can see, there are a lot of things in it: there are events for downloading smiles, opening a window of stickers, and buying a new sticker, etc. Therefore, I provide a link to the modified Emoji.js code

Using


Using this script is quite simple.

 Emoji.emojiToHTML( 'Hello World 😊' ); // 'Hello World <img class="emoji" alt="😊" src="https://vk.com/images/emoji/D83DDE0A.png">' 

As you can see, by default, the script inserts images from the Vkontakte server, which means that you do not need to add all the images to your project. However, you can change the path to the pictures:

 Emoji.pathToEmojisImages = '/path/to/img/'; //      Emoji.emojiToHTML( 'Hello World 😊' ); // 'Hello World <img class="emoji" alt="😊" src="/path/to/img/D83DDE0A.png">' 

Thus, you can easily use smiles in messages received through the Vkontakte API.

Source: https://habr.com/ru/post/263455/


All Articles