From 657e50012843a92139c8c184ec7f2e1caab577cf Mon Sep 17 00:00:00 2001 From: Younes AKHOUAYRI Date: Wed, 14 Oct 2020 18:34:22 +0200 Subject: [PATCH 1/3] Fix: set the storage in the constructor when provided in the configuration --- lib/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/index.js b/lib/index.js index 405ec9c..59bfe8a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -39,6 +39,9 @@ class WatsonMiddleware { if (config.minimum_confidence) { this.minimumConfidence = config.minimum_confidence; } + if(config.storage){ + this.storage = config.storage; + } debug('Creating Assistant object with parameters: ' + JSON.stringify(this.config, null, 2)); this.conversation = new AssistantV1(this.config); From fba25d74e26d038a4606070494820df6f91388e3 Mon Sep 17 00:00:00 2001 From: Younes AKHOUAYRI Date: Wed, 14 Oct 2020 18:34:22 +0200 Subject: [PATCH 2/3] Fix: set the storage in the constructor when provided in the configuration --- lib/.gitkeep | 0 lib/index.d.ts | 2 + lib/index.js | 3 + lib/index.js.map | 2 +- lib/src/index.d.ts | 54 ----- lib/src/index.js | 175 ---------------- lib/src/index.js.map | 1 - lib/src/utils.d.ts | 25 --- lib/src/utils.js | 80 -------- lib/src/utils.js.map | 1 - lib/test/context-store.test.d.ts | 16 -- lib/test/context-store.test.js | 177 ---------------- lib/test/context-store.test.js.map | 1 - .../middleware-delete-user-data.test.d.ts | 16 -- lib/test/middleware-delete-user-data.test.js | 57 ------ .../middleware-delete-user-data.test.js.map | 1 - lib/test/middleware-receive.test.d.ts | 16 -- lib/test/middleware-receive.test.js | 184 ----------------- lib/test/middleware-receive.test.js.map | 1 - lib/test/middleware-send-to-watson.test.d.ts | 16 -- lib/test/middleware-send-to-watson.test.js | 192 ------------------ .../middleware-send-to-watson.test.js.map | 1 - lib/test/post-message.test.d.ts | 16 -- lib/test/post-message.test.js | 122 ----------- lib/test/post-message.test.js.map | 1 - package-lock.json | 9 +- src/index.ts | 4 + 27 files changed, 16 insertions(+), 1157 deletions(-) delete mode 100644 lib/.gitkeep delete mode 100644 lib/src/index.d.ts delete mode 100644 lib/src/index.js delete mode 100644 lib/src/index.js.map delete mode 100644 lib/src/utils.d.ts delete mode 100644 lib/src/utils.js delete mode 100644 lib/src/utils.js.map delete mode 100644 lib/test/context-store.test.d.ts delete mode 100644 lib/test/context-store.test.js delete mode 100644 lib/test/context-store.test.js.map delete mode 100644 lib/test/middleware-delete-user-data.test.d.ts delete mode 100644 lib/test/middleware-delete-user-data.test.js delete mode 100644 lib/test/middleware-delete-user-data.test.js.map delete mode 100644 lib/test/middleware-receive.test.d.ts delete mode 100644 lib/test/middleware-receive.test.js delete mode 100644 lib/test/middleware-receive.test.js.map delete mode 100644 lib/test/middleware-send-to-watson.test.d.ts delete mode 100644 lib/test/middleware-send-to-watson.test.js delete mode 100644 lib/test/middleware-send-to-watson.test.js.map delete mode 100644 lib/test/post-message.test.d.ts delete mode 100644 lib/test/post-message.test.js delete mode 100644 lib/test/post-message.test.js.map diff --git a/lib/.gitkeep b/lib/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/lib/index.d.ts b/lib/index.d.ts index 900f642..96da1d5 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -17,10 +17,12 @@ import Botkit = require('botkit'); import AssistantV1 = require('ibm-watson/assistant/v1'); import { MessageParams, MessageResponse } from 'ibm-watson/assistant/v1'; import { Context } from 'ibm-watson/assistant/v1'; +import { Storage } from 'botbuilder'; import { BotkitMessage } from 'botkit'; export interface WatsonMiddlewareConfig extends AssistantV1.Options { workspace_id: string; minimum_confidence?: number; + storage?: Storage; } /** * @deprecated please use AssistantV1.MessageParams instead diff --git a/lib/index.js b/lib/index.js index 405ec9c..4379229 100644 --- a/lib/index.js +++ b/lib/index.js @@ -39,6 +39,9 @@ class WatsonMiddleware { if (config.minimum_confidence) { this.minimumConfidence = config.minimum_confidence; } + if (config.storage) { + this.storage = config.storage; + } debug('Creating Assistant object with parameters: ' + JSON.stringify(this.config, null, 2)); this.conversation = new AssistantV1(this.config); diff --git a/lib/index.js.map b/lib/index.js.map index 486f897..c608b36 100644 --- a/lib/index.js.map +++ b/lib/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD;;;;;;;;;;;;;;GAcG;;;;;;;;;;;AAEH,8DAA8D;AAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,yBAAyB,CAAC,CAAC;AAE1D,uDAAwD;AAIxD,mCAAkE;AAClE,uCAAwC;AAsBxC,MAAa,gBAAgB;IAQ3B,YAAmB,MAA8B;QAJhC,sBAAiB,GAAW,IAAI,CAAC;QAClD,0FAA0F;QACzE,eAAU,GAAG,CAAC,iBAAiB,EAAE,eAAe,CAAC,CAAC;QAGjE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,MAAM,CAAC,kBAAkB,EAAE;YAC7B,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,kBAAkB,CAAC;SACpD;QAED,KAAK,CACH,6CAA6C;YAC3C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CACvC,CAAC;QACF,IAAI,CAAC,YAAY,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnD,CAAC;IAEM,IAAI,CAAC,QAAkB,EAAE,OAA6B;QAC3D,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE;YACpD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;oBAC1D,IACE,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CA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C5C,MAAM,MAAM,GAAG;gBACb,WAAW,EAAE,UAAU;gBACvB,eAAe,EAAE,IAAI;aACtB,CAAC;YACF,IAAI;gBACF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;gBAChE,KAAK,CAAC,yBAAyB,EAAE,QAAQ,CAAC,CAAC;aAC5C;YAAC,OAAO,GAAG,EAAE;gBACZ,MAAM,IAAI,KAAK,CACb,6CAA6C;oBAC3C,GAAG,CAAC,IAAI;oBACR,aAAa;oBACb,GAAG,CAAC,OAAO,CACd,CAAC;aACH;QACH,CAAC;KAAA;CACF;AAvLD,4CAuLC"} \ No newline at end of file diff --git a/lib/src/index.d.ts b/lib/src/index.d.ts deleted file mode 100644 index 900f642..0000000 --- a/lib/src/index.d.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import Botkit = require('botkit'); -import AssistantV1 = require('ibm-watson/assistant/v1'); -import { MessageParams, MessageResponse } from 'ibm-watson/assistant/v1'; -import { Context } from 'ibm-watson/assistant/v1'; -import { BotkitMessage } from 'botkit'; -export interface WatsonMiddlewareConfig extends AssistantV1.Options { - workspace_id: string; - minimum_confidence?: number; -} -/** - * @deprecated please use AssistantV1.MessageParams instead - */ -export declare type Payload = MessageParams; -export declare type BotkitWatsonMessage = BotkitMessage & { - watsonData?: MessageResponse; - watsonError?: string; -}; -export interface ContextDelta { - [index: string]: any; -} -export declare class WatsonMiddleware { - private readonly config; - private conversation; - private storage; - private readonly minimumConfidence; - private readonly ignoreType; - constructor(config: WatsonMiddlewareConfig); - hear(patterns: string[], message: Botkit.BotkitMessage): boolean; - before(message: Botkit.BotkitMessage, payload: MessageParams): Promise; - after(message: Botkit.BotkitMessage, response: MessageResponse): Promise; - sendToWatson(bot: Botkit.BotWorker, message: Botkit.BotkitMessage, contextDelta: ContextDelta): Promise; - receive(bot: Botkit.BotWorker, message: Botkit.BotkitMessage): Promise; - interpret(bot: Botkit.BotWorker, message: Botkit.BotkitMessage): Promise; - readContext(user: string): Promise; - updateContext(user: string, context: Context): Promise<{ - context: Context; - }>; - deleteUserData(customerId: string): Promise; -} diff --git a/lib/src/index.js b/lib/src/index.js deleted file mode 100644 index 405ec9c..0000000 --- a/lib/src/index.js +++ /dev/null @@ -1,175 +0,0 @@ -"use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -// eslint-disable-next-line @typescript-eslint/no-var-requires -const debug = require('debug')('watson-middleware:index'); -const AssistantV1 = require("ibm-watson/assistant/v1"); -const utils_1 = require("./utils"); -const deepMerge = require("deepmerge"); -class WatsonMiddleware { - constructor(config) { - this.minimumConfidence = 0.75; - // These are initiated by Slack itself and not from the end-user. Won't send these to WCS. - this.ignoreType = ['presence_change', 'reconnect_url']; - this.config = config; - if (config.minimum_confidence) { - this.minimumConfidence = config.minimum_confidence; - } - debug('Creating Assistant object with parameters: ' + - JSON.stringify(this.config, null, 2)); - this.conversation = new AssistantV1(this.config); - } - hear(patterns, message) { - if (message.watsonData && message.watsonData.intents) { - for (let p = 0; p < patterns.length; p++) { - for (let i = 0; i < message.watsonData.intents.length; i++) { - if (message.watsonData.intents[i].intent === patterns[p] && - message.watsonData.intents[i].confidence >= this.minimumConfidence) { - return true; - } - } - } - } - return false; - } - before(message, payload) { - return Promise.resolve(payload); - } - after(message, response) { - return Promise.resolve(response); - } - sendToWatson(bot, message, contextDelta) { - return __awaiter(this, void 0, void 0, function* () { - if ((!message.text && message.type !== 'welcome') || - this.ignoreType.indexOf(message.type) !== -1 || - message.reply_to || - message.bot_id) { - // Ignore messages initiated by Slack. Reply with dummy output object - message.watsonData = { - output: { - text: [], - }, - }; - return; - } - this.storage = bot.controller.storage; - try { - const userContext = yield utils_1.readContext(message.user, this.storage); - const payload = { - // eslint-disable-next-line @typescript-eslint/camelcase - workspace_id: this.config.workspace_id, - }; - if (message.text) { - // text can not contain the following characters: tab, new line, carriage return. - const sanitizedText = message.text.replace(/[\r\n\t]/g, ' '); - payload.input = { - text: sanitizedText, - }; - } - if (userContext) { - payload.context = userContext; - } - if (contextDelta) { - if (!userContext) { - //nothing to merge, this is the first context - payload.context = contextDelta; - } - else { - payload.context = deepMerge(payload.context, contextDelta); - } - } - if (payload.context && - payload.context.workspace_id && - payload.context.workspace_id.length === 36) { - // eslint-disable-next-line @typescript-eslint/camelcase - payload.workspace_id = payload.context.workspace_id; - } - const watsonRequest = yield this.before(message, payload); - let watsonResponse = yield utils_1.postMessage(this.conversation, watsonRequest); - if (typeof watsonResponse.output.error === 'string') { - debug('Error: %s', watsonResponse.output.error); - message.watsonError = watsonResponse.output.error; - } - watsonResponse = yield this.after(message, watsonResponse); - message.watsonData = watsonResponse; - yield utils_1.updateContext(message.user, this.storage, watsonResponse); - } - catch (error) { - message.watsonError = error; - debug('Error: %s', JSON.stringify(error, Object.getOwnPropertyNames(error), 2)); - } - }); - } - receive(bot, message) { - return __awaiter(this, void 0, void 0, function* () { - return this.sendToWatson(bot, message, null); - }); - } - interpret(bot, message) { - return __awaiter(this, void 0, void 0, function* () { - return this.sendToWatson(bot, message, null); - }); - } - readContext(user) { - return __awaiter(this, void 0, void 0, function* () { - if (!this.storage) { - throw new Error('readContext is called before the first this.receive call'); - } - return utils_1.readContext(user, this.storage); - }); - } - updateContext(user, context) { - return __awaiter(this, void 0, void 0, function* () { - if (!this.storage) { - throw new Error('updateContext is called before the first this.receive call'); - } - return utils_1.updateContext(user, this.storage, { - context: context, - }); - }); - } - deleteUserData(customerId) { - return __awaiter(this, void 0, void 0, function* () { - const params = { - customer_id: customerId, - return_response: true, - }; - try { - const response = yield this.conversation.deleteUserData(params); - debug('deleteUserData response', response); - } - catch (err) { - throw new Error('Failed to delete user data, response code: ' + - err.code + - ', message: ' + - err.message); - } - }); - } -} -exports.WatsonMiddleware = WatsonMiddleware; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/src/index.js.map b/lib/src/index.js.map deleted file mode 100644 index a5500fe..0000000 --- a/lib/src/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD;;;;;;;;;;;;;;GAcG;;;;;;;;;;;AAEH,8DAA8D;AAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,yBAAyB,CAAC,CAAC;AAE1D,uDAAwD;AAIxD,mCAAkE;AAClE,uCAAwC;AAsBxC,MAAa,gBAAgB;IAQ3B,YAAmB,MAA8B;QAJhC,sBAAiB,GAAW,IAAI,CAAC;QACl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E7B,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAC/C,CAAC;KAAA;IAEY,WAAW,CAAC,IAAY;;YACnC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;gBACjB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;aACH;YACD,OAAO,mBAAW,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACzC,CAAC;KAAA;IAEY,aAAa,CACxB,IAAY,EACZ,OAAgB;;YAEhB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;gBACjB,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;aACH;YACD,OAAO,qBAAa,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE;gBACvC,OAAO,EAAE,OAAO;aACjB,CAAC,CAAC;QACL,CAAC;KAAA;IAEY,cAAc,CAAC,UAAkB;;YAC5C,MAAM,MAAM,GAAG;gBACb,WAAW,EAAE,UAAU;gBACvB,eAAe,EAAE,IAAI;aACtB,CAAC;YACF,IAAI;gBACF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;gBAChE,KAAK,CAAC,yBAAyB,EAAE,QAAQ,CAAC,CAAC;aAC5C;YAAC,OAAO,GAAG,EAAE;gBACZ,MAAM,IAAI,KAAK,CACb,6CAA6C;oBAC3C,GAAG,CAAC,IAAI;oBACR,aAAa;oBACb,GAAG,CAAC,OAAO,CACd,CAAC;aACH;QACH,CAAC;KAAA;CACF;AApLD,4CAoLC"} \ No newline at end of file diff --git a/lib/src/utils.d.ts b/lib/src/utils.d.ts deleted file mode 100644 index 2e75df6..0000000 --- a/lib/src/utils.d.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { Storage } from 'botbuilder'; -import AssistantV1 = require('ibm-watson/assistant/v1'); -import { Context, MessageParams, MessageResponse } from 'ibm-watson/assistant/v1'; -export declare function readContext(userId: string, storage: Storage): Promise; -export declare function updateContext(userId: string, storage: Storage, watsonResponse: { - context: Context; -}): Promise<{ - context: Context; -}>; -export declare function postMessage(conversation: AssistantV1, payload: MessageParams): Promise; diff --git a/lib/src/utils.js b/lib/src/utils.js deleted file mode 100644 index 46e9a5c..0000000 --- a/lib/src/utils.js +++ /dev/null @@ -1,80 +0,0 @@ -"use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -// eslint-disable-next-line @typescript-eslint/no-var-requires -const debug = require('debug')('watson-middleware:utils'); -const storagePrefix = 'user.'; -function readContext(userId, storage) { - return __awaiter(this, void 0, void 0, function* () { - const itemId = storagePrefix + userId; - try { - const result = yield storage.read([itemId]); - if (typeof result[itemId] !== 'undefined' && result[itemId].context) { - debug('User: %s, Context: %s', userId, JSON.stringify(result[itemId].context, null, 2)); - return result[itemId].context; - } - } - catch (err) { - debug('User: %s, read context error: %s', userId, err); - } - return null; - }); -} -exports.readContext = readContext; -function updateContext(userId, storage, watsonResponse) { - return __awaiter(this, void 0, void 0, function* () { - const itemId = storagePrefix + userId; - let userData = {}; - try { - const result = yield storage.read([itemId]); - if (typeof result[itemId] !== 'undefined') { - debug('User: %s, Data: %s', userId, JSON.stringify(result[itemId], null, 2)); - userData = result[itemId]; - } - } - catch (err) { - debug('User: %s, read context error: %s', userId, err); - } - userData.id = userId; - userData.context = watsonResponse.context; - const changes = {}; - changes[itemId] = userData; - yield storage.write(changes); - return watsonResponse; - }); -} -exports.updateContext = updateContext; -function postMessage(conversation, payload) { - return __awaiter(this, void 0, void 0, function* () { - debug('Assistant Request: %s', JSON.stringify(payload, null, 2)); - const response = yield conversation.message(payload); - debug('Assistant Response: %s', JSON.stringify(response, null, 2)); - return response; - }); -} -exports.postMessage = postMessage; -//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/lib/src/utils.js.map b/lib/src/utils.js.map deleted file mode 100644 index f742cf9..0000000 --- a/lib/src/utils.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD;;;;;;;;;;;;;;GAcG;;;;;;;;;;;AAEH,8DAA8D;AAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,yBAAyB,CAAC,CAAC;AAS1D,MAAM,aAAa,GAAG,OAAO,CAAC;AAE9B,SAAsB,WAAW,CAC/B,MAAc,EACd,OAAgB;;QAEhB,MAAM,MAAM,GAAG,aAAa,GAAG,MAAM,CA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AAC,OAAO,CAAC;QAC1C,MAAM,OAAO,GAAG,EAAE,CAAC;QACnB,OAAO,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC;QAC3B,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAE7B,OAAO,cAAc,CAAC;IACxB,CAAC;CAAA;AA7BD,sCA6BC;AAED,SAAsB,WAAW,CAC/B,YAAyB,EACzB,OAAsB;;QAEtB,KAAK,CAAC,uBAAuB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACjE,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACrD,KAAK,CAAC,wBAAwB,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACnE,OAAO,QAAQ,CAAC;IAClB,CAAC;CAAA;AARD,kCAQC"} \ No newline at end of file diff --git a/lib/test/context-store.test.d.ts b/lib/test/context-store.test.d.ts deleted file mode 100644 index 2b8aa3a..0000000 --- a/lib/test/context-store.test.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export {}; diff --git a/lib/test/context-store.test.js b/lib/test/context-store.test.js deleted file mode 100644 index 9f90784..0000000 --- a/lib/test/context-store.test.js +++ /dev/null @@ -1,177 +0,0 @@ -"use strict"; -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -Object.defineProperty(exports, "__esModule", { value: true }); -const utils_1 = require("../lib/utils"); -const botkit_1 = require("botkit"); -const botbuilder_1 = require("botbuilder"); -const botbuilder_adapter_web_1 = require("botbuilder-adapter-web"); -const sinon = require("sinon"); -const message = { - type: 'message', - channel: 'D2BQEJJ1X', - user: 'U2BLZSKFG', - text: 'Hello there!', - ts: '1475776074.000004', - team: 'T2BM5DPJ6', - incoming_message: null, - reference: null, -}; -const conversation_response = { - intents: [], - entities: [], - input: { - text: 'Hello there!', - }, - output: { - log_messages: [], - text: [ - 'Hi. It looks like a nice drive today. What would you like me to do? ', - ], - nodes_visited: ['node_1_1467221909631'], - }, - context: { - conversation_id: '8a79f4db-382c-4d56-bb88-1b320edf9eae', - system: { - dialog_stack: ['root'], - dialog_turn_counter: 1, - dialog_request_counter: 1, - }, - default_counter: 0, - }, -}; -const adapter = new botbuilder_adapter_web_1.WebAdapter({ noServer: true }); -const controller = new botkit_1.Botkit({ - adapter: adapter, - storage: new botbuilder_1.MemoryStorage(), - disable_webserver: true, -}); -const storage = controller.storage; -test('should read context correctly', function () { - return utils_1.readContext(message.user, storage).then(function (context) { - expect(context).toEqual(null); - }); -}); -test('should suppress storage error', function () { - const storageStub = sinon.stub(storage, 'read').rejects('error message'); - return utils_1.readContext(message.user, storage) - .then(function () { - storageStub.restore(); - }) - .catch(function (err) { - storageStub.restore(); - throw err; - }); -}); -test('should store context of the first response', function () { - const itemId = 'user.' + message.user; - return utils_1.updateContext(message.user, storage, conversation_response) - .then(function () { - return storage.read([itemId]); - }) - .then(function (data) { - expect(data[itemId].context).toEqual(conversation_response.context); - }); -}); -test('should ignore storage error on read when user is not saved yet', function () { - const storageStub1 = sinon - .stub(storage, 'read') - .rejects(new Error('error message')); - const storageStub2 = sinon.stub(storage, 'write').resolves(); - const watsonResponse = { - context: { - a: 1, - }, - }; - return utils_1.updateContext('NEWUSER3', storage, watsonResponse) - .then(function (response) { - expect(response).toEqual(watsonResponse); - storageStub1.restore(); - storageStub2.restore(); - }) - .catch(function () { - storageStub1.restore(); - storageStub2.restore(); - }); -}); -test('should return storage error on write', function () { - const storageStub = sinon.stub(storage, 'write').rejects('error message'); - return utils_1.updateContext(message.user, storage, conversation_response) - .then(function (err) { - expect(err).toEqual('error message'); - storageStub.restore(); - }) - .catch(function () { - storageStub.restore(); - }); -}); -test('should update existing context', function () { - const firstContext = { - a: 1, - b: 2, - }; - const secondContext = { - c: 3, - d: 4, - }; - //first update - return utils_1.updateContext(message.user, storage, { - context: firstContext, - }) - .then(function () { - //second update - return utils_1.updateContext(message.user, storage, { - context: secondContext, - }); - }) - .then(function () { - return storage.read(['user.U2BLZSKFG']); - }) - .then(function (data) { - expect(data['user.U2BLZSKFG'].context).toEqual(secondContext); - }); -}); -test('should preserve other data in storage', function () { - const user = { - id: 'U2BLZSKFX', - profile: { - age: 23, - sex: 'male', - }, - }; - const newContext = { - a: 1, - b: 2, - }; - const itemId = 'user.' + user.id; - const existingData = {}; - existingData[itemId] = user; - return storage - .write(existingData) - .then(function () { - return utils_1.updateContext(user.id, storage, { - context: newContext, - }); - }) - .then(function () { - return storage.read([itemId]); - }) - .then(function (data) { - expect(data[itemId].profile).toEqual(user.profile); - expect(data[itemId].context).toEqual(newContext); - }); -}); -//# sourceMappingURL=context-store.test.js.map \ No newline at end of file diff --git a/lib/test/context-store.test.js.map b/lib/test/context-store.test.js.map deleted file mode 100644 index 8b1da89..0000000 --- a/lib/test/context-store.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"context-store.test.js","sourceRoot":"","sources":["../../test/context-store.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAEH,wCAA0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AO,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/test/middleware-delete-user-data.test.d.ts b/lib/test/middleware-delete-user-data.test.d.ts deleted file mode 100644 index 2b8aa3a..0000000 --- a/lib/test/middleware-delete-user-data.test.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export {}; diff --git a/lib/test/middleware-delete-user-data.test.js b/lib/test/middleware-delete-user-data.test.js deleted file mode 100644 index 9744c40..0000000 --- a/lib/test/middleware-delete-user-data.test.js +++ /dev/null @@ -1,57 +0,0 @@ -"use strict"; -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const index_1 = require("../lib/index"); -const nock = require("nock"); -//Watson Assistant params -const service = { - username: 'batman', - password: 'bruce-wayne', - url: 'http://ibm.com:80', - version: '2018-07-10', -}; -const workspaceId = 'zyxwv-54321'; -const customerId = 'XXXXXX'; -const middleware = new index_1.WatsonMiddleware(Object.assign(Object.assign({}, service), { workspace_id: workspaceId })); -beforeEach(function () { - nock.disableNetConnect(); -}); -afterEach(function () { - nock.cleanAll(); -}); -test('makes delete request', () => __awaiter(void 0, void 0, void 0, function* () { - nock(service.url) - .delete(`/v1/user_data?version=2018-07-10&customer_id=${customerId}`) - .reply(202, ''); - yield middleware.deleteUserData(customerId); -})); -test('throws error on unexpected response code', () => __awaiter(void 0, void 0, void 0, function* () { - nock(service.url) - .delete(`/v1/user_data?version=2018-07-10&customer_id=${customerId}`) - .reply(404, ''); - return yield expect(middleware.deleteUserData(customerId)).rejects.toThrow('Failed to delete user data, response code: 404, message: null'); -})); -//# sourceMappingURL=middleware-delete-user-data.test.js.map \ No newline at end of file diff --git a/lib/test/middleware-delete-user-data.test.js.map b/lib/test/middleware-delete-user-data.test.js.map deleted file mode 100644 index ba4c506..0000000 --- a/lib/test/middleware-delete-user-data.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"middleware-delete-user-data.test.js","sourceRoot":"","sources":["../../test/middleware-delete-user-data.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;AAEH,wCAAgD;AAChD,6BAA8B;AAE9B,yBAAyB;AACzB,MAAM,OAAO,GAAG;IACd,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,aAAa;IACvB,GAAG,EAAE,mBAAmB;IACxB,OAAO,EAAE,YAAY;CACtB,CAAC;AAEF,MAAM,WAAW,GAAG,aAAa,CAAC;AAElC,MAAM,UAAU,GAAG,QAAQ,CAAC;AAE5B,MAAM,UAAU,GAAG,IAAI,wBAAgB,iCAClC,OAAO,KACV,YAAY,EAAE,WAAW,IACzB,CAAC;AAEH,UAAU,CAAC;IACT,IAAI,CAAC,iBAAiB,EAAE,CAAC;AAC3B,CAAC,CAAC,CAAC;AAEH,SAAS,CAAC;IACR,IAAI,CAAC,QAAQ,EAAE,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,sBAAsB,EAAE,GAAS,EAAE;IACtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;SACd,MAAM,CAAC,gDAAgD,UAAU,EAAE,CAAC;SACpE,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAElB,MAAM,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;AAC9C,CAAC,CAAA,CAAC,CAAC;AAEH,IAAI,CAAC,0CAA0C,EAAE,GAAS,EAAE;IAC1D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;SACd,MAAM,CAAC,gDAAgD,UAAU,EAAE,CAAC;SACpE,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAElB,OAAO,MAAM,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACxE,+DAA+D,CAChE,CAAC;AACJ,CAAC,CAAA,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/test/middleware-receive.test.d.ts b/lib/test/middleware-receive.test.d.ts deleted file mode 100644 index 2b8aa3a..0000000 --- a/lib/test/middleware-receive.test.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export {}; diff --git a/lib/test/middleware-receive.test.js b/lib/test/middleware-receive.test.js deleted file mode 100644 index 509ca6a..0000000 --- a/lib/test/middleware-receive.test.js +++ /dev/null @@ -1,184 +0,0 @@ -"use strict"; -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const botkit_1 = require("botkit"); -const botbuilder_1 = require("botbuilder"); -const botbuilder_adapter_web_1 = require("botbuilder-adapter-web"); -const index_1 = require("../lib/index"); -const nock = require("nock"); -//Watson Assistant params -const service = { - username: 'batman', - password: 'bruce-wayne', - url: 'http://ibm.com:80', - version: '2018-07-10', -}; -const workspaceId = 'zyxwv-54321'; -const path = `/v1/workspaces/${workspaceId}/message`; -const pathWithQuery = `${path}?version=${service.version}`; -const message = { - type: 'message', - channel: 'D2BQEJJ1X', - user: 'U2BLZSKFG', - text: 'hi', - ts: '1475776074.000004', - team: 'T2BM5DPJ6', - reference: null, - incoming_message: null, -}; -const adapter = new botbuilder_adapter_web_1.WebAdapter({ noServer: true }); -const controller = new botkit_1.Botkit({ - adapter: adapter, - storage: new botbuilder_1.MemoryStorage(), - disable_webserver: true, -}); -const middleware = new index_1.WatsonMiddleware(Object.assign(Object.assign({}, service), { workspace_id: workspaceId })); -let bot = null; -beforeEach(function (done) { - nock.disableNetConnect(); - controller.spawn({}).then(botWorker => { - bot = botWorker; - done(); - }); -}); -afterEach(function () { - nock.cleanAll(); -}); -test('should make first call to Assistant', () => __awaiter(void 0, void 0, void 0, function* () { - const expectedWatsonData = { - intents: [], - entities: [], - input: { - text: 'hi', - }, - output: { - log_messages: [], - text: ['Hello from Watson Assistant!'], - nodes_visited: ['node_1_1467221909631'], - }, - context: { - conversation_id: '8a79f4db-382c-4d56-bb88-1b320edf9eae', - system: { - dialog_stack: ['root'], - dialog_turn_counter: 1, - dialog_request_counter: 1, - }, - }, - }; - nock(service.url) - .post(pathWithQuery) - .reply(200, expectedWatsonData); - const receivedMessage = Object.assign({}, message); - yield middleware.receive(bot, receivedMessage); - expect(receivedMessage.watsonData).toEqual(expectedWatsonData); -})); -test('should make second call to Assistant', () => __awaiter(void 0, void 0, void 0, function* () { - const receivedMessage = Object.assign(Object.assign({}, message), { text: 'What can you do?' }); - const expectedWatsonData = { - intents: [], - entities: [], - input: { - text: 'What can you do?', - }, - output: { - log_messages: [], - text: ['I can tell you about myself. I have a charming personality!'], - nodes_visited: ['node_3_1467221909631'], - }, - context: { - conversation_id: '8a79f4db-382c-4d56-bb88-1b320edf9eae', - system: { - dialog_stack: ['root'], - dialog_turn_counter: 2, - dialog_request_counter: 2, - }, - }, - }; - nock(service.url) - .post(pathWithQuery) - .reply(200, expectedWatsonData); - yield middleware.receive(bot, receivedMessage); - expect(receivedMessage.watsonData).toEqual(expectedWatsonData); -})); -test('should pass empty welcome message to Assistant', () => __awaiter(void 0, void 0, void 0, function* () { - const expectedWatsonData = { - intents: [], - entities: [], - input: { - text: 'hi', - }, - output: { - log_messages: [], - text: ['Hello from Watson Assistant!'], - nodes_visited: ['node_1_1467221909631'], - }, - context: { - conversation_id: '8a79f4db-382c-4d56-bb88-1b320edf9eae', - system: { - dialog_stack: ['root'], - dialog_turn_counter: 1, - dialog_request_counter: 1, - }, - }, - }; - nock(service.url) - .post(pathWithQuery) - .reply(200, expectedWatsonData); - const welcomeMessage = Object.assign(Object.assign({}, message), { type: 'welcome' }); - yield middleware.receive(bot, welcomeMessage); - expect(welcomeMessage.watsonData).toEqual(expectedWatsonData); -})); -test('should replace not-permitted characters in message text', () => __awaiter(void 0, void 0, void 0, function* () { - // text can not contain the following characters: tab, new line, carriage return. - const receivedMessage = Object.assign(Object.assign({}, message), { text: 'What\tcan\tyou\r\ndo?' }); - const expectedMessage = 'What can you do?'; - const expectedWatsonData = { - intents: [], - entities: [], - input: { - text: expectedMessage, - }, - output: { - log_messages: [], - text: ['I can tell you about myself. I have a charming personality!'], - nodes_visited: ['node_3_1467221909631'], - }, - context: { - conversation_id: '8a79f4db-382c-4d56-bb88-1b320edf9eae', - system: { - dialog_stack: ['root'], - dialog_turn_counter: 2, - dialog_request_counter: 2, - }, - }, - }; - nock(service.url) - .post(pathWithQuery, ({ input }) => input.text === expectedMessage) - .reply(200, expectedWatsonData); - yield middleware.receive(bot, receivedMessage); - expect(receivedMessage.watsonData).toEqual(expectedWatsonData); -})); -//# sourceMappingURL=middleware-receive.test.js.map \ No newline at end of file diff --git a/lib/test/middleware-receive.test.js.map b/lib/test/middleware-receive.test.js.map deleted file mode 100644 index 2e0c3a3..0000000 --- a/lib/test/middleware-receive.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"middleware-receive.test.js","sourceRoot":"","sources":["../../test/middleware-receive.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;AAEH,mCAA+C;AAC/C,2CAA2C;AAC3C,mEAAoD;AACpD,wCAAqE;AACrE,6BAA8B;AAE9B,yBAAyB;AACzB,MAAM,OAAO,GAAG;IACd,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,aAAa;IACvB,GAAG,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EAAE,uBAAuB,GAC9B,CAAC;IACF,MAAM,eAAe,GAAG,mBAAmB,CAAC;IAE5C,MAAM,kBAAkB,GAAG;QACzB,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE;YACL,IAAI,EAAE,eAAe;SACtB;QACD,MAAM,EAAE;YACN,YAAY,EAAE,EAAE;YAChB,IAAI,EAAE,CAAC,6DAA6D,CAAC;YACrE,aAAa,EAAE,CAAC,sBAAsB,CAAC;SACxC;QACD,OAAO,EAAE;YACP,eAAe,EAAE,sCAAsC;YACvD,MAAM,EAAE;gBACN,YAAY,EAAE,CAAC,MAAM,CAAC;gBACtB,mBAAmB,EAAE,CAAC;gBACtB,sBAAsB,EAAE,CAAC;aAC1B;SACF;KACF,CAAC;IAEF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;SACd,IAAI,CAAC,aAAa,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,eAAe,CAAC;SAClE,KAAK,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;IAElC,MAAM,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IAC/C,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;AACjE,CAAC,CAAA,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/test/middleware-send-to-watson.test.d.ts b/lib/test/middleware-send-to-watson.test.d.ts deleted file mode 100644 index 2b8aa3a..0000000 --- a/lib/test/middleware-send-to-watson.test.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export {}; diff --git a/lib/test/middleware-send-to-watson.test.js b/lib/test/middleware-send-to-watson.test.js deleted file mode 100644 index b73fc0b..0000000 --- a/lib/test/middleware-send-to-watson.test.js +++ /dev/null @@ -1,192 +0,0 @@ -"use strict"; -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const botkit_1 = require("botkit"); -const utils_1 = require("../lib/utils"); -const clone_1 = require("clone"); -const botbuilder_1 = require("botbuilder"); -const botbuilder_adapter_web_1 = require("botbuilder-adapter-web"); -const index_1 = require("../lib/index"); -const nock = require("nock"); -//Watson Assistant params -const service = { - username: 'batman', - password: 'bruce-wayne', - url: 'http://ibm.com:80', - version: '2018-07-10', -}; -const workspaceId = 'zyxwv-54321'; -const path = `/v1/workspaces/${workspaceId}/message`; -const pathWithQuery = `${path}?version=${service.version}`; -const message = { - type: 'message', - channel: 'D2BQEJJ1X', - user: 'U2BLZSKFG', - text: 'hi', - ts: '1475776074.000004', - team: 'T2BM5DPJ6', - reference: null, - incoming_message: null, -}; -const adapter = new botbuilder_adapter_web_1.WebAdapter({ noServer: true }); -const controller = new botkit_1.Botkit({ - adapter: adapter, - storage: new botbuilder_1.MemoryStorage(), - disable_webserver: true, -}); -const middleware = new index_1.WatsonMiddleware(Object.assign(Object.assign({}, service), { workspace_id: workspaceId })); -let bot; -beforeEach(function (done) { - nock.disableNetConnect(); - controller.spawn({}).then(botWorker => { - bot = botWorker; - done(); - }); -}); -afterEach(function () { - nock.cleanAll(); -}); -test('should update context if contextDelta is provided', () => __awaiter(void 0, void 0, void 0, function* () { - const storedContext = { - a: 1, - b: 'string', - c: { - d: 2, - e: 3, - f: { - g: 4, - h: 5, - }, - }, - }; - const contextDelta = { - b: null, - j: 'new string', - c: { - f: { - g: 5, - i: 6, - }, - }, - }; - const expectedContextInRequest = { - a: 1, - b: null, - c: { - d: 2, - e: 3, - f: { - g: 5, - h: 5, - i: 6, - }, - }, - j: 'new string', - }; - const expectedContextInResponse = Object.assign(Object.assign({}, clone_1.clonePrototype(expectedContextInRequest)), { conversation_id: '8a79f4db-382c-4d56-bb88-1b320edf9eae', system: { - dialog_stack: ['root'], - dialog_turn_counter: 1, - dialog_request_counter: 1, - } }); - const messageToSend = Object.assign({}, message); - const expectedRequest = { - input: { - text: messageToSend.text, - }, - context: expectedContextInRequest, - }; - const mockedWatsonResponse = { - intents: [], - entities: [], - input: { - text: 'hi', - }, - output: { - log_messages: [], - text: ['Hello from Watson Assistant!'], - nodes_visited: ['node_1_1467221909631'], - }, - context: expectedContextInResponse, - }; - //verify request and return mocked response - nock(service.url) - .post(pathWithQuery, expectedRequest) - .reply(200, mockedWatsonResponse); - yield utils_1.updateContext(messageToSend.user, controller.storage, { - context: storedContext, - }); - yield middleware.sendToWatson(bot, messageToSend, contextDelta); - expect(messageToSend.watsonData.context).toEqual(expectedContextInResponse); -})); -test('should make request to different workspace, if workspace_id is set in context', function () { - return __awaiter(this, void 0, void 0, function* () { - const newWorkspaceId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; - const expectedPath = `/v1/workspaces/${newWorkspaceId}/message`; - const storedContext = { - workspace_id: newWorkspaceId, - }; - const messageToSend = Object.assign({}, message); - const expectedContextInResponse = Object.assign(Object.assign({}, clone_1.clonePrototype(storedContext)), { conversation_id: '8a79f4db-382c-4d56-bb88-1b320edf9eae', system: { - dialog_stack: ['root'], - dialog_turn_counter: 1, - dialog_request_counter: 1, - } }); - const expectedRequest = { - input: { - text: messageToSend.text, - }, - context: storedContext, - }; - const mockedWatsonResponse = { - intents: [], - entities: [], - input: { - text: 'hi', - }, - output: { - log_messages: [], - text: ['Hello from Watson Assistant!'], - nodes_visited: ['node_1_1467221909631'], - }, - context: expectedContextInResponse, - }; - //verify request and return mocked response - nock(service.url) - .post(expectedPath + '?version=' + service.version, expectedRequest) - .reply(200, mockedWatsonResponse); - try { - yield utils_1.updateContext(messageToSend.user, controller.storage, { - context: storedContext, - }); - yield middleware.sendToWatson(bot, messageToSend, {}); - expect(messageToSend.watsonError).toBeUndefined(); - } - catch (err) { - throw err; - } - }); -}); -//# sourceMappingURL=middleware-send-to-watson.test.js.map \ No newline at end of file diff --git a/lib/test/middleware-send-to-watson.test.js.map b/lib/test/middleware-send-to-watson.test.js.map deleted file mode 100644 index ae10a58..0000000 --- a/lib/test/middleware-send-to-watson.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"middleware-send-to-watson.test.js","sourceRoot":"","sources":["../../test/middleware-send-to-watson.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;AAEH,mCAAgC;AAChC,wCAA6C;AAC7C,iCAAuC;AACvC,2CAA2C;AAC3C,mEAAoD;AACpD,wCAAqE;AAErE,6BAA8B;AAE9B,yBAAyB;AACzB,MAAM,OAAO,GAAG;IACd,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,aAAa;IACvB,GAAG,EAAE,mBAAmB;IACxB,O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Aa,EAAE,CAAC,sBAAsB,CAAC;aACxC;YACD,OAAO,EAAE,yBAAyB;SACnC,CAAC;QAEF,2CAA2C;QAC3C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;aACd,IAAI,CAAC,YAAY,GAAG,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC;aACnE,KAAK,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;QAEpC,IAAI;YACF,MAAM,qBAAa,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE;gBAC1D,OAAO,EAAE,aAAa;aACvB,CAAC,CAAC;YACH,MAAM,UAAU,CAAC,YAAY,CAAC,GAAG,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC;YACtD,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,aAAa,EAAE,CAAC;SACnD;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,GAAG,CAAC;SACX;IACH,CAAC;CAAA,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/test/post-message.test.d.ts b/lib/test/post-message.test.d.ts deleted file mode 100644 index 2b8aa3a..0000000 --- a/lib/test/post-message.test.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export {}; diff --git a/lib/test/post-message.test.js b/lib/test/post-message.test.js deleted file mode 100644 index ee953f5..0000000 --- a/lib/test/post-message.test.js +++ /dev/null @@ -1,122 +0,0 @@ -"use strict"; -/** - * Copyright 2016-2019 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const utils = require("../lib/utils"); -const nock = require("nock"); -const AssistantV1 = require("ibm-watson/assistant/v1"); -//Watson Assistant params -const service = { - username: 'batman', - password: 'bruce-wayne', - url: 'http://ibm.com:80', - version: '2018-07-10', -}; -const workspaceId = 'zyxwv-54321'; -const path = `/v1/workspaces/${workspaceId}/message`; -const pathWithQuery = `${path}?version=${service.version}`; -const conversation = new AssistantV1(service); -beforeEach(function () { - nock.disableNetConnect(); -}); -afterEach(function () { - nock.cleanAll(); -}); -it('should initiate a conversation', function () { - const expected = { - intents: [], - entities: [], - input: { - text: 'hi', - }, - output: { - log_messages: [], - text: ['Hello from Watson Assistant!'], - nodes_visited: ['node_1_1467221909631'], - }, - context: { - conversation_id: '8a79f4db-382c-4d56-bb88-1b320edf9eae', - system: { - dialog_stack: ['root'], - dialog_turn_counter: 1, - dialog_request_counter: 1, - }, - }, - }; - nock(service.url) - .post(pathWithQuery) - .reply(200, expected); - return utils - .postMessage(conversation, { - workspace_id: workspaceId, - input: { - text: 'hi', - }, - }) - .then(function (response) { - expect(response).toEqual(expected); - }); -}); -it('should continue a conversation', () => __awaiter(void 0, void 0, void 0, function* () { - const expected = { - intents: [], - entities: [], - input: { - text: 'What can you do?', - }, - output: { - log_messages: [], - text: ['I can tell you about myself. I have a charming personality!'], - nodes_visited: ['node_3_1467221909631'], - }, - context: { - conversation_id: '8a79f4db-382c-4d56-bb88-1b320edf9eae', - system: { - dialog_stack: ['root'], - dialog_turn_counter: 2, - dialog_request_counter: 2, - }, - }, - }; - nock(service.url) - .post(pathWithQuery) - .reply(200, expected); - const response = yield utils.postMessage(conversation, { - workspace_id: workspaceId, - input: { - text: 'What can you do?', - }, - context: { - conversation_id: '8a79f4db-382c-4d56-bb88-1b320edf9eae', - system: { - dialog_stack: ['root'], - dialog_turn_counter: 1, - dialog_request_counter: 1, - }, - }, - }); - expect(response).toEqual(expected); -})); -//# sourceMappingURL=post-message.test.js.map \ No newline at end of file diff --git a/lib/test/post-message.test.js.map b/lib/test/post-message.test.js.map deleted file mode 100644 index c5e8184..0000000 --- a/lib/test/post-message.test.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"post-message.test.js","sourceRoot":"","sources":["../../test/post-message.test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;AAEH,sCAAuC;AACvC,6BAA8B;AAC9B,uDAAwD;AAExD,yBAAyB;AACzB,MAAM,OAAO,GAAG;IACd,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,aAAa;IACvB,GAAG,EAAE,mBAAmB;IACxB,OAAO,EAAE,YAAY;CACtB,CAAC;AACF,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,IAAI,GAAG,kBAAkB,WAAW,UAAU,CAAC;AACrD,MAAM,aAAa,GAAG,GAAG,IAAI,YAAY,OAAO,CAAC,OAAO,EAAE,CAAC;AAC3D,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;AAE9C,UAAU,CAAC;IACT,IAAI,CAAC,iBAAiB,EAAE,CAAC;AAC3B,CAAC,CAAC,CAAC;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AAe,EAAE,sCAAsC;YACvD,MAAM,EAAE;gBACN,YAAY,EAAE,CAAC,MAAM,CAAC;gBACtB,mBAAmB,EAAE,CAAC;gBACtB,sBAAsB,EAAE,CAAC;aAC1B;SACF;KACF,CAAC;IAEF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;SACd,IAAI,CAAC,aAAa,CAAC;SACnB,KAAK,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAExB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,YAAY,EAAE;QACrD,YAAY,EAAE,WAAW;QACzB,KAAK,EAAE;YACL,IAAI,EAAE,kBAAkB;SACzB;QACD,OAAO,EAAE;YACP,eAAe,EAAE,sCAAsC;YACvD,MAAM,EAAE;gBACN,YAAY,EAAE,CAAC,MAAM,CAAC;gBACtB,mBAAmB,EAAE,CAAC;gBACtB,sBAAsB,EAAE,CAAC;aAC1B;SACF;KACF,CAAC,CAAC;IACH,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAA,CAAC,CAAC"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2e23198..b669eda 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1855,7 +1855,8 @@ }, "kind-of": { "version": "6.0.2", - "resolved": "", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", + "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", "dev": true } } @@ -3715,7 +3716,8 @@ }, "kind-of": { "version": "6.0.2", - "resolved": "", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", + "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", "dev": true } } @@ -9272,7 +9274,8 @@ }, "kind-of": { "version": "6.0.2", - "resolved": "", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", + "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", "dev": true } } diff --git a/src/index.ts b/src/index.ts index 51faeab..e484a40 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,6 +29,7 @@ import { BotkitMessage } from 'botkit'; export interface WatsonMiddlewareConfig extends AssistantV1.Options { workspace_id: string; minimum_confidence?: number; + storage?: Storage; } /** @@ -58,6 +59,9 @@ export class WatsonMiddleware { if (config.minimum_confidence) { this.minimumConfidence = config.minimum_confidence; } + if(config.storage){ + this.storage = config.storage; + } debug( 'Creating Assistant object with parameters: ' + From 9948c3dd7c6507c14d8eb7c304971a7a183e8b49 Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Wed, 11 Nov 2020 18:36:00 +0200 Subject: [PATCH 3/3] Fix formatting --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e484a40..854bfb2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,7 +59,7 @@ export class WatsonMiddleware { if (config.minimum_confidence) { this.minimumConfidence = config.minimum_confidence; } - if(config.storage){ + if (config.storage){ this.storage = config.storage; }