{"id":18057,"date":"2018-07-23T10:01:47","date_gmt":"2018-07-23T10:01:47","guid":{"rendered":"https:\/\/developer.kore.ai\/v9-0\/?post_type=docs&#038;p=15099"},"modified":"2021-08-14T08:53:43","modified_gmt":"2021-08-14T07:53:43","slug":"reusing-bot-functions-custom-script-file","status":"publish","type":"post","link":"https:\/\/developer.kore.ai\/v9-0\/docs\/bots\/bot-settings\/bot-functions\/reusing-bot-functions-custom-script-file\/","title":{"rendered":"Bot Functions"},"content":{"rendered":"<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\">\r\n\t<div class=\"wpb_text_column \">\r\n\t\t<div class=\"wpb_wrapper\">\r\n\t\t\t<p>Custom Script file enables you to collate and manage reusable utility JavaScript functions that can be used by different tasks, nodes, and other bot elements. Once you upload a custom script file to the bot, it reduces the redundant development efforts by making all the functions in the file accessible anywhere in the bot.<\/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=\"Using_the_Custom_Script_File\">Using the Custom Script File<\/span><\/h3>\n<p>Let\u2019s consider one use case from a shopping bot to understand how you can leverage the custom script file to reduce development overhead considerably. Take a look at the following conversation flow of a shopping bot that frequently presents consumers with multiple options to make a choice. In the below chat, the bot first prompts the user to select the product line by clicking women\u2019s or men\u2019s products, and then also prompts them to select a product type such as clothing, footwear, or accessories.<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/21\/Chat-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15100\" src=\"\/wp-content\/uploads\/sites\/21\/Chat-1.png\" alt=\"\" width=\"253\" height=\"422\" \/><\/a><br \/>\nYou can observe that both the product line and product type options in the above chat are identical in functionality, but only the choices that they show differ. Instead of hard-coding the functionality of the button template into each node, you can write a function in the custom script file that can be invoked by these nodes by passing options. Below is the sample function script to accomplish the functionality.<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/21\/Function-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15101\" src=\"\/wp-content\/uploads\/sites\/21\/Function-1.png\" alt=\"\" width=\"325\" height=\"263\" \/><\/a><br \/>\nThe following image shows how the function can be called from the nodes.<br \/>\n<a ref=\"magnificPopup\" href=\"\/wp-content\/uploads\/sites\/21\/Invoking-function-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15102\" src=\"\/wp-content\/uploads\/sites\/21\/Invoking-function-1.png\" alt=\"\" width=\"639\" height=\"189\" \/><\/a><\/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=\"Uploading_a_Custom_Script_File\">Uploading a Custom Script File<\/span><\/h3>\n<p>Follow these steps to upload the script file to the bot:<\/p>\n<ol>\n<li>Select the <strong>Build<\/strong> tab from the top menu<\/li>\n<li>From the left menu, select <b>Configurations &gt; <\/b><strong>Bot Functions<\/strong><\/li>\n<li>Under the <strong>Custom Script<\/strong>, click <b>Import<\/b>.<\/li>\n<li>On the Import Custom Script dialog, click <b>Browse <\/b>and navigate to the script file in your local machine. Click <b>Import<\/b>.<\/li>\n<li>After the import is successful, click <b>Done<\/b>.<\/li>\n<\/ol>\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=\"Updating_Custom_Script_File\">Updating Custom Script File<\/span><\/h3>\n<p>You can add or modify functions in the custom script file by downloading the file, making changes, and then importing it back to the bot. Importing a new custom script file <span style=\"text-decoration: underline;\">replaces<\/span> the existing file, which cannot be retrieved later. Therefore, we recommend you exercise caution and keep a copy of the downloaded file for backup.<\/p>\n<ol>\n<li>Select the <strong>Build<\/strong> tab from the top menu<\/li>\n<li>From the left menu, select <b>Configurations &gt; <\/b><strong>Bot Functions<\/strong><\/li>\n<li>Under the <strong>Custom Script<\/strong>, click <b>Download<\/b> to save a copy of the file on your local computer.<\/li>\n<li>After you make changes to the file, click <b>Import New<\/b>.<\/li>\n<li>Click <b>Browse <\/b>to the location of the custom script file on your local computer and then click <b>Import<\/b>.<\/li>\n<li>Click <b>Done <\/b>when the import is complete.<\/li>\n<\/ol>\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><\/div><\/div><\/div><\/div><\/div><\/section>\n","protected":false},"excerpt":{"rendered":"Custom Script file enables you to collate and manage reusable utility JavaScript functions that can be used by different tasks, nodes, and other bot elements. Once you upload a custom script file to the bot, it reduces the redundant development efforts by making all the functions in the file accessible anywhere in the bot. Using...","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-18057","post","type-post","status-publish","format-standard","hentry","category-bot-functions"],"_links":{"self":[{"href":"https:\/\/developer.kore.ai\/v9-0\/wp-json\/wp\/v2\/posts\/18057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.kore.ai\/v9-0\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/developer.kore.ai\/v9-0\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v9-0\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.kore.ai\/v9-0\/wp-json\/wp\/v2\/comments?post=18057"}],"version-history":[{"count":4,"href":"https:\/\/developer.kore.ai\/v9-0\/wp-json\/wp\/v2\/posts\/18057\/revisions"}],"predecessor-version":[{"id":30930,"href":"https:\/\/developer.kore.ai\/v9-0\/wp-json\/wp\/v2\/posts\/18057\/revisions\/30930"}],"wp:attachment":[{"href":"https:\/\/developer.kore.ai\/v9-0\/wp-json\/wp\/v2\/media?parent=18057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/developer.kore.ai\/v9-0\/wp-json\/wp\/v2\/categories?post=18057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/developer.kore.ai\/v9-0\/wp-json\/wp\/v2\/tags?post=18057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}