diff --git a/build/coco.js b/build/coco.js deleted file mode 100644 index 7528812..0000000 --- a/build/coco.js +++ /dev/null @@ -1,48 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const uuid = require("uuid/v4"); -const rp = require("request-promise"); -class ComponentSession { - constructor(p) { - this.component_id = ""; - this.session_id = ""; - this.developer_key = ""; - this.component_id = p.component_id; - this.session_id = p.session_id || uuid(); - this.developer_key = p.developer_key || "trial"; - } - reset(session_id = uuid()) { - this.session_id = session_id; - } - call(user_input, context, source_language_code) { - return new Promise((resolve, reject) => { - const payload = {}; - user_input && (payload.user_input = user_input); - context && (payload.context = context); - source_language_code && (payload.source_language_code = source_language_code); - rp({ - method: "POST", - url: `https://marketplace.conversationalcomponents.com/api/exchange/${this.component_id}/${this.session_id}`, - body: JSON.stringify(payload), - headers: { "api-key": this.developer_key } - }, function (error, response, body) { - if (response.statusCode !== 200) { - reject(new Error(response.body)); - } - if (error) { - reject(error); - return; - } - try { - const bodyJson = JSON.parse(body); - resolve(Object.assign(Object.assign({}, bodyJson), { raw_resp: response })); - } - catch (e) { - reject(e); - } - }); - }); - } -} -exports.ComponentSession = ComponentSession; -//# sourceMappingURL=coco.js.map \ No newline at end of file diff --git a/build/coco.js.map b/build/coco.js.map deleted file mode 100644 index 77de3c8..0000000 --- a/build/coco.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"coco.js","sourceRoot":"","sources":["../src/coco.ts"],"names":[],"mappings":";;AAAA,gCAAiC;AACjC,sCAAsC;AAYtC,MAAa,gBAAgB;IAKzB,YAAY,CAAsE;QAJ1E,iBAAY,GAAG,EAAE,CAAC;QAClB,eAAU,GAAG,EAAE,CAAC;QAChB,kBAAa,GAAG,EAAE,CAAC;QAGvB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,IAAI,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,aAAa,G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;iBACtB;YACL,CAAC,CACJ,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA9CD,4CA8CC"} \ No newline at end of file diff --git a/build/module.js b/build/module.js deleted file mode 100644 index a62463c..0000000 --- a/build/module.js +++ /dev/null @@ -1,56 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const uuid = require("uuid/v4"); -const coco_1 = require("./coco"); -/** - * Chats with CoCo - * @arg {CognigyScript} `component` name of the component - * @arg {CognigyScript} `developerKey` optional developer API key - * @arg {Boolean} `stopOnError` Whether to stop on error or continue - * @arg {CognigyScript} `source_language_code` optional language code - */ -async function CoCo(input, args) { - if (!args.component) { - throw new Error("No component provided"); - } - if (!args.developerKey) { - throw new Error("No developerKey provided"); - } - const component = args.component; - const stageId = component; - const text = input.input.text; - if (!text) - throw new Error("No text"); - const store = "coco"; - const rawContext = input.context.getFullContext() || {}; - const context = Object.assign({}, rawContext[store]) || {}; - if (!context.completed) - context.completed = {}; - if (!context.failed) - context.failed = {}; - if (!context.updated_context) - context.updated_context = {}; - const session_id = context.session_id || uuid(); - const conv = new coco_1.ComponentSession({ component_id: component, developer_key: args.developerKey, session_id }); - context.session_id = session_id; - input.actions.addToContext(store, context, "simple"); - const reply = await conv.call(text, context.updated_context); - if (reply instanceof Error) - throw reply; - if (reply.component_done) { - context.session_id = uuid(); - context.completed[stageId] = true; - if (reply.component_failed) { - context.failed[stageId] = true; - } - } - if (!context[stageId]) - context[stageId] = {}; - context[stageId].result = Object.assign(Object.assign({}, reply), { raw_resp: undefined }); - context.updated_context = Object.assign(Object.assign({}, context.updated_context), reply.updated_context); - input.actions.addToContext(store, context, "simple"); - input.actions.output(reply.response, context.result); - return input; -} -module.exports.CoCo = CoCo; -//# sourceMappingURL=module.js.map \ No newline at end of file diff --git a/build/module.js.map b/build/module.js.map deleted file mode 100644 index ad28a89..0000000 --- a/build/module.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"module.js","sourceRoot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C,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAErD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7D,IAAI,KAAK,YAAY,KAAK;QAAE,MAAM,KAAK,CAAC;IAExC,IAAI,KAAK,CAAC,cAAc,EAAE;QACtB,OAAO,CAAC,UAAU,GAAG,IAAI,EAAE,CAAC;QAC5B,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;QAClC,IAAI,KAAK,CAAC,gBAAgB,EAAE;YACxB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;SAClC;KACJ;IACD,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IAC7C,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,mCAAO,KAAK,KAAE,QAAQ,EAAE,SAAS,GAAC,CAAC;IAC1D,OAAO,CAAC,eAAe,mCAAO,OAAO,CAAC,eAAe,GAAK,KAAK,CAAC,eAAe,CAAC,CAAC;IACjF,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACrD,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAErD,OAAO,KAAK,CAAC;AACjB,CAAC;AACD,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index 113dc1c..c8fcb25 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coco", - "version": "1.0.0", + "version": "1.0.3", "description": "Cognigy-CoCo integration", "main": "build/module.js", "scripts": { diff --git a/release/cognigy-coco-module.zip b/release/cognigy-coco-module.zip deleted file mode 100644 index fc95532..0000000 Binary files a/release/cognigy-coco-module.zip and /dev/null differ diff --git a/src/coco.ts b/src/coco.ts index 41d3487..611d55b 100644 --- a/src/coco.ts +++ b/src/coco.ts @@ -35,7 +35,7 @@ export class ComponentSession { rp( { method: "POST", - url: `https://marketplace.conversationalcomponents.com/api/exchange/${this.component_id}/${this.session_id}`, + url: `https://cocohub.ai/api/exchange/${this.component_id}/${this.session_id}`, body: JSON.stringify(payload), headers: {"api-key": this.developer_key} }, diff --git a/src/module.ts b/src/module.ts index 8296925..fe3ced7 100644 --- a/src/module.ts +++ b/src/module.ts @@ -34,7 +34,7 @@ async function CoCo( context.session_id = session_id; input.actions.addToContext(store, context, "simple"); - const reply = await conv.call(text, context.updated_context); + const reply = await conv.call(text, context.updated_context, args.source_language_code); if (reply instanceof Error) throw reply; if (reply.component_done) {