如何使用节点请求模块正确编码表情符号?

How encode in a right why emojis using node request module?

我正在使用 request 模块向 Telegram 机器人发送消息,一切都很好,除了我显示表情符号的方式,它不会被打印出来嗯

Post 请求:

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

有效负载包含带有一些表情符号的短信,例如:

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

但我正在显示这个符号 ð

作为解决方法,您可能会成功使用不同的 unicode 表示法,即:

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

要获得代码列表,您有 emoji tables

此外,使用 node-emoji (which uses raw emojis under the hood through omnidan/node-emoji json file.

等库可能会减轻一些开发开销