Error: CustomQuestionAnswering is not a constructor - integration

I tried this piece of code for connecting my bot to CustomQuestionAnswering but i got the error as : "CustomQuestionAnswering" is not a constructor. Can you please help me out.
const { ActivityHandler, ActivityTypes } = require('botbuilder');
const { CustomQuestionAnswering } = require('botbuilder-ai');
class CustomQABot extends ActivityHandler {
constructor() {
super();
try {
this.qnaMaker = new CustomQuestionAnswering({
knowledgeBaseId: process.env.ProjectName,
endpointKey: process.env.LanguageEndpointKey,
host: process.env.LanguageEndpointHostName
});
} catch (err) {
console.warn(`QnAMaker Exception: ${err} Check your QnAMaker configuration in .env`);
}
}
}
I tried to make connection between my bot and CustomQuestionAnswering feature of Language Studio. But its giving error as "CustomQuestionAnswering is not a constructor". Any input will be of great help.
Thanks
Ansh Agrawal

Related

Get array inside JSON API response

I'm trying to make an application with both front-end and back-end. I have finished both, but now I'm having some trouble trying to connect them. I keep getting this error:
catalog.component.ts:45 ERROR Error: NG0900: Error trying to diff '[object Object]'. Only arrays and iterables are allowed
at DefaultIterableDiffer.diff (core.mjs:28514:19)
First, I'm trying to get the array response, where the products are located:
product.service.ts
public getAll(): Observable<Product[]> {
return this.http.get<Response["response"]>(this.productsUrl);
}
This method receives the following response:
{
"httpCode": 200,
"message": "OK",
"response": [
{
"pieceName": "Mini Figure Trophy",
"pieceImageURL": "https://www.lego.com/cdn/product-assets/element.img.lod5photo.192x192/6335932.jpg",
"piecePrice": 0.3,
"pieceTag": "Bestseller",
},
{
"pieceName": "Animal No. 17 Dog",
"pieceImageURL": "https://www.lego.com/cdn/product-assets/element.img.lod5photo.192x192/6076467.jpg",
"piecePrice": 2.76,
"pieceTag": "Bestseller",
}
]
}
Then, when my catalog page opens, I run these two functions:
catalog.component.ts
ngOnInit(): void {
this.getProducts();
this.searchSubject.subscribe(value => this.searchService.setSearchValue(value));
this.searchService.searchValue$.subscribe(value => {
this.productService.getProductByNameLike(value).subscribe(productsCalled => {
this.products = productsCalled})
})
}
getProducts(): void {
this.productService.getAll().subscribe({ <- Line where the error occurs
next: (productsCalled: Product[]) => {
this.products = productsCalled
this.checkProductsOnCart()
},
error: (err) => console.log(err),
complete: () => console.log("completo")
});
}
But I keep getting the NG0900 error. I believe it might be because I'm not reading the array where the products are.
I have changed the getAll method, as originally it was:
public getAll(): Observable<Product[]> {
return this.http.get<Product[]>(this.productsUrl);
}
I also tried searching for other responses here, but none seem to be applicable to my problem, or maybe I'm just too much of a newbie to see the relation. Does anyone know what am I doing wrong here? Thanks in advance.
Your JSON response is an object.
export interface ProductListResponse {
httpCode: Number;
message: string;
response: Product[];
}
Work with map from rxjs to return the array from the response property.
import { map } from 'rxjs';
public getAll(): Observable<Product[]> {
return this.http.get<ProductListResponse>(this.productsUrl)
.pipe(map((data) => data.response));
}

How to make a new line in Google Data Studio in the exception?

I am writing a connector for Google Data Studio. I want to make a new line in the exception, but it does not work. Here is the code (look getConfig):
function getData(request) {
return {};
}
function isAdminUser() {
return true;
}
function getConfig(params) {
throw("1st line\n2nd line<br>3rd line");
var cc = DataStudioApp.createCommunityConnector();
var config = cc.getConfig();
return config.build();
}
function getAuthType() {
return false;
}
function getSchema(request) {
return {
'schema' :
[
{
name: "Field_1",
dataType: 'STRING',
semantics: {
conceptType: 'DIMENSION'
}
}
]
}
}
And that's what happens (all in one line):
How do I make a new line in the exception?
Formatting the exception text is not supported. If you need additional information about exceptional behavior, Александр Ермолин is correct in suggesting logging. See Apps Script Logging for details on how to add logging to a connector.

How to Debounce with Observer Polymer

I am trying to run getResponse once when a web components finishes loading. However, when I try to run this, the debounce function just acts as an async delay and runs 4 times after 5000 ms.
static get properties() {
return {
procedure: {
type: String,
observer: 'debounce'
}
}
}
debounce() {
this._debouncer = Polymer.Debouncer.debounce(this._debouncer, Polymer.Async.timeOut.after(5000), () => {
this.getResponse();
});
}
getResponse() {
console.log('get resp');
}
What is necessary to get getResponse to run once upon the loading of the element?
Are you sure you want to use a debouncer for that? you could just use the connectedCallBack to get a one Time Event
class DemoElement extends HTMLElement {
constructor() {
super();
this.callStack = 'constructor->';
}
connectedCallback() {
this.callStack += 'connectedCallback';
console.log('rendered');
fetch(this.fakeAjax()).then((response) => {
// can't do real ajax request here so we fake it... normally you would do
// something like this.innerHTML = response.text();
// not that "rendered" get console logged before "fetch done"
this.innerHTML = `
<p>${this.callStack}</p>
<p>${response.statusText}</p>
`;
console.log('fetch done');
}).catch(function(err) {
console.log(err); // Error :(
});
}
fakeAjax() {
return window.URL.createObjectURL(new Blob(['empty']));
};
}
customElements.define('demo-element', DemoElement);
<demo-element></demo-element>
If you really need to use an observer you could also set a flag this.isLoaded in your connectedCallback() and check for that in your observer code.

Node.js ES6 class private storage

I'm using ES6 to build by Node.js app class. I want to create a db class, so I did the following :
"use strict"
var ini = require('node-ini');
var mysql = require('mysql');
let _db = new WeakMap();
// Class de base pour la base de donnée
class Db{
constructor () {
ini.parse('../config/settings.ini', function(err,data){
if(err) {
console.log(err);
return;
} else {
_db.set(this, mysql.createConnection({
host : data.database_MYSQL.host,
user : data.database_MYSQL.username,
password : data.database_MYSQL.password,
database : data.database_MYSQL.schema
}));
}
});
}
}
module.exports = Db;
It's the first I'm trying to store a private variable, and I looked on the web for solutions. I found the Weakmap solution that I tried to implement. But the MySQL connection won't store it with the following source code. I have this output :
_db.set(this, mysql.createConnection({
^
TypeError: Invalid value used as weak map key
at WeakMap.set (native)
at D:\supervision\application\class\db.js:15:21
at D:\supervision\application\node_modules\node-ini\node-ini.js:168:12
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
So how to deal with it ?
EDIT :
Here is how caller know when it's initialised :
var db;
function instantiateDb(callback){
db = new db_connector();
callback(db);
}
instantiateDb(function(db){
db.connectDatabase();
})
this is undefined inside the callback, it is not referring to an instance of Db, hence you get that error. Have a look at How to access the correct `this` inside a callback? for how to solve that.
However, there is a much bigger problem here: You are performing an asynchronous operation inside the the constructor. That means whatever wants to use an instance of Db has no way of knowing when it will be fully initialized.
A better way of solving this is to have a static asynchronous method that returns a new, fully initialized instance of Db:
class Db {
static get() {
return new Promise((resolve, reject) => {
ini.parse('../config/settings.ini', function(err,data){
if (err) {
reject(err);
} else {
resolve(new Db(data));
}
});
});
}
constructor (data) {
_db.set(this, mysql.createConnection({
host : data.database_MYSQL.host,
user : data.database_MYSQL.username,
password : data.database_MYSQL.password,
database : data.database_MYSQL.schema
}));
}
}
Which can then be used as
Db.get().then(db => {
db.connectDatabase();
});

Delete function not working in JSONStore in Mobilefirst Platform

I'm trying to delete a value which is stored in JSONStore. I'm facing this error:
03-26 18:52:10.391: I/chromium(1890): [INFO:CONSOLE(0)] "document.clear() is deprecated. This method doesn't do anything.", source: (0)
and the value is not not deleted.
Here is the code:
function clear() {
var collectionName = 'people';
//Build the query object
var query = {
_id: 3
};
var options = {
exact: true
};
try {
WL.JSONStore.get(collectionName).remove(query, options)
.then(function(res) {
alert("Success" + res);
})
.fail(function(errorObject) {
alert(errorObject.msg);
});
} catch (e) {
_logError("");
}
}
I would really appreciate the help. Thanks.
well, this error occur because you set clear function but moiblefist(worklight) has this type of API clear so i think it is a bug . you should be use aother name which not in moiblefist API method .
or try with latest version in http://www-01.ibm.com/support/docview.wss?uid=swg2C7000003#71