Chatbot-Alpha

 view release on metacpan or  search on metacpan

lib/Chatbot/Alpha/Tutorial.pm  view on Meta::CPAN

  + tell me a poem
  - Little Miss Muffet\n
  ^ sat on her tuffet\n
  ^ in a nonchalant sort of way.\n
  ^ With her forcefield around her,\n
  ^ the spider, the bounder,\n
  ^ is not in the picture today.

=head2 Conditionals

Conditionals are useful for checking things about a user. You can compare variables to their values.

To modify variables, that's done in your Perl code. You make calls such as these to your Chatbot::Alpha object:

  # Set variables.
  $alpha->setVariable ("name", "Bob");
  $alpha->setVariable ("gender", "male");

  # Remove variables.
  $alpha->removeVariable ("gender");

  # Clear all variables.
  $alpha->clearVariables;

You can check variables' values in your replies with the *CONDITION command. Its basic format is:

  * VARIABLE=VALUE::Say This

Conditionals always need at least one -REPLY in the end to fall back on, in case none of the conditions
return true!

Examples:

  + am i a boy or a girl
  * gender=male::You're a boy.
  * gender=female::You're a girl.
  - I don't know what you are.

  + am i your master
  * master=1::Yes, you are my master.
  - No, you're not.

=head2 Simple Conversation Holders

These are relatively deprecated. They're for holding conversations quite simply. For example a "knock knock"
joke, or for the bot to go on rambling about stuff.

These aren't perfect, and sometimes you'll break out of the conversation by matching a better reply.

Examples:

  // Knock-Knock
  + knock knock
  - Who's there?
  & <msg> who?
  & Ha! <msg>! That's a good one!

  // Rambling
  + are you crazy
  - I was crazy once.
  & They locked me away...
  & In a room with padded walls...
  & There were rats there...
  & I don't like rats.
  & Rats make me crazy!
  & Did I mention I was crazy once?

=head2 "That's"

As I mentioned above, the &HOLDER command is buggy. You can use what we call "that", which is an emulation
of AIML's <that> functionality. It's to give your bot a cure of its A.D.D.

The %THAT command B<must> come directly after the +TRIGGER, before any other command. Here are some examples...

  + ask me a question
  - Do you have any pets?

  + yes
  % do you have any pets
  - What are their names?

  + *
  % what are their names
  - Those are cool names.

  ////////////////////////

  + i am *
  - Are you really?

  + yes
  % are you really
  - How long have you been?

The data of the %THAT command would be the bot's last response, lowercase and with no puncuation. This is a much
better method of holding onto conversations than the &HOLDER command is.

If their next message doesn't have a "that" attached to it (i.e. if the bot asks if they have any pets and they
don't say yes), it will get another reply as normal. However if they do say "yes", it will ask them what their names
are, rather than give a generic reply to "yes".

=head2 Topics

Sometimes, that's just don't do it for you. Topics are groups of replies. The default topic is "B<random>". When
in a topic, you can ONLY match triggers within that topic.

To open a topic, you use the <LABEL and >LABEL commands. To set the user's topic, you use the {topic} tag. See
the below example for how this is all formatted.

Set {topic=random} to return to the default topic.

A practical application for a topic is to force somebody to apologize for being mean.

  + i hate you
  - You're very mean! I'm not going to talk with you until you apologize.{topic=apology}

  > topic apology
    + *
    - Not until you apologize.
    - Say you're sorry.



( run in 2.521 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )