Fetching responses from SUSI.AI Server for Botbuilder Build Views
In SUSI.AI, we use skill editor for creating and editing public/private skills. The editor we use is Ace editor. The skill is written in a code format documented here. This works fine for a developer but for a user with little experience in coding, this can be confusing. Hence, for providing more clarity as to what the skill does, I built conversation view and tree view along with code view for the skill editor. Conversation view shows the skill in form of actual conversation between the user and the bot while tree views shows the same conversation in form of a tree. Earlier these views were implemented by converting the code view into an object containing user queries and SUSI responses. While this works for simple skills, it obviously won’t work for a complex skill in which the responses are fetched from an API. Hence we needed live responses from SUSI server. This is done similar to how preview works. We pass the whole skill in an instant parameter in the chat.json API along with the user query. This gives us the response from SUSI in form of a JSON. API Call: We send a GET request to the following URL: https://api.susi.ai/susi/chat.json?q=userQuery&instant=wholeSkill This contains two parameters: q: The user query is passed in this parameter. instant: The whole skill code (present in the code view) is passed in this parameter. The response is a JSON providing response from SUSI. Getting user queries: We can not rely on user to provide the user queries in conversation view and tree view because the user has already provided it in the code view. Hence, we fetch the user queries from code view. This is simply done by dissecting the code and putting all the lines which don’t start with ::, !, #, {, } and “ in an array. Then we split the entries of this array wherever a vertical bar (|) is found. This provides us an array containing all the user queries. It’ll be clear from the following function: fetchUserInputs = () => { let code = this.state.code; let userInputs = []; let userQueries = []; var lines = code.split('\n'); for (let i = 0; i < lines.length; i++) { let line = lines[i]; if ( line && !line.startsWith('::') && !line.startsWith('!') && !line.startsWith('#') && !line.startsWith('{') && !line.startsWith('}') && !line.startsWith('"') ) { let user_query = line; while (true) { i++; if (i >= lines.length) { break; } line = lines[i]; if ( line && !line.startsWith('::') && !line.startsWith('!') && !line.startsWith('#') …
