A common requirement for chatbot testing is to implement token-based authentication.
-
A chatbot client knows about the authenticated 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
Configuration > Connector
Settings
-
Enable the Advanced Mode switch
-
Add a new capability named CUSTOMHOOK_ONBUILD
- In the Capability Value field, add your custom JavaScript code to call your API for a
token. In this example we are calling a public dummy API, and we are using one of the
returned JSON fields as
token
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() }) }) }
Note: The dummy token is written to the Botium Capability MYTOKEN - Click SAVE to complete your task.
2. Use the Token in a Test Case
Botium Tools & Settings > Test Sets > Test Set Configuration >
Scripting
.- Add a Convo file in your Test Set.
- Here is the BotiumScript for copy and
paste:
Greet the bot #me /chatid $cap(MYTOKEN) #bot