Debugger, Logs & JSON

Event Debugger

The Event Debugger provides information on how your bot understood the user's message and why it made specific decisions. It also displays the complete event payload, including NLU metadata, state, and raw responses.

To open or close the Debugger, you can use the keyboard shortcut cmd/ctrl + j. This will toggle the Debugger on and off and allow you to access the information it provides.


Logs

By using logs, you can see what happened step-by-step before an error occurred. This can help you understand what went wrong and how to fix it.

It's important to include enough logging in your bot to ensure that you have enough
information to find and fix issues. By analyzing the Botpress Logs, you can pinpoint
exactly where the problem occurred and take the necessary steps to resolve it.

How to log in Botpress

Logging in Botpress is similar to logging in JavaScript. You can use the console.log() function in the Code Card to print messages to the Botpress Logs. This function takes a string as an argument and prints it to the Botpress Logs.

Logging User Information

If you're interested in understanding what user data is being processed, you might want to log their first name. This could help you trace if the correct user data is being accessed and used in your workflow.

Example use-case: Understanding which user's data is being processed especially if your bot offers personalized experiences.

console.log("User's First Name:", user.firstName);

Logging Workflow Data

You might want to know which phone number is being used in a specific workflow. By logging this, you can ensure that the correct numbers are being pulled from your database or user input.

Example use-case: Debugging workflows that might involve sending SMS messages or making phone calls. Ensuring that the correct phone numbers are used can be critical.

console.log("Workflow Phone Number:", workflow.phoneNumber);

Logging Environment Configurations

If your bot accesses external APIs or databases, the API key or endpoint might change depending on the environment (development, staging, production, etc.). Logging the env variables can help ensure that the bot is using the correct configurations.

Example use-case: Troubleshooting connectivity or access issues with external services. By logging the API key or endpoint, you can ensure you're using the correct configurations and not accidentally hitting a production database during development or vice versa.

console.log("Current API Key:", env.apiKey);

Checking the Botpress Studio Logs

To check the Botpress Studio Logs, open up the bottom panel and click on the Logs tab. This will display all the logs that have been generated by your bot.

📘

Note

The logs are displayed in reverse chronological order, with the most recent log at the top. You can click on a log to expand it and view its details.

Checking the Production Logs

To check the Production Logs (or logs from a deployed bot), go to the admin dashboard -> select your workspace and bot -> click on the Logs tab. This will display all the logs that have been generated by your deployed bot.


State

In a bot conversation, each session has an associated state which is created at the beginning of the conversation just before the Entry Node is processed. The state persists throughout the conversation and is used to keep track of information related to the ongoing interaction with the user.

The state is global to the conversation, which means that if the conversation spans multiple flows, all the flows will share the same state. This allows information to be passed between flows and ensures that the bot has a consistent view of the conversation history.

The state can be used to store variables, such as the user's name, preferences, or history of interactions, that are needed throughout the conversation. It can also be used to keep track of the bot's progress through the conversation, such as which questions have been asked and which tasks have been completed.

By using the state effectively, you can create more personalized and engaging bot experiences for your users.


JSON

This tab displays the raw information that is processed during each conversation exchange in the Botpress Emulator. The information can be accessed through event.property, where "property" refers to one of the properties listed in the table below.

Here is a table that describes each property in detail:

PropertyDescription
TypeA string property that indicates the type of the message, e.g., text, audio, video, etc.
ChannelA string property that specifies the channel or platform through which the message was received. For example, the channel can be an emulator, Facebook Messenger, WhatsApp, etc.
DirectionA string property that specifies the direction of the message, i.e., whether the message is incoming or outgoing.
PayloadA JSON object that encapsulates the message data. The structure of the payload object depends on the type of message.
UserIdA string property that identifies the user who sent the message.
BotIdA string property that identifies the bot or conversational AI system that received the message.
CreatedOnA timestamp that specifies the date and time when the message was received.
ConversationIdA string property that identifies the conversation thread to which the message belongs.
IdA unique identifier for the message.
PreviewA preview or summary of the message.
MessageIdA string property that identifies the ID of the message.
TagsAn object that contains tags associated with the message.
FlagsAn object that contains flags associated with the message.
StateAn object that contains the state of the conversation.
SuggestionsAn array of suggested responses or actions that the bot can take based on the message.
NLUAn object that encapsulates the results of the natural language understanding (NLU) process for the message.
DecisionAn object that encapsulates the decision-making process for the message.