Basics · Context
Edit this page on GitHubContext
The "context" object is a key component within the framework that provides developers with access to essential information about the ongoing interaction between the user and the bot. This information includes default properties like from (representing the sender) and body (containing the message or input from the user).
When utilizing the framework's addAnswer and addAction methods, the context object is passed as the first argument in the callback functions. This allows developers to access and manipulate the context's properties dynamically, enabling tailored responses and actions based on the specifics of each user interaction.
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 flowAIt is important to note that the properties you will always have available are from, body, name but you will also have many more different properties depending on the provider.
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.