I am slowly getting somewhere with my chatbot

So today I reworked most of my chatbot code so that he would accept multiple greetings ("Hi", "Hullo", "Hello" etc).  Also, I wanted Mac to respond with a friendly "what is your name?" and have the chatbot remember what to call you in the future.


This is achieved through the use of AIML <srai> recursion and setting context with <that>.

  • This code deals with matching multiple ways of saying 'Hi'.  What did I miss out?


<category><pattern>HI</pattern><template>Hullo. What is your name?</template></category>
<category><pattern>HI ^</pattern><template><srai>HI</srai></template></category>
<category><pattern>HELLO ^</pattern><template><srai>HI</srai></template></category>
<category><pattern>HULLO ^</pattern><template><srai>HI</srai></template></category>
<category><pattern>HEY ^</pattern><template><srai>HI</srai></template></category>
<category><pattern>HOWDY ^</pattern><template><srai>HI</srai></template></category>
<category><pattern>SUP ^</pattern><template><srai>HI</srai></template></category>

  • This code deals with the user replying to Mac's question "What is your name?"  Whatever is typed is stored in a variable called 'name' for later.

<category><pattern>*</pattern><that>^ WHAT IS YOUR NAME</that>
<template>It is nice to meet you <set name="name"><star/></set>.</template></category>
<category><pattern>MY NAME IS *</pattern><that>^ WHAT IS YOUR NAME</that>
<template>It is nice to meet you <set name="name"><star/></set>.</template></category>

  • This code deals with the user checking whether Mac has indeed remembered their name.
<category><pattern>WHAT IS MY NAME</pattern><template>You are <get name="name"/>.</template></category>
<category><pattern>WHO AM I</pattern><template><srai>WHAT IS MY NAME</srai></template></category>