Google Node.js SDK unicode上的操作

duf*_*ffn 7 unicode node.js google-assistant-sdk

如何在Google智能助理中简单地显示欧元符号?每次我尝试以不同的编码获得符号.我错过了什么简单的事情?

actions-on-google SDK 2.0.1版

const { dialogflow } = require('actions-on-google')

const app = dialogflow({ debug: true })

app.intent('euro-intent', (conv) => {
  console.log('€')
  conv.ask('€')
})

exports.myBot = app
Run Code Online (Sandbox Code Playgroud)

我的操作是在AWS API Gateway上调用webhook,该webhook使用Node.js v 8.10连接到Lambda函数.CloudWatch日志显示

{
    "payload": {
        "google": {
            "expectUserResponse": true,
            "richResponse": {
                "items": [
                    {
                        "simpleResponse": {
                            "textToSpeech": "€"
                        }
                    }
                ]
            },
            "userStorage": "{\"data\":{}}"
        }
    },
    "outputContexts": [
        {
            "name": "projects/newagent-9bde7/agent/sessions/1525808242247/contexts/_actions_on_google",
            "lifespanCount": 99,
            "parameters": {
                "data": "{}"
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

但是,我在模拟器中得到了以下内容.

欧元

bur*_*kan 3

在您的 webhook 中,对EURO SIGN使用 unicode 。EURO SIGN的 unicode是U+20AC

Node.js 实现中,使用“\u20ac”表示法。

在字符串值中,“\u”表示法表示该值是由四个十六进制数字表示的 unicode 字符。

这是带有 unicode 值的版本:

const { dialogflow } = require('actions-on-google')

const app = dialogflow({ debug: true })

app.intent('euro-intent', (conv) => {
  console.log('\u20ac')
  conv.ask('\u20ac')
})

exports.myBot = app
Run Code Online (Sandbox Code Playgroud)