1.0.7 • Published 5 years ago

dialogflow_json_function v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

This is just for calling responses of dialog flow through JSON and node All the this written below for how to use it:-

context_url = "projects/practice-prove/agent/sessions/ticketak/contexts/"; exports.simple_res = function (user_strg, text_voice, text_to_speech, sgsn_1, sgsn_2, sgsn_3, sgsn_4, sgsn_5, context_value) { if (!context_value){ if(sgsn_2 == '' && sgsn_3 == '' && sgsn_4 == '' && sgsn_5 == ''){ sugges = { "title": sgsn_1 } } else if(sgsn_3 =='' && sgsn_4=='' && sgsn_5==''){ sugges = { "title": sgsn_1 }, { "title": sgsn_2 } } else if(sgsn_4=='' && sgsn_5==''){ sugges = { "title": sgsn_1 }, { "title": sgsn_2 }, { "title": sgsn_3 } } else if(sgsn_5==''){ sugges = { "title": sgsn_1 }, { "title": sgsn_2 }, { "title": sgsn_3 }, { "title": sgsn_4 } } else{ sugges = { "title": sgsn_1 }, { "title": sgsn_2 }, { "title": sgsn_3 }, { "title": sgsn_4 }, { "title": sgsn_5 } }

let response = {
"payload": {
    "google": {
        "userStorage": user_strg,
        "expectUserResponse": true,
        "richResponse": {
            "items": [
                {  
                    "simpleResponse": {
                      "ssml": text_voice,
                      "displayText": text_to_speech    
                    }
                }                           
            ],
             "suggestions": sugges
        }
    }
}
}
return response;

} else{ if(sgsn_2 == '' && sgsn_3 == '' && sgsn_4 == '' && sgsn_5 == ''){ sugges = { "title": sgsn_1 } } else if(sgsn_3 =='' && sgsn_4=='' && sgsn_5==''){ sugges = { "title": sgsn_1 }, { "title": sgsn_2 } } else if(sgsn_4=='' && sgsn_5==''){ sugges = { "title": sgsn_1 }, { "title": sgsn_2 }, { "title": sgsn_3 } } else if(sgsn_5==''){ sugges = { "title": sgsn_1 }, { "title": sgsn_2 }, { "title": sgsn_3 }, { "title": sgsn_4 } } // if context exist else{ sugges = { "title": sgsn_1 }, { "title": sgsn_2 }, { "title": sgsn_3 }, { "title": sgsn_4 }, { "title": sgsn_5 } } let response = { "payload": { "google": { "userStorage": user_strg, "expectUserResponse": true, "richResponse": { "items": {
"simpleResponse": { "ssml": text_voice, "displayText": text_to_speech
} }
, "suggestions": sugges } } }, "outputContexts": { "name": context_url+context_value, "lifespanCount": 1 } } return response; } }

exports.simple_res_without_sugges = function(user_strg, check_exit, text_voice, text_to_speech,context_value){ let response = { "payload": { "google": { "userStorage": user_strg, "expectUserResponse": check_exit, "richResponse": { "items": {
"simpleResponse": { "ssml": text_voice, "displayText": text_to_speech
} }
, } } }, "outputContexts": { "name": context_url+context_value, "lifespanCount": 1 } } return response; }

exports.basic_card = function(user_strg, text_voice, text_to_speech, formatted_text, title_text, image_ulr, sgsn_1, sgsn_2, sgsn_3){ let response ={ "payload": { "google": { "userStorage": user_strg, "expectUserResponse": true, "richResponse": { "items": [ { "simpleResponse": { "ssml": text_voice, "displayText": text_to_speech
} }, { "basicCard": { "formattedText": formatted_text, "title": title_text, "image": { "url": image_ulr, "accessibilityText": "Google Logo" }, // "buttons": // { // "title": "Click Here", // "openUrlAction": { // "url": "https://www.reliancegeneral.co.in/Insurance/Self-Help/Intimate-Claim-Health.aspx" // } // } // , "imageDisplayOptions": "WHITE" } } ], "suggestions": [

        {
            "title": sgsn_1
        },
        {
            "title": sgsn_2
        },
        {
            "title": sgsn_3
        }
    ]
    }
  }
}

} return response;

}

exports.carousel_card = function(user_strg, text_voice, text_to_speech, item, context_value){ let response = { "payload": { "google": { "userStorage": user_strg, "expectUserResponse": true, "richResponse": { "items": { "simpleResponse": { "ssml": text_voice, "displayText": text_to_speech
} }
}, "systemIntent": { "intent": "actions.intent.OPTION", "data": { "@type": "type.googleapis.com/google.actions.v2.OptionValueSpec", "carouselSelect": { "items": item } } } } }, "outputContexts": { "name": context_url+context_value, "lifespanCount": 1 } } return response; }

exports.permission = function(user_strg,text_to_speech,name,email,location,context_value){ if(name =='' && email ==''){ permission_arr = location } else if(location == ''){ permission_arr = name, email } else{ permission_arr = name, email, location }

let response = { "payload": { "google": { "userStorage": user_strg, "expectUserResponse": true, "systemIntent": { "intent": "actions.intent.PERMISSION", "data": { "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec", "optContext": text_to_speech, "permissions": permission_arr } } } }, "outputContexts": { "name": context_url+context_value, "lifespanCount": 1 } } return response; }

exports.permission_for_notification = function(user_strg, text_to_speech, intent_name, context_value){ let response = { "payload": { "google": { "userStorage": user_strg, "expectUserResponse": true, "systemIntent": { "intent": "actions.intent.PERMISSION", "data": { "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec", "optContext": text_to_speech, "permissions": "UPDATE" , "updatePermissionValueSpec": { "intent": intent_name } } } } }, "outputContexts": { "name": context_url+context_value, "lifespanCount": 1 } } resolve(response); }

// res.send(all_templetes.permission( // '1st argument is for user storage', // '2nd argument is for text to speech', // '3rd argument is for intent name', // '4th_argument_is_for_context' // ))

// here is how to defined dynamic carousel's item // let item = []; // if (result.length > 0) { // Object.keys(result).forEach(function(key) { // var row = resultkey; // name = row.shop_name; // image = row.image; // id = row.id; // shop_des = row.shop_desc; // // carousel bna re h // let itemObj = {}; // let optionInfoObj = {}; // let imageObj = {}; // optionInfoObj.key = name; // itemObj.optionInfo = optionInfoObj; // itemObj.title = name; // imageObj.url = image; // itemObj.description = shop_des; // imageObj.accessibilityText = name; // itemObj.image = imageObj; // item.push(itemObj); // }) // }

// here is how to defined static carousel's item // let item = // { // "optionInfo": { // "key": "1st key" // }, // "description": "1st description text", // "image": { // "url": "1st image url", // "accessibilityText": "1st accesbility text" // }, // "title": "1st title text" // }, // { // "optionInfo": { // "key": "2nd key" // }, // "description": "2nd description text", // "image": { // "url": "2nd image url", // "accessibilityText": "2nd accesbility text" // }, // "title": "2nd title text" // }, // // if you want to show more cards in this caousel then you can easily show. //

// this is how to call functions in your if else conditions //res.send(all_templetes.{here your response type}({here your arguments}))

// permission pattern // NAME, EMAIL, DEVICE_PRECISE_LOCATION