How do I use Google directives?

What are Directives?

Directives are templates, which developers should use, to render information on smart display devices. Google directives expose platform-specific Google action's functionality, letting developers customize default bot responses, such as displaying a carousel, image, and so on in smart display devices.

What are Directives used for?

Directives enrich the user experience with suggestions, options, images, and so on.

For example:

  • Use a rich response to display visual elements that enhance user interactions with your Action. These visual elements can provide hints on how to continue a conversation.

  • Use a visual selection response for the user to choose among several options to continue with your Action.

How to use Google Directives in Orbita

Orbita provides the directives in JSON format. The following steps use a directive in your project.

  1. In the Experience Designer, select the flow where you want to add the directive.

  2. Copy the JSON code and Import the code to the current flow. A function node appears on the screen.

  3. Connect the function node after the Say node.

  4. Deploy the flow.

Sample flow:

The JSON code for a carousel directive is:

[{"id":"78e32b4f.74b7c4", "type":"function", "z":"2aa61283.50abee", "name":"append - carousel", "func":"var _ = global.get('lodash'); \nvar obj = {\n  \"carouselBrowse\": {\n    \"items\": [\n      {\n        \"title\": \"Title of item 1\", \n        \"description\": \"Description of item 1\", \n        \"footer\": \"Item 1 footer\", \n        \"image\": {\n          \"url\": \"https://www.gstatic.com/mobilesdk/170329_assistant/assistant_color_96dp.png\", \n          \"accessibilityText\": \"Google Assistant Bubbles\"\n        }, \n        \"openUrlAction\": {\n          \"url\": \"https://github.com\"\n        }\n      }, \n      {\n        \"title\": \"Title of item 2\", \n        \"description\": \"Description of item 2\", \n        \"footer\": \"Item 2 footer\", \n        \"image\": {\n          \"url\": \"https://www.gstatic.com/mobilesdk/170329_assistant/assistant_color_96dp.png\", \n          \"accessibilityText\": \"Google Assistant Bubbles\"\n         }, \n        \"openUrlAction\": {\n          \"url\": \"https://google.com\"\n        } \n      } \n    ] \n  } \n} \nvar existGSay = _.get(msg,'alexaResponse.response.payload.google.richResponse.items', undefined)\n\nif(existGSay) {\n    existGSay.push(obj);\n} \nreturn msg;","outputs":1,"noerr":0,"x":610.5,"y":130,"wires":[["21ae331f.8935ac"]]}, {"id":"slots","type":"slots","z":"","slots":[ {"_id":"5bfd38963b7ba45953092542", "name":"test", "type":"slot", "values":["a","b","c"], "projectId":[], "isDeleted":false, "projectArrayLength":0}, {"_id":"5c0131e0da270ee27ce040a4", "name":"abc", "type":"slot", "values":["good"], "projectId":[], "isDeleted":false, "projectArrayLength":0}, {"_id":"5c0a49310e02b1fab315ae9c", "name":"List_Message_Values", "type":"slot", "values":["Insert Value"], "projectId":["5c0a3355ab631299696b62fa"], "isDeleted":false, "projectArrayLength":1}, {"_id":"5c0a49320e02b1fab315aed5", "name":"TaskType", "type":"slot", "values":["Insert Value"], "projectId":["5c0a3355ab631299696b62fa"], "isDeleted":false, "projectArrayLength":1}, {"_id":"5c0a49320e02b1fab315aef5", "name":"NUMBER", "type":"slot", "values":["Insert Value"], "projectId":["5c0a3355ab631299696b62fa"], "isDeleted":false, "projectArrayLength":1}, {"_id":"5c0a49320e02b1fab315af45", "name":"LIST_OF_MEASUREMENT_VALUES", "type":"slot", "values":["Insert Value"], "projectId":["5c0a3355ab631299696b62fa"], "isDeleted":false,"projectArrayLength":1}, {"_id":"5c0a49330e02b1fab315b0e9", "name":"DATE", "type":"slot", "values":["Insert Value"], "projectId":["5c0a3355ab631299696b62fa"], "isDeleted":false, "projectArrayLength":1}, {"_id":"5c0a49330e02b1fab315b0f2", "name":"SURVEY_NAMES", "type":"slot", "values":["Insert Value"], "projectId":["5c0a3355ab631299696b62fa"], "isDeleted":false,"projectArrayLength":1}, {"_id":"5c0a49330e02b1fab315b0fa", "name":"SURVEY_REQUESTS", "type":"slot", "values":["Insert Value"], "projectId":["5c0a3355ab631299696b62fa"], "isDeleted":false, "projectArrayLength":1}, {"_id":"5c0a49330e02b1fab315b0fe", "name":"MESSAGE_VALUES", "type":"slot", "values":["Insert Value"], "projectId":["5c0a3355ab631299696b62fa"], "isDeleted":false, "projectArrayLength":1}, {"_id":"5c0a49350e02b1fab315b3d3", "name":"General_Response_List", "type":"slot", "values":["Insert Value"], "projectId":["5c0a3355ab631299696b62fa"], "isDeleted":false,"projectArrayLength":1} ] } ]

Related Articles