Use the following built-in functions to log events and print debug messages.
Log custom event
logCustomEvent for tracking specific bot events for the purpose of analytics. This function requires some type of user message and an event name.
The event detail is optional. Keep the event detail short, as it can't be more than 32 kilobytes, i.e., approximately 32,000 characters in length.
When using logCustomEvent, don’t store personally identifiable information (PII).
user_message — the user's message text
event_name - string
event _detail — string; any optional detail
In this example, we set the user message to the current user message and name the event “Invoice API”.
botContext.logCustomEvent(botContext.getCurrentUserMessage(), 'Invoice API', 'API call successful');
See also this step-by-step, example guide on implementing custom event logging.
To view the details of a custom event, in Bot Analytics you must click Download Event Details (not Download) and examine the downloaded CSV file.
Print debug message
printDebugMessage is used to log debug messages to the console. For example, in the code example below, the
response variable stores the most recent message from the consumer, which we print to the console using
Keep in mind that simply printing a debug message might not always reveal an issue. It can be helpful to use quotation marks to clearly indicate the start and the end of the debug message; this lets you see leading/trailing white space, new lines due to \n, and so on.
Logged debug messages are displayed in the bot's logs.
||message (string) — A message to print to the debug logs||None|
// get what the user just said var response = botContext.getCurrentUserMessage(); botContext.printDebugMessage("User said '" + response + "'");