diff --git a/helm_charts/router/values.j2 b/helm_charts/router/values.j2 index a07937d..6d75c27 100644 --- a/helm_charts/router/values.j2 +++ b/helm_charts/router/values.j2 @@ -30,3 +30,4 @@ routerenv: WHATSAPP_SECRET_KEY: "{{sunbird_whatsapp_secret_key | default("''")}}" WHATSAPP_AUTH_TOKEN: "{{sunbird_whatsapp_auth_token | default("''")}}" WHATSAPP_SOURCE: "{{sunbird_whatsapp_source | default("''")}}" + CONFIG_BLOB_PATH: "{{sunbird_public_storage_account_name}}" \ No newline at end of file diff --git a/router/appRest.js b/router/appRest.js index 709d609..6a18a79 100644 --- a/router/appRest.js +++ b/router/appRest.js @@ -81,29 +81,35 @@ appBot.post('/whatsapp', function (req, res) { // Update latest config from blob appBot.post('/refresh', function(req, response) { - var domian = config.ENV_URL[req.headers.host] - var url = domian + 'chatbot/router/config/' - var dest = './config/' - - var literalsStr = 'literals.js'; - var chatflowStr = 'chatflow.js'; - updateConfigFromBlob(url, dest, literalsStr, function(){ - try { - literals = reload('./config/literals'); - updateConfigFromBlob(url, dest, chatflowStr, function(){ - try { - chatflow = reload('./config/chatflow'); - response.send({'msg': 'Configuration is updated successfully for chatflow and literals!!!'}) - } catch (e) { - //if this threw an error, the api variable is still set to the old, working version - console.error("Failed to reload literals.js! Error: ", e); - } - }) - } catch (e) { - //if this threw an error, the api variable is still set to the old, working version - console.error("Failed to reload literals.js! Error: ", e); - } - }) + if(config.CONFIG_BLOB_PATH) { + var domian = "https://" + config.CONFIG_BLOB_PATH + ".blob.core.windows.net" + var url = domian + '/chatbot/router/config/' + var dest = 'router/config/' + + var literalsStr = 'literals.js'; + var chatflowStr = 'chatflow.js'; + updateConfigFromBlob(url, dest, literalsStr, function(){ + try { + literals = reload('./config/literals'); + updateConfigFromBlob(url, dest, chatflowStr, function(){ + try { + chatflow = reload('./config/chatflow'); + response.send({'msg': 'Configuration is updated successfully for chatflow and literals!!!'}) + } catch (e) { + //if this threw an error, the api variable is still set to the old, working version + console.error("Failed to reload chatflow.js! Error: ", e); + response.send({'msg': e.message}) + } + }) + } catch (e) { + //if this threw an error, the api variable is still set to the old, working version + console.error("Failed to reload literals.js! Error: ", e); + response.send({'msg': e.message}) + } + }) + } else { + response.send({'msg': 'ENV configuration blob path is not defined'}) + } }) var updateConfigFromBlob = function(url, dest, configName, cb) { diff --git a/router/config/config.js b/router/config/config.js index 207c8ba..01ff82c 100644 --- a/router/config/config.js +++ b/router/config/config.js @@ -57,12 +57,6 @@ config.UNKNOWN_OPTION = 'unknown_option' config.TELEGRAM_BOT_ENDPOINT = 'https://api.telegram.org/bot/sendMessage' -config.ENV_URL = { - 'diksha.gov.in': 'https://ntpproductionall.blob.core.windows.net/', - 'staging.sunbirded.org':'https://ntpstagingall.blob.core.windows.net/', - 'preprod.ntp.net.in':'https://preprodall.blob.core.windows.net/', - 'dev.sunbirded.org':'https://sunbirddev.blob.core.windows.net/', - 'vdn.diksha.gov.in/': '' -} +config.CONFIG_BLOB_PATH = env.CONFIG_BLOB_PATH module.exports = config;