...
3. Modify its content in the window and click Save.
Sample
Note that by default Callbacks Code
files provide you with the tips on how to create functions.
...
Reference material
To view the reference material on callbacks, open the help page. It is available on your instance with the following address: https://<yourinstance>.konverso.ai/doc/Responding-with-callback-scripts_500302062.html.
Just substitute <yourinstance>
with the actual name of your host.
Sample
Creating a callback
Here is a sample demonstrating a function that asks a user whether they are satisfied with the support and saves the reply.
What’s next?
Code Block |
---|
from common.Callback import Callback
from utils import logger
log = logger.getPackageLogger('callback')
# Sample callback, can be used in an Intent with a response type "Callback"
# and callback name is my2
#
class HelloWorld(Callback):
_isRealAction = True
def DoAction(self, dialog, sentence):
log.debug("Begin callback my2")
response = dialog.UserAsk("Tell us how you are satisfied with out JSM support?")
dialog.AddKeyword('callback_last_feedback', response.text)
dialog.UserPost("Saved your last feedback:%s" %(response.text))
return "" |
You can copy this code and paste it into one of Callbacks Code files. Make sure to click Save and Apply.
...
Setting an intent’s response
Once you have created a callback, you can use it as an intent’s response. :
1. Go to Content > Intents.
...
5. In the Callback name field, enter the name of your callback. For example, if your custom callback is stored in core/python/callback/my2.py
, specify your callback as my2
.
6. Click Save.
...
...
Testing a callback
Now, when Koji detects a given intent in the chat, it will invoke the defined callback as a response. To test your callback, go to chat and enter the #do <your-callback-name>
command.
...
Debug
See the sample above: the log.debug("Begin callback my2")
string helps you identify your callback performance in the Process log report. To view the debug information on callbacks usage:
1. Go to DevOps > Errors > Debug level to set the required debug level.
2. Select the level, process, and packages, and click Refresh.
3. Go to DevOps > Errors > Process log.
4. Set the required parameters and click Refresh.
...