You just need to instantiate Johnny5 function with the configuration of your conversation. To run it you need to run the method start.
var myJohnny5 = Johnny5(myConfig);
myJohnny5.start();
Type: DOM element
The input element where the users will write their answers.
Type: DOM element
The output element where Johnny5 will prints her phrases.
Type: String
The name of the robot. Will be printed in his chat messages.
Type: String
The name of the user. Will be printed in his chat messages.
Type: Object
The conversation screenplay.
Type: String
The first question id. Johnny5 will start the conversation with that question.
Type: Object
The object with the questions.
Type: Object
A question configuration object.
Type: String|Array
The phrase of the question. If is an array will gets randomly one of the phrases.
Type: Array
List of posibles answers.
Type: Object
Answer configuration object.
Type: String | Function | Undefined
The possible answer or, if a function, the validation function of the answer. Must return a Boolean
If is not defined will be used as default answer for the question.
Type: String
Id of the conversation.questions
that Johnny5 will ask after the answer.
var myJohnny5 = new Johnny5( {
input: document.getElementById('input'),
output: document.getElementById('output'),
robotName: 'Johnny 5',
userName: 'You',
conversation: {
startPhrase: 0,
questions: {
0: {
phrase: 'Hi there! Do you want to register?',
answers: [ {
answer: 'yes',
goTo: 1
}, {
answer: 'no',
goTo: 2
}, {
goTo: 6
} ]
},
1: {
phrase: 'Great! Write your email!',
answers: [ {
answer: function ( input ) {
return input === 'email';
},
goTo: 4
}, {
goTo: 7
} ]
},
2: {
phrase: 'What a pitty! Let me know if you change your mind',
answers: [ {
answer: 'bah',
goTo: 2
}, {
goTo: 3
} ]
},
3: {
phrase: 'Hey! Do you change your mind?',
answers: [ {
answer: 'yes',
goTo: 1
}, {
answer: 'no',
goTo: 2
}, {
goTo: 6
} ]
},
4: {
phrase: 'Perfect! We got you!',
answers: [ {
goTo: 5
} ]
},
5: {
phrase: 'My job is done here. Have a nice day!',
answers: [ {
goTo: 5
} ]
},
6: {
phrase: 'Sorry, I cant understand you. Try again with just yes or no.'
},
7: {
phrase: 'Please, enter a valid email address'
}
}
}
});
myJohnny5.start();
You can check a live demo here.