{"id":22924,"date":"2019-11-26T07:12:38","date_gmt":"2019-11-26T07:12:38","guid":{"rendered":"https:\/\/developer.kore.ai\/v10-1\/?p=22924"},"modified":"2023-09-29T14:37:06","modified_gmt":"2023-09-29T13:37:06","slug":"koreutil-libraries","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v10-1\/docs\/bots\/advanced-topics\/koreutil-libraries\/","title":{"rendered":"koreUtil Libraries"},"content":{"rendered":"<section class=\"l-section wpb_row height_auto\"><div class=\"l-section-h i-cf\"><div class=\"g-cols vc_row type_boxes valign_top\"><div class=\"vc_col-sm-12 wpb_column vc_column_container\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<p><strong>koreUtil libraries<\/strong> provide pre-written JavaScript functions which makes common or complex tasks easy to implement. These libraries often target specific tasks such as setting up recurring rules for calendar, parsing and manipulation of dates, conversion of dates between timezone, tools to simplify programming with strings, numbers, arrays, functions and objects etc.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"How_to_Use\">How to Use<\/span><\/h2>\n<p>koreUtil libraries can be used anywhere in the assistant where there is a flexibility to write JavaScript code such as script node, message node, confirmation node, entity node, standard responses, answers to FAQs, small talk, event handlers etc.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h2><span class=\"ez-toc-section\" id=\"List_of_koreUtil_libraries\">List of koreUtil libraries<\/span><\/h2>\n<p>Below is the list of koreUtil libraries provided by the Platform:<\/p>\n<ul>\n<li><a href=\"#koreUtilrrule\">koreUtil.rrule<\/a><\/li>\n<li><a href=\"#koreUtilmoment\">koreUtil.moment<\/a><\/li>\n<li><a href=\"#koreUtilintl\">koreUtil.intl<\/a><\/li>\n<li><a href=\"#koreUtilmomenttz\">koreUtil.momenttz<\/a><\/li>\n<li><a href=\"#koreUtilxml2js\">koreUtil.xml2js<\/a><\/li>\n<li><a href=\"#koreUtilhash\">koreUtil.hash<\/a><\/li>\n<li><a href=\"#koreUtil\">koreUtil._<\/a><\/li>\n<li><a href=\"#koreUtilgetCurrentOptions\">koreUtil.getCurrentOptions<\/a><\/li>\n<li><a href=\"#koreUtilgetAmbiguousIntents\">koreUtil.getAmbiguousIntents<\/a><\/li>\n<li><a href=\"#koreUtilgetSessionId\">koreUtil.getSessionId<\/a><\/li>\n<li><a href=\"#koreUtilclose\">koreUtil.closeConversationSession<\/a><\/li>\n<li><a href=\"#koreautotranslate\">koreUtil.autoTranslate<\/a><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilrrule\">koreUtil.rrule<\/span><\/h3>\n<p>koreUtil.rrule is a Platform offered JS library for creating new recurrence rules, interpreting and reading them in human readable format.<\/p>\n<p><strong>Usage Example:<\/strong><br \/>\n<code>context.rule = new koreUtil.rrule({<br \/>\nfreq: koreUtil.rrule.WEEKLY,<br \/>\ninterval: 5,<br \/>\nbyweekday: [koreUtil.rrule.MO, koreUtil.rrule.FR],<br \/>\ndtstart: new Date(2012, 1, 1, 10, 30),<br \/>\nuntil: new Date(2012, 12, 31)<br \/>\n});<\/code><br \/>\n<code>context.between=context.rule.between(new Date(2012, 7, 1), new Date(2012, 8, 1));<\/code><br \/>\n<code>context.readableFormat=context.rule.toText();<\/code><\/p>\n<p><strong>Output:<\/strong><\/p>\n<ul>\n<li>For context.between<br \/>\n<code>[<br \/>\n\"2012-08-27T10:30:00.000Z\",<br \/>\n\"2012-08-31T10:30:00.000Z\"<br \/>\n]<\/code><\/li>\n<li>For context.readableFormat<br \/>\n<code>every 5 weeks on Monday, Friday until January 31, 2013<\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilmoment\">koreUtil.moment<\/span><\/h3>\n<p>koreUtil.moment is a Platform offered JS library for validating, manipulating, and formatting dates.<\/p>\n<p><strong>Usage Example:<\/strong><br \/>\n<code>context.german=koreUtil.moment().locale('de').format('LLLL');<\/code><\/p>\n<p><strong>Output:<\/strong><br \/>\nFor context.german:<br \/>\n<code>Montag, 18. November 2019 01:43<\/code><\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilintl\">koreUtil.intl<\/span><\/h3>\n<p>koreUtil.intl is a Platform offered JS library for language specific string comparison, number formatting, and date and time formatting.<\/p>\n<p><strong>Usage Example:<\/strong><br \/>\n<code>context.formattedNumberUK = koreUtil.intl.NumberFormat('en-GB').format(123456.789);<br \/>\nvar date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));<br \/>\ncontext.USdate=koreUtil.intl.DateTimeFormat('en-US').format(date);<\/code><\/p>\n<p><strong>Output:<\/strong><\/p>\n<ul>\n<li>For context.formattedNumberUK:<br \/>\n<code>123,456.789<\/code><\/li>\n<li>For context.USdate<br \/>\n<code>12\/20\/2012<\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilmomenttz\">koreUtil.momenttz<\/span><\/h3>\n<p>koreUtil.momenttz is a Platform offered JS library for formatting of dates in any timezone and convert dates between timezones.<\/p>\n<p><strong>Usage Example:<\/strong><br \/>\n<code>var jun = koreUtil.moment(\"2014-06-01T12:00:00Z\");<br \/>\ncontext.newyork= koreUtil.momenttz(jun,'America\/New_York').format('ha z');<br \/>\ncontext.tokyo = koreUtil.moment().tz('Asia\/Tokyo').format('ha z');<br \/>\ncontext.sydney = koreUtil.moment().tz('Australia\/Sydney').format('ha z');<\/code><\/p>\n<p><strong>Output:<\/strong><\/p>\n<ul>\n<li>For context.newyork:<br \/>\n<code>5am PDT<\/code><\/li>\n<li>For context.tokyo:<br \/>\n<code>7pm JST<\/code><\/li>\n<li>For context.sydney:<br \/>\n<code>9pm AEDT<\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilxml2js\">koreUtil.xml2js<\/span><\/h3>\n<p>koreUtil.xml2js is a Platform offered JS library for parsing xml to json and vice versa.<\/p>\n<p><strong>Usage Example:<\/strong><br \/>\n<code>var obj = {name: \"John\", Surname: \"Doe\", age: 23};<br \/>\nvar builder = new koreUtil.xml2js.Builder();<br \/>\ncontext.xml = builder.buildObject(obj);<\/code><\/p>\n<p><strong>Output:<\/strong><\/p>\n<ul>\n<li>For context.xml:<br \/>\n<code><!--?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?-->  John Doe 23 <\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilhash\">koreUtil.hash<\/span><\/h3>\n<p>koreUtil.hash is a Platform offered JS library that supports SHA on JavaScript.<\/p>\n<p><strong>Usage Example:<\/strong><br \/>\n<code>context.hashString= koreUtil.hash('sha256').update('42').digest('hex');<\/code><\/p>\n<p><strong>Output:<\/strong><\/p>\n<ul>\n<li>For context.hashString:<br \/>\n<code>73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049<\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtil\">koreUtil._<\/span><\/h3>\n<p>koreUtil._ is a Platform offered JS library which provides utility functions for common programming tasks.<\/p>\n<p><strong>Usage Example:<\/strong><br \/>\n<code>context.chunkArray = koreUtil._.chunk(['a', 'b', 'c', 'd'], 2);<br \/>\nvar users = [<br \/>\n{ 'user': 'barney', 'age': 36, 'active': true },<br \/>\n{ 'user': 'fred',   'age': 40, 'active': false }<br \/>\n];<br \/>\ncontext.filterActive =koreUtil._.pluck(koreUtil._.filter(users, { 'age': 36, 'active': true }), 'user');<\/code><\/p>\n<p><strong>Output:<\/strong><\/p>\n<ul>\n<li>For context.chunkArray:<br \/>\n<code>[[\"a\",\"b\"],[\"c\",\"d\"]]<\/code><\/li>\n<li>For context.filterActive:<br \/>\n<code>[<br \/>\n\"barney\"<br \/>\n]<\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilgetCurrentOptions\">koreUtil.getCurrentOptions<\/span><\/h3>\n<p>koreUtil.getCurrentOptions is a Platform offered JS library which provides utility functions to get the current template for language selection standard response options. This can be used to customize the standard response.<br \/>\nPost the release of v8.1, this function has been enhanced to return the authorization URL used in the standard response when end-user authorization is requested.<\/p>\n<p>Following is the return format for each of the situations:<\/p>\n<ul>\n<li>For the language selection standard response:\n<pre>{\"list_of_languages\": [\r\n   {\"title\": \"English\",\"value\": \"English\"},\r\n   {\"title\": \"Deutsche\",\"value\": \"Deutsche\"},\r\n   {\"title\": \"Espa\u00f1ol\",\"value\": \"Espa\u00f1ol\"}\r\n]}<\/pre>\n<\/li>\n<li>For the language ambiguity standard response:\n<pre>{\"current_language\": \"Espa\u00f1ol\",\r\n      \"list_of_new_languages\": [\r\n         {\"title\": \"English\",\"value\": \"English\"},\r\n         {\"title\": \"Deutsche\",\"value\": \"Deutsche\"},\r\n         {\"title\": \"Espa\u00f1ol\",\"value\": \"Espa\u00f1ol\"}\r\n  ]}<\/pre>\n<\/li>\n<li>For the language switch standard response:\n<pre>{\"new_language\": \"Espa\u00f1ol\",\"current_language\": \"English\"}<\/pre>\n<\/li>\n<li>For User authorization request standard response:\n<pre>{\r\n    \"authorizationURL\": \"https:\/\/\/r\/xxxxxxxxxxxxx\"\r\n}<\/pre>\n<\/li>\n<\/ul>\n<p>Following are the usage examples of how the above utility can be used to render the message in a button template, you can use any template as per your requirements.\u00a0 <a href=\"\/docs\/bots\/sdks\/message-templates\/\" target=\"_blank\" rel=\"noopener noreferrer\">See here for more on message templates<\/a>.<\/p>\n<p><strong>Usage Example 1:<\/strong> To get the standard response for &#8220;<em>Ask if the user would like to select any of the languages<\/em>&#8221;<\/p>\n<pre>var info = koreUtil.getCurrentOptions();\r\nvar message = {\r\n  \"type\": \"template\",\r\n  \"payload\": {\r\n    \"template_type\": \"button\",\r\n    \"text\": \"please select your laguage\",\r\n    \"subText\": \"Button Template Description\",\r\n    \"buttons\": []\r\n    }\r\n  };\r\nfor (i = 0; i &lt; info.list_of_languages.length; i++) {\r\n  var button = {\r\n    \"type\": \"postback\",\r\n    \"title\": info.list_of_languages[i].title,\r\n    \"payload\": info.list_of_languages[i].value\r\n    };\r\n\r\n  message.payload.buttons.push(button);\r\n }\r\nprint(JSON.stringify(message));\r\n<\/pre>\n<p><strong>Usage Example 2:<\/strong> To get the standard response for &#8220;<em>Ask if the user would like to switch to any of the new languages detected during a conversation<\/em>&#8221;<\/p>\n<pre>var info = koreUtil.getCurrentOptions();\r\nvar message = {\r\n    \"type\": \"template\",\r\n    \"payload\": {\r\n        \"template_type\": \"button\",\r\n        \"text\": \"language ambiguity response for the current language\" + info.current_language,\r\n        \"subText\": \"Button Template Description\",\r\n        \"buttons\": []\r\n    }\r\n};\r\nfor (i = 0; i &lt; info.list_of_new_languages.length; i++) {\r\n    var button = {\r\n        \"type\": \"postback\",\r\n        \"title\": info.list_of_new_languages[i].title,\r\n        \"payload\": info.list_of_new_languages[i].value\r\n    };\r\n\r\n    message.payload.buttons.push(button);\r\n}\r\nprint(JSON.stringify(message));\r\n<\/pre>\n<p><strong>Usage Example 3:<\/strong> To get the standard response for &#8220;<em>Ask if the user would like to switch to any of the new languages detected during a conversation<\/em>&#8221;<\/p>\n<pre>var info = koreUtil.getCurrentOptions();\r\nvar message = {\r\n    \"type\": \"template\",\r\n    \"payload\": {\r\n        \"template_type\": \"button\",\r\n        \"text\": \"would you like to switch to new language detected: current language \" + info.current_language + \"new language : \" + info.new_language,\r\n        \"subText\": \"Button Template Description\",\r\n        \"buttons\": []\r\n    }\r\n};\r\nvar options = [\"yes\", \"no\"]\r\nfor (i = 0; i &lt; options.length; i++) {\r\n    var button = {\r\n        \"type\": \"postback\",\r\n        \"title\": options[i],\r\n        \"payload\": options[i]\r\n    };\r\n    message.payload.buttons.push(button);\r\n}\r\nprint(JSON.stringify(message));\r\n<\/pre>\n<p><strong>Usage Example 4:<\/strong> To get the standard response for &#8220;<em>User needs to authorize or re-authorize<\/em>&#8221;<\/p>\n<pre>var info = koreUtil.getCurrentOptions();\r\n\r\nvar message = {\r\n    type: 'template',\r\n    payload: {\r\n        template_type: 'button',\r\n        text: 'Please authorize before we continue...',\r\n        buttons: [\r\n            {\r\n                type: 'url',\r\n                title: 'Click here to authorize',\r\n                url: info.authorizationURL\r\n            }\r\n        ]\r\n    }\r\n};\r\n\r\nprint(JSON.stringify(message));\r\n<\/pre>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilgetAmbiguousIntents\">koreUtil.getAmbiguousIntents<\/span><\/h3>\n<p>The <code>koreUtil.getAmbiguousIntents<\/code> util function is used to obtain the ambiguous intents list when the <a href=\"https:\/\/developer.kore.ai\/v10-1\/docs\/bots\/advanced-topics\/event-based-bot-actions\/#Ambiguous_Intents_Identified_Event\" target=\"_blank\" rel=\"noopener noreferrer\">Ambiguity Intents Identified<\/a> event gets triggered. Along with the list of ambiguous intents, the retrieved context object contains additional details such as ambiguity reasons &#8211; \u2018multiple definite intents&#8217;, \u2018multiple intents with similar scores\u2019, etc., and the engine name that detects the intent (ML, FM, or KG), the score given by the respective engines, and so on. The <a href=\"https:\/\/developer.kore.ai\/v10-1\/docs\/bots\/nlp\/nlp-detection\/\" target=\"_blank\" rel=\"noopener noreferrer\">Ranking and Resolver<\/a> score is displayed wherever available.<\/p>\n<p><strong>Usage Example<\/strong><br \/>\nYou can use the <code>koreUtil.getAmbiguousIntents()<\/code> function in the entity prompt or any other node to obtain the list of ambiguous intents.<\/p>\n<p><strong>Sample Response<\/strong><\/p>\n<p><code>{<br \/>\n\"intents\": [<br \/>\n{<br \/>\n\"intent\": \"Transfer Money\",<br \/>\n\"name\": \"Transfer Money\",<br \/>\n\"intentType\": \"dialog\",<br \/>\n\"mlScore\": 100,<br \/>\n\"rrScore\": 7980,<br \/>\n\"identifyingEngines\": {<br \/>\n\"ml\": true<br \/>\n}<br \/>\n},<br \/>\n{<br \/>\n\"intent\": \"Pay Bills\",<br \/>\n\"name\": \"Pay Bills\",<br \/>\n\"intentType\": \"dialog\",<br \/>\n\"rrScore\": 0,<br \/>\n\"identifyingEngines\": {<br \/>\n\"traits\": true<br \/>\n}<br \/>\n},<br \/>\n{<br \/>\n\"intent\": \"Status of Funds Transfer\",<br \/>\n\"name\": \"Status of Funds Transfer\",<br \/>\n\"intentType\": \"dialog\",<br \/>\n\"fmScore\": 5330,<br \/>\n\"rrScore\": 5330,<br \/>\n\"identifyingEngines\": {<br \/>\n\"fm\": true<br \/>\n}<br \/>\n},<br \/>\n{<br \/>\n\"PrimaryQuestion\": \"How to Send Money\",<br \/>\n\"MatchedQuestion\": \"How to Send Money\",<br \/>\n\"intentType\": \"FAQ\",<br \/>\n\"faqScore\": 100,<br \/>\n\"rrScore\": 7960,<br \/>\n\"faqDemystification\": {<br \/>\n\"path\": [<br \/>\n\"Money Transfer\"<br \/>\n]<br \/>\n},<br \/>\n\"identifyingEngines\": {<br \/>\n\"faq\": true<br \/>\n}<br \/>\n}<br \/>\n],<br \/>\n\"cause\": \"multipleChoices\",<br \/>\n\"userInput\": \"How do I make a payment or transfer\"<br \/>\n};<br \/>\n<\/code><\/p>\n<p>In this response, we obtain the details of multiple ambiguous intents from different engines.<\/p>\n<p>The type of intent is captured in the <code>intentType<\/code>object. For example, <code>Status of Funds Transfer<\/code> is a Dialog-type intent, and <code>How to Send Money<\/code> is a FAQ-type intent. The identifying engine for that respective intent and the confidence scores assigned by the engines for the intents are captured. For example, for the intent <code>Transfer Money<\/code>, the <code>mlScore<\/code>is 100. The <code>rrScore<\/code>is the <a href=\"https:\/\/developer.kore.ai\/v10-1\/docs\/bots\/nlp\/nlp-detection\/\" target=\"_blank\" rel=\"noopener noreferrer\">Ranking and Resolver<\/a> score for the winning intent. The object <code>faqDemystification<\/code>provides the bot path for the FAQ. The user input and the cause for the ambiguous intents are also captured.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilgetSessionId\">koreUtil.getSessionId<\/span><\/h3>\n<p>koreUtil.getSessionId is a Platform offered JS library for obtaining the current conversation session Id.<\/p>\n<p><strong>Usage Example:<\/strong><br \/>\n<code>var sessionId = koreUtil.getSessionId();<\/code><\/p>\n<p><strong>Output:<\/strong><\/p>\n<ul>\n<li>For sessionId:<br \/>\n<code>5x54321x11xx87654321xx12<\/code><\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3><span class=\"ez-toc-section\" id=\"koreUtilgetSunshineConversationsMetadata\"><span style=\"font-weight: 400;\">koreUtil.getSunshineConversationsMetadata<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The XO Platform captures and stores the metadata sent as part of the Pass control action that routes the conversation to the bot via Switchboard integration API in Zendesk. Developers can use the <code>koreUtil.getSunshineConversationsMetadata()<\/code> function to access the stored metadata.<\/span> <span style=\"font-weight: 400;\">For more information, read the <\/span><a href=\"https:\/\/developer.kore.ai\/v10-1\/docs\/bots\/channel-enablement\/adding-the-sunshine-conversations-channel\/#Switchboard_Integration_for_Agent_Handoff\"><span style=\"font-weight: 400;\">Switchboard Integration<\/span><\/a><span style=\"font-weight: 400;\"> section<\/span>.<\/p>\n<p><span style=\"font-weight: 400;\">The <\/span><b>koreUtil.getSunshineConversationsMetadata<\/b><span style=\"font-weight: 400;\"> function can be used by a bot developer to access the metadata captured in any node.<\/span><\/p>\n<p><strong>Usage Example:<\/strong><br \/>\n<code><span style=\"font-weight: 400;\">koreUtil.getSunshineConversationsMetadata();<\/span><\/code><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><code>{<br \/>\n\"dataCapture.systemField.tags\" : \"TransferToBot\",<br \/>\n\"dataCapture.systemField.priority\" : \"high\"<br \/>\n}<br \/>\n<\/code><\/p>\n<p><b>Note<\/b><span style=\"font-weight: 400;\">: The <\/span><b>koreUtil.getSunshineConversationsMetadata<\/b><span style=\"font-weight: 400;\"> is supported in the Platform v10.1.9 and above versions.<\/span><\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3 id=\"koreUtilclear\"><span class=\"ez-toc-section\" id=\"koreUtilClearAuthProfiles\">koreUtil.ClearAuthProfiles<\/span><\/h3>\n<p>The <code>koreUtil.ClearAuthProfiles<\/code> is a Platform function to clear tokens associated with an authorization profile of an active conversation by passing a particular profile name in the custom script. This function can be invoked from any component that supports JavaScript.<\/p>\n<p><strong>Usage Example:<\/strong><\/p>\n<p>Example : To clear one or more authorization profile:<\/p>\n<p><code>koreUtil.ClearAuthProfiles([Auth_Profle_Name]);<\/code><\/p>\n<p>Example: <code>koreUtil.ClearAuthProfiles([\u201cAuth_openai\u201d, \u201cAuth_hubspot\u201d]);<\/code><\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3 id=\"koreUtilclearAll\"><span class=\"ez-toc-section\" id=\"koreUtilClearAllAuthProfiles\">koreUtil.ClearAllAuthProfiles<\/span><\/h3>\n<p>The <code>koreUtil.ClearAllAuthProfiles<\/code> is a Platform function to clear tokens associated with all auth profiles associated with any active conversation. This function can be invoked from any component that supports JavaScript.<\/p>\n<p><strong>Usage Example:<\/strong><\/p>\n<p>Example : To clear all authorization profiles:<\/p>\n<p><code>koreUtil.ClearAllAuthProfiles ( );<\/code><\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3 id=\"koreUtilclose\"><span class=\"ez-toc-section\" id=\"koreUtilcloseConversationSession\">koreUtil.closeConversationSession<\/span><\/h3>\n<p>koreUtil.closeConversationSession is a Platform function for force closing any active conversation. This function can be invoked from any component that supports JavaScript. When you invoke this function, the Platform will discard any ongoing task and the active conversation session\u00a0 will be closed. The Platform also presents the session timeout message on the supported channels.<\/p>\n<p><strong>Usage Example:<\/strong><\/p>\n<p><code>koreUtil.closeConversationSession();<\/code><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p>No response is returned and session ends.<\/p>\n<p><strong>Note<\/strong>: The koreUtil.closeConversationSession is supported in the Platform v8.1 and above versions.<\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h3 id=\"koreautotranslate\"><span class=\"ez-toc-section\" id=\"koreUtilautoTranslate\">koreUtil.autoTranslate<\/span><\/h3>\n<p>koreUtil.autotranslate is a Platform function that lets you automatically translate the virtual assistant response from a language in which the assistant is configured to the language in which the user is interacting or a language of your choice. This function uses a translation engine to translate the bot responses into user input language. For more information on how to configure a translation engine, <a href=\"https:\/\/developer.kore.ai\/v10-1\/docs\/bots\/advanced-topics\/multi-lingual\/managing-translation-services\/\" target=\"_blank\" rel=\"noopener noreferrer\">refer here<\/a>.<\/p>\n<p><strong data-renderer-mark=\"true\">Note: <\/strong>To use the <code>koreUtil.autoTranlsate <\/code>function for language translation, you must have the Access Key provided by your translation service provider, such as Google Translator, Microsoft Translator, etc.<\/p>\n<p>Please refer below for the translation behavior:<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">Response Types<\/th>\n<th style=\"text-align: center;\">Components<\/th>\n<th style=\"text-align: center;\">Translation Behavior<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Plain Text Responses<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Refers to plain text responses defined anywhere in the virtual assistant. For example, prompts, responses etc.,<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Default: Auto-translated<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can choose to translate only a specific part of the response by using the koreUtil.autoTranslate function only for that part. <\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Advanced \/ JavaScript based Responses<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Refers to responses defined using JavaScript. For example, prompts, responses etc.,<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Default: No auto-translation<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can use the AutoTranslation function inside the JavaScript to define the parts of the responses that need translation.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Auto-formatted Responses<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Refers to the responses that are auto-formatted by the Platform as per the channel specifications. For example, confirmations, list of values, ambiguities etc.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Default: Auto-translated<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Usage Example:<\/strong><\/p>\n<p><code>koreUtil.autoTranslate();<\/code><\/p>\n<p>Here are a few use case examples for your reference:<\/p>\n<p><strong>Use Case-1:<\/strong>To translate part of a sentence in the user\u2019s language:<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p><code>{{koreUtil.autoTranslate('Welcome! I am a virtual assistant powered by ')}} General Insurance<\/code><\/p>\n<p><strong>Output in Serbian<\/strong><\/p>\n<p><code>\u0414\u043e\u0431\u0440\u0435\u0434\u043e\u0458\u0434\u043e\u0432\u0442\u0435! \u0408\u0430\u0441 \u0441\u0443\u043c \u0432\u0438\u0440\u0442\u0443\u0435\u043b\u0435\u043d \u0430\u0441\u0438\u0441\u0442\u0435\u043d\u0442 \u043d\u0430\u043f\u043e\u0458\u0443\u0432\u0430\u043d \u043e\u0434 General Insurance<\/code><\/p>\n<p><strong>Use Case-2:<\/strong>To translate the content of a customized JavaScript template, then use koreUtil.autoTranslate as follows:<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p><code>var accountBalance = getbalance();  var message = koreUtil.autoTranslate(\"Your account balance is \"); var message = message.concat(env.currency, \u2018 \u2019, accountBalance); print(message);<\/code><\/p>\n<p><strong>Output in Serbian<\/strong><\/p>\n<p><code>\u0411\u0430\u043b\u0430\u043d\u0441 \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u0447\u0435\u0442\u0430 USD 5,278.00<\/code><\/p>\n<p><strong>Use Case-3:<\/strong> To translate the bot responses in a particular language by passing the language code. An example where the assistant will respond only in German even though the user is interacting in any language:<\/p>\n<p><strong>Example<\/strong><\/p>\n<p><code>var message = koreUtil.autoTranslate(\"This is a sample message\", \"de\");print(message);<\/code><\/p>\n<p><strong>Output in German<\/strong><\/p>\n<p><code>Dies ist eine Beispielnachricht<\/code><\/p>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"w-separator size_small with_line width_default thick_1 style_solid color_border align_center\"><div class=\"w-separator-h\"><\/div><\/div>\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<h4>Related Link<\/h4>\n<ul>\n<li><a href=\"https:\/\/developer.kore.ai\/v10-1\/docs\/bots\/bot-builder-tool\/dialog-task\/working-with-the-script-node\/\"><strong>Script Node<\/strong><\/a> (Write JavaScript code in a dialog task)<\/li>\n<\/ul>\n\r\n\t\t<\/div>\r\n\t<\/div>\r\n<div class=\"ult-spacer spacer-6ae8721b04d1c\" data-id=\"6ae8721b04d1c\" data-height=\"10\" data-height-mobile=\"10\" data-height-tab=\"10\" data-height-tab-portrait=\"\" data-height-mobile-landscape=\"\" style=\"clear:both;display:block;\"><\/div><\/div><\/div><\/div><\/div><\/div><\/section><section class=\"l-section wpb_row height_auto\"><div class=\"l-section-h i-cf\"><div class=\"g-cols vc_row type_default valign_top\"><div class=\"vc_col-sm-12 wpb_column vc_column_container\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\"><\/div><\/div><\/div><\/div><\/div><\/section>\n","protected":false},"excerpt":{"rendered":"koreUtil libraries provide pre-written JavaScript functions which makes common or complex tasks easy to implement. These libraries often target specific tasks such as setting up recurring rules for calendar, parsing and manipulation of dates, conversion of dates between timezone, tools to simplify programming with strings, numbers, arrays, functions and objects etc. How to Use koreUtil...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-22924","post","type-post","status-publish","format-standard","hentry","category-advanced-topics"],"_links":{"self":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts\/22924","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/comments?post=22924"}],"version-history":[{"count":41,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts\/22924\/revisions"}],"predecessor-version":[{"id":59690,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/posts\/22924\/revisions\/59690"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/media?parent=22924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/categories?post=22924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v10-1\/wp-json\/wp\/v2\/tags?post=22924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}