Architecture overview

The easiest way to understand Chatbots is to think about them as applications with a conversational interface. Most of the challenges revolve around structuring Business Logic into "Conversations".

Botomatic splits conversations into States. A state is a simple object that handles specific input -> output operations and is composed of:

The State object uses the Message object to determine the intent of the user and the Response object to store all possible responses of that State

{tip} A state can have as many input -> output operations but, in order to keep the code maintanable and scalable you should enforce Single Responsibility Principle

There are multiple State types, each with it's own purpose: Listener, Workflow, Filter, Postback, Fallback and Background. All will be covered by this tutorial.

To learn more about States read the docs: States

Message Handler

Each State object has a Message handler to manage the incoming messages, either detecting specific intent or extracting information.

The methods can use simple string functions or NLP services, no restrictions apply.


 * @return bool
public function saysHi(): bool
    return $this->normalizeMessage() == 'hi';

Response Handler

Each State will handle specific business logic which will imply specific responses. This responses are structured into methods that return an instance of \Botomatic\Engine\Facebook\Entities\Response. The response can travel from State to State, you never have to instanciate a new instance but rather access $this->response


 * @param string $name
 * @return \Botomatic\Engine\Facebook\Entities\Response
public function responseDefault(string $name) : Response
    return $this->response->addMessage('hello ' . $name)

A full list of methods can be found here: Responses