You can extend the capabilities of your bot using tags created by other people.
Or you can create new tags yourself and even offer them for other people to use.
Custom tag classes live in the App\LemurTag directory. You can have a look and see an example for the both types of tags;
In 99% of cases copying one of those files and adding your functionality to the closeTag() method will suit your needs.
Below is the custom HelloWorldTag.
You can find a copy of this in the app/LemurTag directory.
<?php
namespace App\LemurTag;
use LemurEngine\LemurBot\Classes\LemurLog;
use LemurEngine\LemurBot\LemurTag\AimlTag;
use LemurEngine\LemurBot\Models\Conversation;
/**
* Class HelloWorldTag
* @package App\LemurTag
*
* Usage:
*
* Example AIML:
*
* TEST HELLO WORLD
*
*
*
* Expected Conversation:
* Input: Test Hello World
* Output: Hello World!
*
* Documentation:
* https://docs.lemurengine.com/extend.html
*/
class HelloWorldTag extends AimlTag
{
protected string $tagName = "HelloWorld";
//this is a standard tag
static $aimlTagType = self::TAG_STANDARD;
/**
* HelloWorldTag Constructor.
* @param Conversation $conversation
* @param array $attributes
*/
public function __construct(Conversation $conversation, array $attributes = [])
{
parent::__construct($conversation, $attributes);
}
/**
* This method is called when the closing tag is encountered e.g.
* @return string|void
*/
public function closeTag()
{
//some debugging
LemurLog::debug(
__FUNCTION__, [
'conversation_id'=>$this->conversation->id,
'turn_id'=>$this->conversation->currentTurnId(),
'tag_id'=>$this->getTagId(),
'attributes'=>$this->getAttributes()
]
);
//build response in the stack
$this->buildResponse("Hello World!");
}
}
Below is the custom EchoTag.
You can find a copy of this in the app/LemurTag directory.
<?php
namespace App\LemurTag;
use LemurEngine\LemurBot\Classes\LemurLog;
use LemurEngine\LemurBot\LemurTag\AimlTag;
use LemurEngine\LemurBot\Models\Conversation;
/**
* Class EchoTag
* @package App\LemurTag
*
* Usage:
*
* Example AIML:
*
* ECHO *
*
*
*
* Expected Conversation:
* Input: Echo Yikes
* Output: Yikes
*
* Documentation:
* https://docs.lemurengine.com/extend.html
*/
class EchoTag extends AimlTag
{
protected string $tagName = "Echo";
//this is a standard tag
static $aimlTagType = self::TAG_STANDARD;
/**
* FormalTag Constructor.
* @param Conversation $conversation
* @param array $attributes
*/
public function __construct(Conversation $conversation, array $attributes = [])
{
parent::__construct($conversation, $attributes);
}
/**
* when we close the tag we need to decide if we want
*/
public function closeTag()
{
LemurLog::debug(
__FUNCTION__,
[
'conversation_id'=>$this->conversation->id,
'turn_id'=>$this->conversation->currentTurnId(),
'tag_id'=>$this->getTagId(),
'attributes'=>$this->getAttributes()
]
);
//this will return the value of
$contents = $this->getCurrentTagContents(true);
$this->buildResponse($contents);
}
}
Follow the guidelines below when making your custom tag;
You can create custom tag packages to allow others to pull in your custom tags or just to better organise your own tags;
Checkout the custom GoogleSearchTag on Packagist for an example on how to do this:
lemurtag-googlesearch
If you need help with customisation or a bespoke feature - then get in touch with us over that theramenrobotdiscocode.com and let's see how we can help.
Get In Touch