首页 > 解决方案 > 对话框流中的 SOAP API

问题描述

我是 Node.Js 的新手,正在为一些原型机器人开发 Google DialogFlow。我正在调用 Workday SOAP Web 服务来获取信息。我能够在我的机器上本地在 Node.Js 中获得以下代码。任何人都可以使用内联编辑器帮助在 DialogFlow 中进行相同的工作吗

代码 :-

*"use strict";
var fs = require('fs'),
    assert = require('assert'),
    request = require('request'),
    http = require('http'),
    lastReqAddress;
var soap = require('strong-soap').soap;
var XMLHandler = soap.XMLHandler;
var util = require('util');
//wsdl of the Web Service this client is going to invoke. This can point to local wsdl as well.
var url = 'https://community.workday.com/sites/default/files/file-hosting/productionapi/Human_Resources/v34.1/Human_Resources.wsdl';
var requestArgs = {
    ElementName: 'Oxygen'
};
var clientOptions = {};
var Get_Workers_Args = {
    "Get_Workers_Request": {
        "$attributes": {
            "version": "v34.1"
        },
        "Request_References": {
            "Worker_Reference": {
                "ID": {
                    "$attributes": {
                        "type": "Employee_ID"
                    },
                    "$value": "**21001**"
                }
            }
        },
        "Response_Group": {
            "Include_Reference": "1",
            "Include_Personal_Information": "1",
            "Include_Additional_Jobs": "1",
            "Include_Employment_Information": "1",
            "Include_Compensation": "1",
            "Include_Organizations": "1"
        }
    }
};
soap.createClient(url, clientOptions, function(err, client) {
    //custom request header
    var customRequestHeader = {timeout: 5000};
    var options = {};
    var description = client.describe();
    var elements= description.Human_ResourcesService.Human_Resources.Get_Workers.input.body;
    client.setEndpoint("https://wd2-impl-services1.workday.com/ccx/service/**Tenant**/Human_Resources");
    client.addSoapHeader(`<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
   <wsse:UsernameToken wsu:Id="UsernameToken-6525124955572DD3B815893110892343">
   <wsse:Username>**Username**</wsse:Username>
   <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">**Password**</wsse:Password>

   </wsse:UsernameToken>
   </wsse:Security>`);
    var Get_Workers_Method = client['Human_ResourcesService']['Human_Resources']['Get_Workers'];
    Get_Workers_Method(Get_Workers_Args, function WorkdayWebServices(err, result, envelope, soapHeader) {
        console.log(' PUT  INSIDE GET Result: \n' + JSON.stringify(result));
        console.log(' PUT  INSIDE Request : \n' + JSON.stringify(Get_Workers_Args));
        console.log(' PUT  INSIDE GET Error: \n' + JSON.stringify(err));
    });
});*

任何人都可以帮助编写代码以在 Google DialogFlow 中调用。目的是将员工 ID 作为 Worker Reference 下的文本参数传递。

感谢您对此的任何帮助!

标签: node.jsdialogflow-esdialogflow-es-fulfillment

解决方案


内联编辑器的 Node.Js 文件如下:-

// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';

const axios = require('axios');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
    const agent = new WebhookClient({ request, response });
    console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
    console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function f1(agent) {
    var fs = require('fs'),
        assert = require('assert'),
        request = require('request'),
        http = require('http'),
        lastReqAddress;
    var soap = require('strong-soap').soap;
    var XMLHandler = soap.XMLHandler;
    var util = require('util');
//wsdl of the Web Service this client is going to invoke. This can point to local wsdl as well.
    var url = 'https://community.workday.com/sites/default/files/file-hosting/productionapi/Human_Resources/v34.1/Human_Resources.wsdl';
    var requestArgs = {
        ElementName: 'Oxygen'
    };
    var clientOptions = {};
    var Get_Workers_Args = {
        "Get_Workers_Request": {
            "$attributes": {
                "version": "v34.1"
            },
            "Request_References": {
                "Worker_Reference": {
                    "ID": {
                        "$attributes": {
                            "type": "Employee_ID"
                        },
                        "$value": "21001"
                    }
                }
            },
            "Response_Group": {
                "Include_Reference": "1",
                "Include_Personal_Information": "1",
                "Include_Additional_Jobs": "1",
                "Include_Employment_Information": "1",
                "Include_Compensation": "1",
                "Include_Organizations": "1"
            }
        }
    };


    let client1 = soap.createClient(url, clientOptions, function (err, client) {

        //custom request header
        var customRequestHeader = {timeout: 5000};
        var options = {};
        var description = client.describe();
        var elements = description.Human_ResourcesService.Human_Resources.Get_Workers.input.body;

        client.setEndpoint("https://wd2-impl-services1.workday.com/ccx/service/Human_Resources");

        client.addSoapHeader(`<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
   <wsse:UsernameToken wsu:Id="UsernameToken-6525124955572DD3B815893110892343">
   <wsse:Username>Username</wsse:Username>
   <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>

   </wsse:UsernameToken>
   </wsse:Security>`);

        var Get_Workers_Method = client['Human_ResourcesService']['Human_Resources']['Get_Workers'];
        Get_Workers_Method(Get_Workers_Args, function (err, result, envelope, soapHeader) {
            console.log(JSON.stringify(result));
            agent.add(JSON.stringify(result));
        }
        );
    });

}
exports.f1=f1();
    function welcome(agent) {
        agent.add(`Welcome to my agent!`);
    }

    function fallback(agent) {
        agent.add(`I didn't understand`);
        agent.add(`I'm sorry, can you try again?`);
    }
    // // Uncomment and edit to make your own intent handler
    // // uncomment `intentMap.set('your intent name here', yourFunctionHandler);`
    // // below to get this function to be run when a Dialogflow intent is matched
    // function yourFunctionHandler(agent) {
    //   agent.add(`This message is from Dialogflow's Cloud Functions for Firebase editor!`);
    //   agent.add(new Card({
    //       title: `Title: this is a card title`,
    //       imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png',
    //       text: `This is the body text of a card.  You can even use line\n  breaks and emoji! `,
    //       buttonText: 'This is a button',
    //       buttonUrl: 'https://assistant.google.com/'
    //     })
    //   );
    //   agent.add(new Suggestion(`Quick Reply`));
    //   agent.add(new Suggestion(`Suggestion`));
    //   agent.setContext({ name: 'weather', lifespan: 2, parameters: { city: 'Rome' }});
    // }

    // // Uncomment and edit to make your own Google Assistant intent handler
    // // uncomment `intentMap.set('your intent name here', googleAssistantHandler);`
    // // below to get this function to be run when a Dialogflow intent is matched
    // function googleAssistantHandler(agent) {
    //   let conv = agent.conv(); // Get Actions on Google library conv instance
    //   conv.ask('Hello from the Actions on Google client library!') // Use Actions on Google library
    //   agent.add(conv); // Add Actions on Google library responses to your agent's response
    // }
    // // See https://github.com/dialogflow/fulfillment-actions-library-nodejs
    // // for a complete Dialogflow fulfillment library Actions on Google client library v2 integration sample

    // Run the proper function handler based on the matched Dialogflow intent name
    let intentMap = new Map();
    intentMap.set('Default Welcome Intent', welcome);
    intentMap.set('Default Fallback Intent', fallback);
    intentMap.set('GetWorkerDetails',f1);
    // intentMap.set('your intent name here', yourFunctionHandler);
    // intentMap.set('your intent name here', googleAssistantHandler);
    agent.handleRequest(intentMap);
});

我在 webhook 状态中收到此错误。Webhook 调用失败。错误:DEADLINE_EXCEEDED。间歇性地,webhook 调用成功,但我检查了 firebase 控制台,函数调用没有响应。


推荐阅读