验证错误:TypeError:URL不是构造函数

时间:2019-03-11 07:10:19

标签: node.js amazon-web-services dialogflow

在AWS上部署时遇到此错误:

  

“验证错误:TypeError:URL不是构造函数”“ DF错误:14   无法使用:从插件获取元数据失败,并显示以下错误:URL为   不是构造函数”

虽然在本地运行良好。 调用Dialogflow后没有任何响应。

1 个答案:

答案 0 :(得分:0)

我的代码是:

// Instantiate a DialogFlow client.
        var dialogflow = require('dialogflow');
        var sessionClient = new dialogflow.SessionsClient({
                credentials: {
                    private_key: config.dialogflow.privateKey,
                    client_email: config.dialogflow.clientEmail
                }
            }
        );

        // Define session path
        var sessionPath = sessionClient.sessionPath(config.dialogflow.projectId, req.sessionID);

        // The text query request.
        var request = {
            session: sessionPath,
            queryInput: {},
        };
        if (chatBotEvent.text.text){
            request.queryInput.text = {
                text:chatBotEvent.text.text,
                languageCode: chatBotEvent.text.languageCode
            };
        }
        if (chatBotEvent.event.name){
            var dialogflowService = new DialogflowService();
            request.queryInput.event = {
                name:chatBotEvent.event.name,
                parameters:dialogflowService.jsonToStructProto(chatBotEvent.event.parameters),//event.parameters,
                languageCode: chatBotEvent.event.languageCode,
            };
        }
        // Send request and log result
        return sessionClient
            .detectIntent(request)
            .then(function(responses){
                var incidentData = $this.analyseResponse(responses[0].queryResult);
                if (incidentData){
                    responses[0].queryResult.incident = incidentData;
                }
                return responses[0].queryResult;
            })
            .catch(function(err){
                console.error('ERROR:', err);
            });