Basics · Context

Edit this page on GitHub

Context

El objeto "context" es un componente clave dentro del marco que brinda a los desarrolladores acceso a información esencial sobre la interacción continua entre el usuario y el bot. Esta información incluye propiedades predeterminadas como ' de '(que representa al remitente) y `cuerpo ' (que contiene el mensaje o la entrada del usuario).

Cuando utilizas el metodo addAnswer and addAction, el objeto context se pasa como primer argumento en las funciones de devolución de llamada. Esto permite a los desarrolladores acceder y manipular las propiedades de los contextos de forma dinámica, lo que permite respuestas y acciones personalizadas basadas en las características específicas de cada interacción del usuario.

  import { addKeyword } from '@builderbot/bot';

  const flowA = addKeyword('register')
    .addAnswer('What is your name?', { capture: true }, async (ctx, { state }) => {
      const responseName = ctx.body
      const nameFrom = ctx.name
      const numberFrom = ctx.from

      console.log(`Other properties:`, ctx)
    })

  export default flowA

Es importante tener en cuenta que las propiedades que siempre tendrá disponibles son from, body, name, pero también tendrá muchas más propiedades diferentes según el provider.


Guides

My first chatbot

Learn how build your first chatbot in few minutes

Read more

Concepts

Understand the essential concepts for building bots

Read more

Add Functions

The key to learning how to write flows is add-functions.

Read more

Plugins

Unlimitate and start implementing the community plugins.

Read more

Resources

Modularize

Learn how to modularise flows so that you can have a more maintainable bot.

Send Message

How to send a message via HTTP to start conversations, you can send multimedia as well.

Dockerizer

A good practice is to dockerise your bots to make them more maintainable and effective.

Events

Learning about events will make us more fluent when creating chatbots.