Skip to content
Philip Nicolcev edited this page Jan 7, 2014 · 3 revisions

To make your chatbot respond to certain keywords, follow these steps.
Remeber that you should not use windows notepad to edit PHP code. Get an editor like Notepad++ to edit php code or you may encounter problems.

Open lib/class/AJAXChat.php and do a search for this:

function insertParsedMessage($text)
At the end of this function (about line 762 or so) is this:
	} else {
			// No command found, just insert the plain message:
			$this->insertCustomMessage(
				$this->getUserID(),
				$this->getUserName(),
				$this->getUserRole(),
				$this->getChannel(),
				$text
			);

		}

          }

Right ABOVE the last } paste this:

include("chatbot.php");

Save, then create a new php page called chatbot.php in the lib/class/ folder (or you can create the chatbot.php first if you want to avoid any interruption in ajax chat).

enter this code into the chatbot.php page

<?php
// Chat bot messages
if(stristr($text, 'help me')) {
	// KEYWORDS TRIGGER START
    $this->insertChatBotMessage(
		$this->getPrivateMessageID(),
		"\nHow may I help you?\n" //This is what the chatbot says when the visitor enters "help me" anywhere in a sentence!
	);
}
// KEYWORD TRIGGER END

?>

What to change if(stristr($text, 'help me')) is the part you enter your keyword (help me). The chatbot response is added in between the quotes ("\nHow may I help you?\n")

The \n at the beginning makes the message show below the chatbot name and the \n at the end makes a space between the end of the message and the bottom of the chat screen.

You can add all the keyword triggers you wish by copying and pasting the if statement above BELOW the KEYWORD TRIGGER END comment!

You can use the \n for a double line break or the \r for a single line break.

Jan (hiredgunz)
support at articlefriendly dot com