lambda与IBM tone_chat错误集成

问题描述 投票:0回答:1

我正在尝试将lambda函数与IBM Tone_chat情感分析器集成。我收到以下错误消息:

“ errorMessage”:“第一个参数必须是字符串或缓冲区类型之一。接收到的类型未定义”

这是我的活动:

{ "utterances": [
        {"text": "Hello, can you help me", "user": "customer"},
        {"text": "How are you ?", "user": "agent"},
        {"text": "Nothing is working", "user": "customer"},
        {"text": "Sorry to hear this", "user": "agent"}
    ]}

如果我将事件更改为:

{"text":"hello, this is test test, Happy sad"}

我收到以下错误:“ {\” code \“:400,\” sub_code \“:\” C00012 \“,\” error \“:\”在第1行第2列输入无效的JSON \“} “

这是我的代码:


        const AWS = require('aws-sdk');
        var http = require('https');
        exports.handler = (event, context, callback) => {
                var text = event.text;
                var options = {
                       method: process.env.method,
                       hostname: process.env.watson_hostname,
                       port: null,
                       path: process.env.path,
                       headers: {
                           'content-type': process.env.content_type,
                            authorization: process.env.authorization,
                           'cache-control': process.env.cache_control,
                           'X-Watson-Learning-Opt-Out': 'true'
                       }
                 };
                   var req = http.request(options, function (res) {
                   var chunks = [];
                   res.on("data", function (chunk) {
                   chunks.push(chunk);
                      });
                res.on("end", function () { 
                       var sentimentResponse = JSON.parse(Buffer.concat(chunks));
                   console.log("Sent respose");
                    callback(null, JSON.stringify(sentimentResponse));
               });
               })
    }

任何人都可以帮助我,我是新来的人,现在已经被困了一段时间!

谢谢

javascript node.js lambda ibm-watson tone-analyzer
1个回答
0
投票

令您感到惊讶的是,您没有同时将eventevent.texttext传递给http请求,因此两个输入都没有得到相同的错误。实际操作方式取决于您使用的是POST还是GET

[如果要提出建议,它将作为POST,您将在其中添加text作为请求body的一部分。

有关用法,请参见API文档-https://cloud.ibm.com/apidocs/tone-analyzer#analyze-general-tone

© www.soinside.com 2019 - 2024. All rights reserved.