License: GPL
version="1.0" encoding="UTF-8"?> <Config> <State id="0"> <message>Hello, How are you?message> <keywords> <keyword target="1">happykeyword> keywords> State>In the above example, If user enters happy keyword, bot moves to State "1" and display one of state "1" messages randomly, If user enters any other strings, one of the invalid messages will appear.<State id="1"> <message>wow, you are happy!message> <message>glad to hear that!message> State> <InvalidMessages> <message>Huh, I didn't understand?message> <message>What do you mean?message> InvalidMessages> Config>
Keyword tag contains multiple attributes to make it possible to customize the bot according to the requirements.
<State id="16"> <message>Hello, how are you today?message> <message>How are you feeling?message> <message>How are you doing?message> <keyword target="11">happy, very happykeyword> <keyword target="13">not happy,not good,not fine,sad,upsetkeyword> <keyword target="23">fine, good, thankskeyword> <keyword target="14">yourselfkeyword> State>
Using the weather feature
To use weather feature, keyword tag should contain two attributes, className and arg, className should set to Weather and arg should set to "today", "tomorrow" or "dayaftertomorrow" keywords. Here is an example to get today's weather:
<keyword className="Weather" arg="today">weatherkeyword>
Result:
You: how is the weather Bot: I think today is Fog
<State id="11"> <message>That's great, why you are happy?message> <keywords> <keyword target="21">lotterykeyword> <keyword target="22">*keyword> keywords> State>
<Config> <State id="0"> <message>Hello, My name is MajBot, what is your name?message> <keywords> <keyword target="2" variable="name">([a-zA-Z ]+)keyword> keywords> State> <State id="16"> <message>Hello [name], nice to see you!message> State> Config>Result:
Bot: Hello, My name is MajBot, what is your name? You: Majid Bot: Hello majid, nice to see you!In the above example "([a-zA-Z )+)" regex accepts any characters betwen a to z (case insensitive) including spaces and store the matching word to name variable, then by using [name] in the message, user's name will be replaced with this tag. (For more information about Regex syntax refer to Java Regex Documentation).
<Config> <State id="0"> <message>Hello, My name is MajBot, what is your name?message> <keywords> <keyword target="16" variable="name" points="2">.*my name is ([a-zA-z]+).*keyword> <keyword target="16" variable="name">([a-zA-Z ]+)keyword> keywords> State> <State id="16"> <message>Hello [name], nice to see you!message> State> Config>Result:
Bot: Hello, My name is MajBot, what is your name? You: my name is Majid Bot: Hello majid, nice to see you!In the above example we are adding 2 points for the first keyword so if user enters "my name is Majid", it only gets the name instead of returning "My name is Majid" as name.
<State id="1"> <message>What do you want to talk about?message> <keyword variable="subject" target="27">([a-zA-z]+)keyword> State> <State id="27"> <message>What is [subject]?message> <keyword target="43" variable="result" learn="subject">(.*)keyword> State>Result:
Bot: What do you want to talk about? You: football Bot: What is football? You: it is a good game Bot: I see... Bot: What do you want to talk about? You: football Bot: it is a good gameAs it is shown in the above example, bot learns about football keyword and then send the response back to the user when user sends same keyword again.
java -cp MajBot.jar bot.MainTo run MajBot you can simply type:
sh run.shIf you are using windows, you can run run.bat file instead.
After starting the bot, user can enter a message and start chating with MajBot.
Enjoy!
http://www.majidkhosravi.com/chat-bot/