Skip to content

Commit

Permalink
Update to version v5.2.2
Browse files Browse the repository at this point in the history
Update to version v5.2.2
  • Loading branch information
tabdunabi authored Oct 24, 2022
2 parents 388c053 + 133077a commit f2bf6a9
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 141 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.2.2] - 2022-10-24

### Updated

- Security patches for npm and pip packages
- `axios` npm package removed from lambda/cfn
- Add retries for elasticsearch api requests with 5xx error codes to improve stability of initial stack deployment
- Split the creation of Lex Bot Versions in CF templates into batches of 3 to improve stability of initial stack deployment


### Fixed

- Lex rebuild failures when there is any single character utterance (#503)
- ElicitResponse bug causing bot to prompt 'What is the question?' (#506)

## [5.2.1] - 2022-09-15

### Updated
Expand Down
14 changes: 7 additions & 7 deletions lambda/cfn-lambda-layer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lambda/cfn-lambda-layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"license": "ISC",
"dependencies": {
"cfn-lambda": "^5.1.0"
},
"overrides": {
"minimatch@<3.0.5": "3.0.5"
}
}
}
55 changes: 7 additions & 48 deletions lambda/cfn/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions lambda/cfn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.913.0",
"axios": "^0.21.1",
"bluebird": "^3.5.0",
"body-parser": "^1.18.2",
"cfn-lambda": "^4.0.0",
Expand All @@ -29,6 +28,6 @@
"devDependencies": {
"diff": "^4.0.2",
"tap": "^16.2.0",
"tap-mocha-reporter": "^5.0.1"
"tap-mocha-reporter": "^5.0.3"
}
}
}
59 changes: 41 additions & 18 deletions lambda/es-proxy-layer/lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const qnabot = require("qnabot/logging")


module.exports=function(opts){

const url=Url.parse(opts.url)
const request={
host:url.hostname,
Expand All @@ -19,15 +19,20 @@ module.exports=function(opts){
}
request.headers['Host']=request.host;
if(opts.body){
//if the JSON body being passed to elasticsearch is an array,
//then let's convert it to a newline delmited JSON string (ndjson)
if(Array.isArray(opts.body)){
opts.body=opts.body.map(JSON.stringify).join('\n')+'\n'
request.headers['content-type']='application/x-ndjson'
}else if(typeof opts.body === "string"){
opts.body=opts.body
request.headers['content-type']='application/json'
}else{
request.headers['Content-Type']='application/x-ndjson'
}
//stringify the body object into JSON if not already a string
else if(typeof opts.body !== "string"){
opts.body = JSON.stringify(opts.body)
request.headers['content-type']='application/json'
}

//if content type is not set, default to application/json
if(!request.headers['Content-Type'] && !request.headers['content-type']){
request.headers['Content-Type']='application/json'
}
request.body=opts.body
request.data=opts.body
Expand All @@ -39,22 +44,40 @@ module.exports=function(opts){
if(count>0){
qnabot.log("Tries left:"+count)
var credentials=aws.config.credentials
var signed=sign(request,credentials)
Promise.resolve(axios(signed))
.then(res)
.catch(error=>{
if(error.code==="ECONNABORTED"){
setTimeout(()=>next(--count),1000)
}else{
var signed=sign(request,credentials)
axios(signed)
.then(res)
.catch(error=>{
// if the server responded with an actual HTTP response then log and retry on 5xx codes
if (error.response) {
qnabot.log(error.response.data);
qnabot.log(error.response.status);
if(error.response.status >= 500){
qnabot.log("Received 500 error code, retrying...")
setTimeout(()=>next(--count),1000)
}
else{
//any non 5xx failure codes should be rejected as normal
rej(error)
}
}
//in some cases, the axios client does not return a fully formatted response object
//in those cases, the message property may contain useful debugging information
else if(error.message) {
qnabot.log(error.message);
rej(error)
}
else{
rej(error)
}
})
}else{
rej("timeout")
})
}
else{
rej("Retry limits exceeded. See logs for additional information.")
}
}
next(10)
})
.tap(x=>qnabot.log(x.status))
.get('data')
}
}
18 changes: 9 additions & 9 deletions lambda/es-proxy-layer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lambda/es-proxy-layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "ISC",
"dependencies": {
"aws4": "^1.6.0",
"axios": "0.21.1",
"axios": "0.21.4",
"handlebars": "^4.7.2",
"linkifyjs": "^3.0.0-beta.3",
"simple-encryptor": "^3.0.0",
Expand Down
17 changes: 13 additions & 4 deletions lambda/fulfillment/lib/middleware/lex.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ function isConnectClientChat(req){
}

function isElicitResponse(request, response){
return _.get(response,'result.elicitResponse.responsebot_hook', undefined) !== undefined || _.get(request,'session.qnabotcontext.specialtyBot' ,undefined) !== undefined;
let result = false;
const qnabotcontextJSON = _.get(response,'session.qnabotcontext');
if (qnabotcontextJSON) {
const qnabotcontext = JSON.parse(qnabotcontextJSON);
if (_.get(qnabotcontext,'elicitResponse.responsebot')) {
result = true;
}
if (_.get(qnabotcontext,'specialtyBot')) {
result = true;
}
}
return result;
}

function trapIgnoreWords(req, transcript) {
Expand Down Expand Up @@ -395,9 +406,7 @@ function getV2ElicitTemplate(request, response){
sessionState: {
sessionAttributes:_.get(response,'session',{}),
dialogAction:{
type:'ElicitSlot',
slotToElicit: 'qnaslot'
},
type:'ElicitIntent' },
intent: {
name: 'QnaIntent',
},
Expand Down
5 changes: 3 additions & 2 deletions lambda/import/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ exports.step = function (event, context, cb) {
objects.push(questionStr)
})
config.buffer = ""
} else {
} else {
objects = config.buffer.split(/\n/)
JSON.parse(objects[objects.length - 1])
config.buffer = ""
Expand Down Expand Up @@ -140,7 +140,8 @@ exports.step = function (event, context, cb) {
endpoint: process.env.ES_ENDPOINT,
method: "POST",
path: "/_bulk",
body: result
body: result,
headers: {'Content-Type': 'application/x-ndjson'}
}

return lambda.invoke({
Expand Down
Loading

0 comments on commit f2bf6a9

Please sign in to comment.