Amazon Alexa语音服务API-如何获取当前的语言环境设置

时间:2019-03-20 08:44:08

标签: node.js amazon-web-services alexa alexa-voice-service

我目前正在寻找一种解决方案,以获取当前的AVS语言环境设置API

例如: 我们已经有设置当前语言环境的文档

https://developer.amazon.com/docs/alexa-voice-service/settings.html

下面是我的用于设置AVS语言环境的node.js方法

 setAVSLocale(locale) {

    //locale -> example: ja-JP
    let headers = {
        ':method': 'POST',
        ':scheme': 'https',
        ':path': '/v20160207/events',
        'authorization': `Bearer ${this.accessToken}`,
        'content-type': 'multipart/form-data; boundary=seeed-voice-engine'
    }
    const postReq = this.client.request(headers);
    var json_part = '--seeed-voice-engine\r\n';
    json_part += 'Content-Disposition: form-data; name="metadata"\r\n'
    json_part += 'Content-Type: application/json; charset=UTF-8\r\n\r\n'
    const postBody = {
        "content": [],
        "event": {
            "header": {
                "namespace": "Settings",
                "name": "SettingsUpdated",
                "messageId": "message_123"
            },
            "payload": {
                "settings": [
                    {
                        "key": "locale",
                        "value": locale
                    }
                ]
            }
        }
    };
    // const buffer = new Buffer(JSON.stringify(postBody));
    const stringBuffer = JSON.stringify(postBody);
    json_part += stringBuffer;
    postReq.setEncoding('utf8');
    postReq.write(json_part);
    postReq.end();
    postReq.on('response', (headers, flags) => {
        for (const name in headers) {
            console.log(`${name}: ${headers[name]}`);
        }

    });
    postReq.on('end', () => {
        console.log(`locale "${locale}" setting complete;`);

    });
    postReq.on('error', (err) => {
    });
}

有人可以提供示例或解决方法来获取我当前的AVS语言环境属性吗?我需要此功能,因为用户可能会刷新页面或其他内容,我需要找到一种可靠的方式来获取当前的语言环境设置,以便可以将数据刷新到UI。

0 个答案:

没有答案