Skip to content

Commit

Permalink
Issue #SB-0000 merge: Merge pull request #42 from JagadishPujari/rele…
Browse files Browse the repository at this point in the history
…ase-3.7.0

Release 3.7.0
  • Loading branch information
vinukumar-vs authored Mar 5, 2021
2 parents df2841a + 59d6842 commit ee3aedc
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 33 deletions.
38 changes: 23 additions & 15 deletions bot/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,34 @@ node('build-slave') {
println(ANSI_BOLD + ANSI_YELLOW + "github_release_tag specified, building from github_release_tag: " + params.github_release_tag + ANSI_NORMAL)
}
echo "public_repo_commit_hash: " + public_repo_commit_hash
bot_repo_url = params.diksha_bot_repo
dir('bot_repo') {
if (params.diksha_bot_tag == "") {
def scmVars = checkout scm
checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/heads/master"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]])
private_repo_commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
}
else {
def scmVars = checkout scm
checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/tags/params.diksha_bot_tag"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]])
private_repo_commit_hash = params.diksha_bot_tag
}
}
bot_repo_url = params.private_bot_repo

if (params.private_bot_repo) {
dir('bot_repo') {
if (params.private_bot_tag == "") {
def scmVars = checkout scm
checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/heads/master"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]])
private_repo_commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
}
else {
def scmVars = checkout scm
checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/tags/params.private_bot_tag"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]])
private_repo_commit_hash = params.private_bot_tag
}
}

}

}

stage('Build') {
env.NODE_ENV = "build"
print "Environment will be : ${env.NODE_ENV}"
build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot"
sh('cp -r bot_repo/* .')
build_tag = public_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot"
if (params.private_bot_repo) {
sh('cp -r bot_repo/* .')
build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot"
}
dir('bot') {
sh('chmod 777 build.sh')
sh("./build.sh ${build_tag} ${env.NODE_NAME} ${hub_org}")
Expand Down
22 changes: 15 additions & 7 deletions router/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,34 @@ node('build-slave') {
}

echo "public_repo_commit_hash: " + public_repo_commit_hash
bot_repo_url = params.diksha_bot_repo
dir('bot_repo') {
if (params.diksha_bot_tag == "") {
bot_repo_url = params.private_bot_repo

if (params.private_bot_repo) {
dir('bot_repo') {
if (params.private_bot_tag == "") {
def scmVars = checkout scm
checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/heads/master"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]])
private_repo_commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
}
else {
def scmVars = checkout scm
checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/tags/params.diksha_bot_tag"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]])
private_repo_commit_hash = params.diksha_bot_tag
checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/tags/params.private_bot_tag"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]])
private_repo_commit_hash = params.private_bot_tag
}
}

}
}

stage('Build') {
env.NODE_ENV = "build"
print "Environment will be : ${env.NODE_ENV}"
build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_router"
sh('cp -r bot_repo/* .')

build_tag = public_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot"
if (params.private_bot_repo) {
sh('cp -r bot_repo/* .')
build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot"
}
dir('router') {
sh('chmod 777 build.sh')
sh("./build.sh ${build_tag} ${env.NODE_NAME} ${hub_org}")
Expand Down
13 changes: 7 additions & 6 deletions router/appRest.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,19 @@ function menuDrivenLogic(data, res, chatflowConfig) {
menuIntentKnown = true
// TODO : Don't call function inside each if/else if it should be called once.
telemetryData = createInteractionData({ currentStep: currentFlowStep, responseKey: responseKey }, data, false)
// Telemetry event for Main menu button
var mainMenuEventData = createInteractionData({ currentStep: 'step_0', responseKey: 'MAIN_MENU' }, data, false)
telemetry.logInteraction(mainMenuEventData);
} else if (data.message === '99') {
if (currentFlowStep.lastIndexOf("_") > 0) {
currentFlowStep = currentFlowStep.substring(0, currentFlowStep.lastIndexOf("_"))
responseKey = chatflowConfig[currentFlowStep].messageKey
menuIntentKnown = true
// TODO : Don't call function inside each if/else if it should be called once.
telemetryData = createInteractionData({ currentStep: currentFlowStep, responseKey: responseKey }, data, false)
// Telemetry event for Go-back button
var goBackEventData = createInteractionData({ currentStep: 'step_99', responseKey: 'GO_BACK' }, data, false)
telemetry.logInteraction(goBackEventData);
}
} else {
responseKey = getErrorMessageForInvalidInput(currentFlowStep, chatflowConfig, true)
Expand Down Expand Up @@ -532,9 +538,4 @@ function replaceUserSpecficData(str) {
}
return str;
}






module.exports = appBot;
17 changes: 12 additions & 5 deletions router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
"description": "thor bot router",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"router-test": "nyc mocha 'test/**/*.spec.js'",
"coverage": "nyc --reporter=lcov --reporter=text-lcov npm run router-test"
},
"author": "waibhav",
"license": "ISC",
"dependencies": {
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"cors": "^2.8.5",
"dateformat": "^3.0.3",
"elasticsearch": "^16.6.0",
Expand All @@ -18,15 +22,18 @@
"helmet": "^3.21.2",
"lodash": "^4.17.20",
"method-override": "^3.0.0",
"ua-parser-js": "^0.7.13",
"sb_telemetry_util": "file:libs/sb_telemetry_util",
"sb_config_util": "file:libs/sb-config-util",
"sb_logger_util": "file:libs/sb_logger_util",
"mocha": "^8.2.1",
"nock": "^13.0.5",
"nyc": "^15.1.0",
"redis": "^3.0.2",
"request": "^2.88.0",
"require-reload": "^0.2.2",
"sb_config_util": "file:libs/sb-config-util",
"sb_logger_util": "file:libs/sb_logger_util",
"sb_telemetry_util": "file:libs/sb_telemetry_util",
"socket.io": "^2.3.0",
"tz-lookup": "^6.1.25",
"ua-parser-js": "^0.7.13",
"uuid": "^3.4.0",
"winston": "^3.2.1"
}
Expand Down
78 changes: 78 additions & 0 deletions router/test/appRest.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const chai = require('chai');
let chaiHttp = require('chai-http');
chai.should();
chai.use(chaiHttp);
let server = require('../appRest');
const nock = require('nock');
const mockData = require('./mock.data.spec');
var expect = require('chai').expect;

describe('Chatbot router APIs', () => {
it('it should get bot response fot user input on web portal', (done) => {
nock('https://dev.sunbirded.org/chatapi')
.post('/bot')
.reply(200, mockData.botResponse);
const response = {"type":"button","data":{"text":" Hello, I am Tara!<br>I am your DIKSHA guide<br>Please select your preference from the options I provide or type your query directly.","buttons":[{"text":"Digital content","value":"1"},{"text":"Courses","value":"2"},{"text":"DIKSHA mobile app","value":"3"},{"text":"Content contribution","value":"4"},{"text":"Other DIKSHA queries","value":"5"}]}}
chai.request(server)
.post('/bot')
.send({
"Body": "0",
"userId": "449c94833e1caa71aaadfe2567bea945",
"appId": "prod.diksha.portal",
"channel": "505c7c48ac6dc1edc9b08f21db5a571d",
"From": "449c94833e1caa71aaadfe2567bea945"
})
.end((err, res) => {
expect(res).to.be.a('object');
expect(res.body).to.be.a('Object');
expect(JSON.stringify(res.body)).to.equal(JSON.stringify(response));
done();
});
});

xit('it should get bot response fot user input in whats app', (done) => {
nock('https://preprod.ntp.net.in/chatapi')
.post('/whatsapp')
.reply(200, mockData.whatsappResponse);
const response = {
"text": "Hi, I’m TARA, your DIKSHA assistant. How may I help you today? \n Select from one of the following options. Send the number corresponding to your choice \n 1- To find and play content \n 2- To download/update the DIKSHA mobile app \n 3- Other Queries",
"intent": "greet",
"type": "buttons",
"buttons": []
};
chai.request(server)
.post('/whatsapp')
.send({
"incoming_message": [{
"from": "9611654628",
"text_type": {
"text": "0"
}
}]
})
.end((err, res) => {
expect(res).to.be.a('object');
expect(res.body).to.be.a('Object');
expect(JSON.stringify(res.body)).to.equal(JSON.stringify(response));
done();
});
});

it('refresh the config', (done) => {
nock('https://dev.sunbirded.org/chatapi')
.post('/refresh')
.reply(200, mockData.refreshAPIResponse);
const response = {
"msg": "ENV configuration blob path is not defined"
}
chai.request(server)
.post('/refresh')
.end((err, res) => {
expect(res).to.be.a('object');
expect(res.body).to.be.a('Object');
expect(JSON.stringify(res.body)).to.equal(JSON.stringify(response));
done();
});
});

});
53 changes: 53 additions & 0 deletions router/test/mock.data.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module.exports = {
botResponse:{
"type": "button",
"data": {
"text": " Hello, I am Tara!<br>I am your DIKSHA guide<br>Please select your preference from the options I provide or type your query directly.",
"buttons": [
{
"text": "Digital content",
"value": "1"
},
{
"text": "Courses",
"value": "2"
},
{
"text": "DIKSHA mobile app",
"value": "3"
},
{
"text": "Content contribution",
"value": "4"
},
{
"text": "Other DIKSHA queries",
"value": "5"
}
]
}
},
whatsappResponse:{
"text": "Hi, I’m TARA, your DIKSHA assistant. How may I help you today? \n Select from one of the following options. Send the number corresponding to your choice \n 1- To find and play content \n 2- To download/update the DIKSHA mobile app \n 3- Other Queries",
"intent": "greet",
"type": "buttons",
"buttons": []
},
refreshAPIResponse: {
"msg": "ENV configuration blob path is not defined"
},
postRes: {
"code": "ok",
"payload": {}
},
errorResponse: {
"code": "params-missing",
"message": "Something was wrong with the request payload you passed in. | Required parameters were missing from this API call, please see the \"params\" property",
"params": {}
},
errorMessage: {
"code": "not-found",
"message": "Invalid API call",
"params": {}
}
}

0 comments on commit ee3aedc

Please sign in to comment.