チャットボットを構築しています。スクリプトの一部は次のとおりです
var convpatterns = new Array (
new Array (".*hi.*", "Hello there! ","Greetings!"),
new Array (".*ask me*.", Smoking),
new Array (".*no*.", "Why not?"),
ユーザーが「こんにちは」と入力した場合にわかるように、チャットボットは Hello there または Greetings! のいずれかで応答します。ユーザーが「質問してください」と入力すると、Smoking() 関数にリンクします。
function Smoking(){
window.iSpeech.speak(speakPluginResultHandler,nativePluginErrorHandler,"Do you smoke?");
return field
SmokingAnswer()
}
function SmokingAnswer(){
var userinput=document.getElementById("messages").value;
if (userinput="yes"){
window.iSpeech.speak(speakPluginResultHandler,nativePluginErrorHandler,"Oh no! Smoking is not good for your health!");
}else if(userinput="no"){
window.iSpeech.speak(speakPluginResultHandler,nativePluginErrorHandler,"Good to hear that you are not smoking!");
}
return field
}
したがって、Smoking() 関数内で、チャットボットは口頭でユーザーに「喫煙しますか?」と尋ね、ユーザーが「はい」または「いいえ」と入力できる次の関数 SmokingAnswer() にリンクする必要があります。その後、ユーザーからの応答に基づいて応答します。しかし、今は「質問してください」と入力すると、チャットボットが「タバコを吸いますか?」と尋ねますが、「いいえ」と入力すると、「タバコを吸っていないと聞いてよかったです!」ではなく、チャットボットが「なぜですか?」と言います。新しい配列に基づいています。
更新(提案に基づいて変更されましたが、まだ機能していません):
function initialCap(field) {
field = field.substr(0, 1).toUpperCase() + field.substr(1);
return field
}
function Smoking(){
window.iSpeech.speak(speakPluginResultHandler,nativePluginErrorHandler,"Do you smoke?");
SmokingAnswer()
}
function SmokingAnswer(){
var userinput=document.getElementById("messages").value;
if (userinput=="yes"){
window.iSpeech.speak(speakPluginResultHandler,nativePluginErrorHandler,"Oh no! Smoking is not good for your health!");
}else if(userinput=="no"){
window.iSpeech.speak(speakPluginResultHandler,nativePluginErrorHandler,"Good to hear that you are not smoking!");
}
return field
}