Skip to content

Commit

Permalink
Make greeting personalized and handle null response case
Browse files Browse the repository at this point in the history
Signed-off-by: Scar26 <mmatty26@gmail.com>
  • Loading branch information
Scar26 committed Jul 20, 2020
1 parent 5676ec4 commit 7de0fb0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const ctx = fs.readFileSync(`${__dirname}/factory.js`).toString()
const { NlpManager } = require('node-nlp')

class Bot {
constructor (name, greeting, trainingSet) {
constructor (name, greeting, trainingSet, defaultResponse) {
this.name = name
this.greeting = greeting
this.defaultResponse = defaultResponse
this.training = {
state: false,
data: trainingSet
Expand All @@ -22,8 +23,8 @@ class Bot {
this.factory.run(`trainingSet=${trainingSet}`)
}

greet () {
return this.render(this.greeting)
greet (token) {
return this.render(this.greeting, token)
}

addUser (token, name) {
Expand All @@ -47,6 +48,9 @@ class Bot {
} else {
message = response.body
}
if (!message) {
message = this.defaultResponse
}
message = this.render(message, token)
return { action: response.action, body: message }
}
Expand Down

0 comments on commit 7de0fb0

Please sign in to comment.