There’s no limit imposed by Conversation Builder as to the size of your methods, but Java itself might impose one. If you encounter an error that your method code is too large, split the method into smaller ones.
Things to do
- Catch issues early in bot development by inserting debug statements into the code to verify things work as you expect.
- Use loops wisely. Avoid time-consuming external API calls from within loops, as the call might time out before the loop finishes.
Use try-catch blocks inside interactions that have code with methods that can throw exceptions that need to be caught. Log a custom event to save the error.
- Expect that tokens will expire and implement proper checks for this. It’s common to initialize a token within the bot’s Global Functions and use it in API calls elsewhere within the bot. If the API call fails, fetch the token again within the same global variables.
Take advantage of the Global Helper Functions dialog template and bot template provided by LivePerson. The bot template is for educational purposes, while the dialog template can be imported into your bot to “add in” the global helper functions that are included.
The global helper functions are designed to simplify the use of custom code. They’re recommended and useful for bots that have logic implemented via custom code in interactions or integrations. Use the helper functions in your bot’s global functions to capture needed info and process common methods without having to write botContext methods.
- When setting a bunch of variables in the Conversation Context Service (so you can use them to guide the bot flow), make a single API call submitting an object of key/value pairs. See our example.
- When writing code that transfers to a skill, check for a null value for that skill. This helps to ensure a successful transfer.
- When writing code that “wakes up” an idle bot (for example, with “hi”), take the bot’s configured session length into consideration. If the bot is awakened after the session has expired, there won’t be any available conversational context. So, the flow that follows will not be as desired.
Things to avoid
Handling exceptions and errors
- Catch and handle exceptions and errors gracefully.