Skip to content

How to start receiving and responding to messages#


Before you begin, you need to install the library and configure the bot; this process is described in detail here: How to import the library and configure your bot.

How to start receiving and responding to messages#

After you have installed the library and configured the bot, you need to create the first scene. To do this, create a class that inherits from Scene and override the handler method of the desired type. Most often you will need processIncomingMessage() which handles webhooks about incoming messages. Come up with a clear name for the class; I recommend marking starting scenes with the postfix StartScene.

The processIncomingMessage() method, like other handlers, returns the updated state of the bot. If the state has not changed, it is enough to return the currentState object.

Link to example:

public class BaseStartScene extends Scene {
     public State processIncomingMessage(MessageWebhook incomingMessage, State currentState) {
         answerWithText(incomingMessage, "Hello!", "message");

         return currentState;

To start the bot, you need to call the bot.startReceivingNotifications(); function. In this example, the bot only has one scene and will only respond to the message.

Link to example:

public class BotStarterClassExample {

     public static void main(String[] args) {
         var context =, args);
         var botFactory = context.getBean(BotFactory.class);

         var bot = botFactory.createBot(
             new HandlerExample(),
             new BaseStartScene());


List of examples#

Description Example link
How to initialize an object
Scene "Hello"
Scene "Echo"
How to receive other types of notifications
How to filter incoming messages
How to handle notification body
How to work with bot state state
Example of a ready-made chat-bot full