A common requirement for chatbot testing is to implement token-based authentication.
-
A chatbot client knows about the autenticated user - there is a client-based mechanism for user authentication in place (Cookies ? Web-App Login?)
-
For starting a chatbot conversation, the chatbot client has to transmit some kind of user authentication token to the chatbot engine to initialize the user context in the conversation
-
The authentication token is available by calling an API
If your requirements are similar to this, head on - here are the step by step instructions how to
-
Setup Botium to query an API for an authentication token before starting a test session
-
Use this authentication token in the test cases
1. Implement Botium Hook to Retrieve API Token
In Botium, head over to the Chatbot and go to Configuration > Connector Settings.
-
Enable the Advanced Mode switch
-
Add a new capability with name CUSTOMHOOK_ONBUILD and type Javascript Code
-
In the Capability Value field, you can now add your own custom Javascript Code to call your API to retreive token. For this sample, we are calling a public dummy API and we are using one of the returned JSON fields as token (see code below).
-
The dummy token is written to the Botium Capability MYTOKEN

Here is the Javascript code for Copy&Paste:
module.exports = async ({ container, request }) => {
return new Promise((resolve, reject) => {
const requestOptions = {
method: 'get',
uri: 'https://jsonplaceholder.typicode.com/todos/1',
json: true
}
request(requestOptions, (err, response, body) => {
if (err) return reject(err)
container.pluginInstance.caps.MYTOKEN = body.title
resolve()
})
})
}
2. Use the Token in the Test Case
We can use the Botium Scripting Memory to use the dummy token in our convo files. Add a convo file in your Test Set.
Do not forget to enable the Scripting Memory in the Scripting Settings of the Test Set. To enable Scripting Memory, go to Test Sets > Configuration > Scripting.

Here is the BotiumScript for copy and paste:
Greet the bot
#me
/chatid $cap(MYTOKEN)
#bot
We are using the $cap Scripting Memory function to use the capability named MYTOKEN within the convo file.
Comments
0 comments
Please sign in to leave a comment.