Actions on Google Node.js SDK unicode
Asked Answered
P

1

7

How do I very simply show a Euro symbol in Google Assistant? Every time that I attempt to I get the symbol in a different encoding. What simple thing am I missing?

actions-on-google SDK version 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

My action is calling a webhook on AWS API Gateway that is connected to a Lambda function using Node.js v 8.10. The CloudWatch logs show

{
    "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": "{}"
            }
        }
    ]
}

However, I get the below in the simulator.

euro

Proverbial answered 8/5, 2018 at 19:50 Comment(4)
Can you try returning "\\u20ac" instead of and see if it helpsBronchi
@TarunLalwani This returns the characters "\u20ac" and the assistant reads it as "you twenty ack".Proverbial
I think this may be a encoding issue then. I would look at the headers and make sure Content-type: application/json; charset=utf-8 is being returned, if not then return the content-type header with the charset in your lambda. Another thing i would try is setting the content handling to convert to text if needed. I have not used it but not sure it would changing anything for you, i.sstatic.net/AMKTB.pngBronchi
Did you get chance to try these things?Bronchi
C
3

In your webhook, use unicode for EURO SIGN. The unicode for EURO SIGN is U+20AC

In your Node.js implementation, use '\u20ac' notation.

In a string value, '\u' notation indicates that value is a unicode character denoted by four hex digits.

Here is the version with unicode value:

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
Chorography answered 15/5, 2018 at 13:1 Comment(4)
This returns exactly the same "â¬" characters.Proverbial
I've tried this on my webhook and running. It's deployed to firebase. I checked both in my phone and on simulator. What are you seeing when you run console.log('\u20ac') at online editor: repl.it/repls/MelodicWillingFunctionChorography
I see the Euro symbol in the online editor. Perhaps it is something with the way AWS is returning the payload? I am not using Firebase, but using AWS API Gateway and a Lambda function.Proverbial
Maybe you can also try to use escape with ES6 way: \u{20ac} @ProverbialChorography

© 2022 - 2024 — McMap. All rights reserved.