Basic Usage
There are two pieces to every chatbot - a BotmanChatbot plugin which provides the business logic of your chatbot, and a BotmanWidget plugin which provides the interface. The module provides a few widgets you can use right out of the box including a web widget (provided by the botman framework), and an embed widget, which embeds the chatbot in the content of a page.
Chatbots are added to the site using the Botman Chatbot block type. When adding the block, you can select the BotmanChatbot plugin to use as well as the BotmanWidget to display it.
Getting Started
Create a BotmanChatbot Plugin
You must create at least one BotmanChatbot plugin.
You can look at botman/modules/examples/botman_helloworld/src/Plugin/HelloWorldChatbot.php for an example.
A simple plugin example
<?php
namespace Drupal\botman_helloworld\Plugin\BotmanChatbot;
use Drupal\botman\BotmanChatbotBase;
use Drupal\botman\BotmanChatbotInterface;
use BotMan\BotMan\BotMan;
/**
* @BotmanChatbot(
* id = "helloworld",
* label = @Translation("HelloWorld")
* )
*/
class HelloWorldChatbot extends BotmanChatbotBase implements BotmanChatbotInterface {
/**
* {@inheritdoc}
*/
public function initialize(Botman $botman) {
$botman->hears('hello|hi|hola', function (Botman $botman) {
$botman->reply('Hello, nice to meet you.');
});
return $botman;
}
}
Add a Botman Chatbot Block to your site
Once you've created your chatbot plugin, you can add it to the website by going to /admin/structure/block, clicking Place Block for the content region and selecting the Botman Chat Block. On the block configuration screen you can select your plugin as well as a widget for displaying/interacting with the chatbot.
For a full example, take a look at the example module in:
/botman/modules/examples/botman_helloworld/
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion