-1

I am a newbie in Node.Js and working on Google DialogFlow for some prototype bots. I am calling a Workday SOAP Web Service to fetch the information . I was able to get the below code working in Node.Js locally on my machine . Can anyone please help to get the same working in DialogFlow using Inline Editor

Code :-

*"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));
    });
});*

Can anyone please help in writing the code to invoke in Google DialogFlow. The intention is to pass the employee ID as text parameter under Worker Reference.

Appreciate any help regarding this!

  • If you are having problems running this in the inline editor, you should update the question to include any information about what is happening when you try. For example, it would be useful to see the error messages, or to know exactly what happens when you try. The more information you can provide, the better our chances are of being able to help you. See [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Prisoner May 14 '20 at 23:54

1 Answers1

0

The Node.Js file for Inline Editor is as below :-

// 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);
});

I am getting this error in the webhook status. Webhook call failed. Error: DEADLINE_EXCEEDED. Intermittently the webhook calls were successful but I checked the firebase console and there was no response from the function call.