AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

AIML code
 
 

Hi everyone,

Need a little help in AIML if possible.

How we can program the bot to offer 3 or 4 answers and the human should answer one of these options to get to the next question etc.. The bot will end in by opening another link or url,

I am stuck with the AIML code…

Enjoy your day all!

Thanks,
Mazen

 

 
  [ # 1 ]

Hi, Mazen! smile

Your question more or less depends on how you intend to word the questions and what you expect as valid replies. Can you post what you already have so that a relevant example could be crafted? Thanks.

 

 
  [ # 2 ]

Hello Dave,

An example of simple chatbot is as follows: the chatbot asks the human a question with 3 or more predefined answers and the the human has to click one of these answers to go to the next question. I am working with chatfuel but I want my chatbot to be running on my website and not into facebook messenger.

<category>
      <
patternHELLO </pattern>
      
      <
template>
         
Hello Userplease choose the occasion:
         
xxxx
         xxxx
         xxxx
      
</template>
   </
category

xxxx are the options that the user can choose from and will direct him to another question…

Thanks for your response!

 

 
  [ # 3 ]

Ok, let’s look at this in terms of a quiz. when the chatbot asks a question that requires one of several answers, you’ll need to set up the AIML categories in a certain way. The following example is one way to do just that. What you have for your example isn’t the best way to start out due to some issues with the code (I’ll address that at the end of this post), so I’ll post code that I feel will serve your needs best:

<category>
    <
pattern>HELLO</pattern>
    <
template>HelloWould you like to take a short quiz?</template>
</
category>
<
category>
    <
pattern>NO</pattern>
    <
that>* TAKE A SHORT QUIZ</that>
    <
template>
        <!-- 
add a response here to handle a "no" answer -->
    </
template>
</
category>
<
category>
    <
pattern>*</pattern>
    <
that>* TAKE A SHORT QUIZ</that>
    <
template>
        <!-- 
add a response here to handle any inputs that are neither yes nor no -->
    </
template>
</
category>
<
category>
    <
pattern>YES</pattern>
    <
that></that>
    <
template>
        <
srai>QUIZQUESTION1</srai>
    </
template>
</
category>
<
category>
  <
pattern>QUIZQUESTION1</pattern>
  <
template>
    
please choose the occasion:

    
XXX1
    XXX2
    XXX3
  
</template>
</
category>
<
category>
  <
input>*</input>
  <
that>PLEASE CHOOSE THE OCCASION *</that>
  <
template>
    <
think>
        <
set name="QQ1ANSWER"></star></set>
        <
set name="NEXTQUESTION">QUIZQUESTION2</set>
    </
think>
    <
condition name="QQ1ANSWER">
        <
li value="XXX1"><!-- handle response for condition XXX1 here --></li>
        <
li value="XXX2"><!-- handle response for condition XXX2 here --></li>
        <
li value="XXX3"><!-- handle response for condition XXX3 here --></li>
        <
li value="quit">
            <!-- 
this is included in case the user wants to exit the quiz -->
            <
think><set name="NEXTQUESTION">QUIZABORT</set></think>
        </
li>
        <
li>
            <
think><set name="NEXTQUESTION">QUIZQUESTION1</set></think>
            
I am sorrybut I do not understand what you mean by thatPlease try again.
        </
li>
    </
condition>
    <
srai><get name="NEXTQUESTION"></srai>
  </
template>
</
category>
<
category>
  <
pattern>QUIZQUESTION2</pattern>
  <
template>
    <!-- 
the second question to be asked will go herewith answers handled just like QUIZQUESTION1above -->
  </
template>
</
category>
<
category>
  <
pattern>QUIZABORT</pattern>
  <
template>
    <!-- 
abort the quiz -->
  </
template>
</
category

There are other ways of doing this, but this way is compact, fairly easy to follow, and works pretty well. The idea is simple, really. The code creates a linear progression that only advances when an expected input is given, looping back on itself if an unexpected input is seen. I’ve added an “escape clause” to the code to show how that’s handled as well. Additional questions are handled in exactly the same manner, with the exception of the last question, but that’s something that I didn’t cover here because I don’t wish to do ALL of your homework for you. raspberry

Now let’s move on to something else for a moment. I’m sure that you noticed that my AIML code (and now the AIML code that you also posted) sits within a grey “box”, and that all of the code is visible. This is because I’ve surrounded the AIML code with [code] tags. This is done for a very important reason. The forum software used here does not allow certain HTML/XML tags to be displayed in order to prevent malicious code execution, and the <pattern> tag (among others) is among these “forbidden” tags. The only reason you see it here, outside of [code] tags is because I know how to get around this. The “how” of that is unimportant, so I won’t get into it. The bottom line here is that any AIML, HTML, PHP, JavaScript or any other type of code needs to be placed within [code] tags in order for it to be properly displayed. It’s a really good habit to get into, so I encourage you to start now.

Ok, now that that’s done, let’s move on to the original AIML code that you posted. I feel that I need to point out that nearly ALL AIML interpreters are very literal and strict when it comes to the contents of <pattern>, <that> and <topic> tags. The extra spaces that you’ve added surrounding the word HELLO in your <pattern> tag will produce unexpected results if left there. there can be no leading or trailing spaces within the tags I mentioned unless you intend the user to make use of such spaces in their inputs, and that’s an unreasonable expectation. Thus, this:

<patternHELLO </pattern

should look like this, instead:

<pattern>HELLO</pattern

The difference is subtle to the eye, but it’s VERY important to remember.

I hope this helps. smile

 

 

 

 
  login or register to react