I have basically two endpoints to interact with my bot: (both is a POST method)
/GetConversation = this one is used to send a message as user
{
“message”: “john doe”,
"sessionID: “”
}
and the other endpoint:
/GetAnswer = this one is used to get the last answer from the queue
{
“sessionId”:
}
I want to know how can I config the botium to be used in my chatbot, I’ve already read all the documentation, but I did not get exactly how can I setup the botium.json, for that.
The Generic HTTP/JSON Connector is the way to go.
botium.json would look somehow like this for the endpoint you described.
- Posting text to the /GetConversation endpoint
- Polling the /GetAnswer endpoint for queue answers
- Extracting the response text with JSONPath
...
"SIMPLEREST_URL": "http://my-url/GetConversation",
"SIMPLEREST_METHOD": "POST",
"SIMPLEREST_BODY_TEMPLATE": {
"message": "{{msg.messageText}}",
"sessionID": "{{botium.conversationId}}"
},
"SIMPLEREST_RESPONSE_JSONPATH": "$.message",
"SIMPLEREST_POLL_URL": "http://my-url/GetAnswer",
"SIMPLEREST_POLL_VERB": "POST",
"SIMPLEREST_POLL_BODY": {
"sessionID": "{{botium.conversationId}}"
},
Thank you very much @Florian
Last question, how can I authenticate storing the conversationID response?
I have the endpoint /Login/ClientLogin, it is also a POST method. This body contain the login/password and returns the sessionID that I need to send on each request above, how can I store that?
This would look like this - note that the response of the initial call to the ClientLogin-endpoint can be used as context-variable in the other calls.
"SIMPLEREST_START_URL": "http://my-url/Login/ClientLogin",
"SIMPLEREST_START_VERB": "POST",
"SIMPLEREST_START_BODY": {
"username": "my-user",
"password": "my-password"
},
...
"SIMPLEREST_URL": "http://my-url/GetConversation",
"SIMPLEREST_METHOD": "POST",
"SIMPLEREST_BODY_TEMPLATE": {
"message": "{{msg.messageText}}",
"sessionID": "{{context.sessionID}}"
},
"SIMPLEREST_RESPONSE_JSONPATH": "$.message",
"SIMPLEREST_POLL_URL": "http://my-url/GetAnswer",
"SIMPLEREST_POLL_VERB": "POST",
"SIMPLEREST_POLL_BODY": {
"sessionID": "{{context.sessionID}}"
},
It is still not working, I guess it is related to getting the sessionID at client login, this is my json:
"PROJECTNAME": "sophie",
"CONTAINERMODE": "simplerest",
"SIMPLEREST_INIT_CONTEXT": { "sessionId": "" },
"SIMPLEREST_CONTEXT_JSONPATH": "$.sessionId",
"SIMPLEREST_PING_URL": "https:///Login/ClientLogin",
"SIMPLEREST_PING_VERB": "POST",
"SIMPLEREST_PING_BODY": {
"login": "oooo",
"password": "ooo",
"authenticated": "ooo",
"tenant": "ooo"
},
"SIMPLEREST_URL": "https://ooo/GetConversation",
"SIMPLEREST_METHOD": "POST",
"SIMPLEREST_BODY_TEMPLATE": {
"userText": "{{msg.messageText}}",
"sessionId": "{{context.sessionId}}"
},
"SIMPLEREST_RESPONSE_JSONPATH": "$.message",
"SIMPLEREST_POLL_URL": "https:///GetAnswer",
"SIMPLEREST_POLL_VERB": "POST",
"SIMPLEREST_POLL_BODY": {
"id": "{{context.sessionId}}"
}
},
"Sources": {},
"Envs": {}
}
This error:
stack": "Error: give me picture/Line 3: error sending to bot - got error response: 401/Unauthorized\r\n########################################\r\ngive me picture/Line 3: error sending to bot - got error response: 401/Unauthorized\r\n------------ TRANSCRIPT ----------------------------
The response from the /Login has no attribute name it is like only:
“6as5c2s448ssczcd238scdxc” <--------
How can I solve, my friend?
you mean, the response is not JSON but plain text ?
I guess so, because the response looks like:
“7554a3c8f2264b3eac00d6112fb2c63c00637623770594129105833443409”
Instead of,
“sessionId”: "“7554a3c8f2264b3eac00d6112fb2c63c00637623770594129105833443409"”
In this case, there is no way around developing a custom hook - the Generic HTTP/JSON connector relies on JSON content as the name implies.
https://wiki.botiumbox.com/how-to-guides/test-strategy-and-test-case-authoring/implementing-token-based-authentication-for-test-cases/
But following this, shall I move ALL the capabilities to the javascript file? Each one of those endpoints?
Or just getting the variable related to the sessionid, I will be able to use this in the botium.json?
Something like:
container.caps.sessionId = body.title
How I would be able to use this sessionId variable at the botium.json? I’m a little bit confused about that.
And if I have to move all to the javascript file, forgetting the botium.json, how can I make the relation between the messages and answers from the endpoint and what botium is watching?
In the Javascript file you should only pre-fill the sessionId capability, everything else stays in the botium.json