最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How encode in a right why emojis using node request module? - Stack Overflow

programmeradmin1浏览0评论

I'm using request module in order to send message to a Telegram bot, everything is fine, except the way I'm display emojis, which don't get printed well

Post request:

request.post({
            url: `${this.getApiURL()}/${apiName}`,
            formData: payload,
            headers: {
                'Content-Type': 'application/json',
                'Charset': 'utf-8',
            }
        }, (err, resp, body) => {});

The payload contains a text message with some emojis like:

const _emojis = {
            throwingAKiss: '\xF0\x9F\x98\x98',
            tearsOfJoy: '\xF0\x9F\x98\x82',
            smirkingFace: '\xF0\x9F\x98\x8F'
        }

but I'm displaying this symbol ð

I'm using request module in order to send message to a Telegram bot, everything is fine, except the way I'm display emojis, which don't get printed well

Post request:

request.post({
            url: `${this.getApiURL()}/${apiName}`,
            formData: payload,
            headers: {
                'Content-Type': 'application/json',
                'Charset': 'utf-8',
            }
        }, (err, resp, body) => {});

The payload contains a text message with some emojis like:

const _emojis = {
            throwingAKiss: '\xF0\x9F\x98\x98',
            tearsOfJoy: '\xF0\x9F\x98\x82',
            smirkingFace: '\xF0\x9F\x98\x8F'
        }

but I'm displaying this symbol ð

Share Improve this question edited May 16, 2018 at 8:28 Donovant asked May 15, 2018 at 23:58 DonovantDonovant 3,1618 gold badges45 silver badges75 bronze badges 5
  • It seems like only your first group is used, as ð is U+00F0 in UTF8. – k0pernikus Commented May 16, 2018 at 9:33
  • 1 Can you try using this syntax: "\u{1F604}"? ( apps.timwhitlock.info/emoji/tables/unicode ) – k0pernikus Commented May 16, 2018 at 9:36
  • Also you could try: github./omnidan/node-emoji – k0pernikus Commented May 16, 2018 at 9:41
  • It worked, thanks. It's weird because my code above used to work couple of days ago -_- – Donovant Commented May 16, 2018 at 9:47
  • I have added my ment as an answer after your feedback. – k0pernikus Commented May 16, 2018 at 12:07
Add a ment  | 

1 Answer 1

Reset to default 5

As a workaround you may have success with using a different unicode notation, i.e.:

const smiley = "\u{1F604}";

For a list of codes, there are emoji tables out there.

Additionally, it might ease a bit development overhead by using libraries such as node-emoji (which uses raw emojis under the hood through omnidan/node-emoji json file.

发布评论

评论列表(0)

  1. 暂无评论