@vraksha/bottender-rasa 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +88 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present Yoctol (github.com/Yoctol/bottender)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @vraksha/bottender-rasa
|
|
2
|
+
|
|
3
|
+
[Rasa NLU](https://rasa.com/docs/rasa/nlu/about/) integration for Bottender.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can install it with npm:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @vraksha/bottender-rasa
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
or Yarn:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
yarn add @vraksha/bottender-rasa
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
const { chain } = require('bottender');
|
|
23
|
+
const rasa = require('@vraksha/bottender-rasa');
|
|
24
|
+
|
|
25
|
+
async function SayHello(context) {
|
|
26
|
+
await context.sendText('Hello!');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function Unknown(context) {
|
|
30
|
+
await context.sendText('Sorry, I don’t know what you say.');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const Rasa = rasa({
|
|
34
|
+
origin: 'http://localhost:5005',
|
|
35
|
+
actions: {
|
|
36
|
+
greeting: SayHello,
|
|
37
|
+
},
|
|
38
|
+
confidenceThreshold: 0.7,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
module.exports = async function App() {
|
|
42
|
+
return chain([
|
|
43
|
+
Rasa, //
|
|
44
|
+
Unknown,
|
|
45
|
+
]);
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Reference
|
|
50
|
+
|
|
51
|
+
### origin
|
|
52
|
+
|
|
53
|
+
The origin of the Rasa NLU server.
|
|
54
|
+
|
|
55
|
+
Type: `string`.
|
|
56
|
+
Required.
|
|
57
|
+
|
|
58
|
+
### actions
|
|
59
|
+
|
|
60
|
+
Actions to be executed when the event matches corresponding intent.
|
|
61
|
+
|
|
62
|
+
Type: `Record<string, Action>`.
|
|
63
|
+
Required.
|
|
64
|
+
|
|
65
|
+
### confidenceThreshold
|
|
66
|
+
|
|
67
|
+
Threshold of the answer confidence. The action only be executed when confidence is over this threshold.
|
|
68
|
+
|
|
69
|
+
Type: `number`.
|
|
70
|
+
Required.
|
|
71
|
+
|
|
72
|
+
### emulationMode,
|
|
73
|
+
|
|
74
|
+
The emulation mode to use in the request.
|
|
75
|
+
|
|
76
|
+
Type: `'WIT' | 'LUIS' | 'DIALOGFLOW'`.
|
|
77
|
+
Optional.
|
|
78
|
+
|
|
79
|
+
### jwt
|
|
80
|
+
|
|
81
|
+
The JSON Web Token (JWT) to use in the request.
|
|
82
|
+
|
|
83
|
+
Type: `string`.
|
|
84
|
+
Optional.
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT © [Yoctol](https://github.com/Yoctol/bottender)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Action, Context } from '@vraksha/bottender';
|
|
2
|
+
import { Entity, Intent } from './types';
|
|
3
|
+
declare const _default: ({ origin, actions, confidenceThreshold, emulationMode, jwt, }: {
|
|
4
|
+
origin: string;
|
|
5
|
+
actions: Record<string, Action<Context, {
|
|
6
|
+
intent: Intent;
|
|
7
|
+
entities: Entity[];
|
|
8
|
+
}>>;
|
|
9
|
+
confidenceThreshold: number;
|
|
10
|
+
emulationMode?: "WIT" | "LUIS" | "DIALOGFLOW" | undefined;
|
|
11
|
+
jwt?: string | undefined;
|
|
12
|
+
}) => Action<Context>;
|
|
13
|
+
export = _default;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAa,MAAM,oBAAoB,CAAC;AAGhE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAgB,MAAM,SAAS,CAAC;;YAuB7C,MAAM;aACL,OACP,MAAM,EACN,OACE,OAAO,EACP;QACE,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CACF,CACF;yBACoB,MAAM;;;MAGzB,OAAO,OAAO,CAAC;AArBnB,kBA6DE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
const axios_1 = __importDefault(require("axios"));
|
|
15
|
+
const bottender_1 = require("@vraksha/bottender");
|
|
16
|
+
const lodash_1 = require("lodash");
|
|
17
|
+
module.exports = function rasa({ origin = 'http://localhost:5005', actions, confidenceThreshold, emulationMode, jwt, }) {
|
|
18
|
+
return function Rasa(context, { next }) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
if (!context.event.isText) {
|
|
21
|
+
return next;
|
|
22
|
+
}
|
|
23
|
+
const { data } = yield axios_1.default.post(`${origin}/model/parse`, {
|
|
24
|
+
text: context.event.text,
|
|
25
|
+
message_id: (0, lodash_1.get)(context, 'event.message.id'),
|
|
26
|
+
}, {
|
|
27
|
+
params: {
|
|
28
|
+
emulation_mode: emulationMode,
|
|
29
|
+
},
|
|
30
|
+
headers: jwt ? { Authorization: `bearer ${jwt}` } : undefined,
|
|
31
|
+
});
|
|
32
|
+
const { intent, entities } = data;
|
|
33
|
+
if (intent && intent.confidence > confidenceThreshold) {
|
|
34
|
+
context.setIntent(intent.name);
|
|
35
|
+
context.setAsHandled();
|
|
36
|
+
const TargetAction = actions[intent.name];
|
|
37
|
+
if (TargetAction) {
|
|
38
|
+
return (0, bottender_1.withProps)(TargetAction, { intent, entities });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
context.setAsNotHandled();
|
|
43
|
+
}
|
|
44
|
+
return next;
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,kDAAgE;AAChE,mCAA6B;AAkB7B,iBAAS,SAAS,IAAI,CAAC,EACrB,MAAM,GAAG,uBAAuB,EAChC,OAAO,EACP,mBAAmB,EACnB,aAAa,EACb,GAAG,GAgBJ;IACC,OAAO,SAAe,IAAI,CACxB,OAAgB,EAChB,EAAE,IAAI,EAA8B;;YAEpC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE;gBACzB,OAAO,IAAI,CAAC;aACb;YAGD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,GAAG,MAAM,cAAc,EACvB;gBACE,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI;gBACxB,UAAU,EAAE,IAAA,YAAG,EAAC,OAAO,EAAE,kBAAkB,CAAC;aAC7C,EACD;gBACE,MAAM,EAAE;oBACN,cAAc,EAAE,aAAa;iBAC9B;gBACD,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS;aAC9D,CACF,CAAC;YAEF,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;YAElC,IAAI,MAAM,IAAI,MAAM,CAAC,UAAU,GAAG,mBAAmB,EAAE;gBACrD,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBAC/B,OAAO,CAAC,YAAY,EAAE,CAAC;gBAEvB,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBAC1C,IAAI,YAAY,EAAE;oBAChB,OAAO,IAAA,qBAAS,EAAC,YAAY,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;iBACtD;aACF;iBAAM;gBACL,OAAO,CAAC,eAAe,EAAE,CAAC;aAC3B;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KAAA,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type ParsedResult = {
|
|
2
|
+
entities: Entity[];
|
|
3
|
+
intent: Intent;
|
|
4
|
+
intent_ranking: Intent[];
|
|
5
|
+
text: string;
|
|
6
|
+
};
|
|
7
|
+
export type Intent = {
|
|
8
|
+
name: string;
|
|
9
|
+
confidence: number;
|
|
10
|
+
};
|
|
11
|
+
export type Entity = {
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
value: string;
|
|
15
|
+
entity: string;
|
|
16
|
+
confidence: number;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vraksha/bottender-rasa",
|
|
3
|
+
"version": "1.7.0",
|
|
4
|
+
"description": "Rasa NLU integration for Bottender.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://bottender.js.org/",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/Yoctol/bottender.git"
|
|
10
|
+
},
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"types": "dist/index.d.ts",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@types/lodash": "^4.14.149",
|
|
18
|
+
"axios": "^0.21.4",
|
|
19
|
+
"lodash": "^4.17.15"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@vraksha/bottender": ">= 1.2.0-0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@vraksha/bottender": "1.7.0"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"bot",
|
|
29
|
+
"bottender",
|
|
30
|
+
"chatbot",
|
|
31
|
+
"language",
|
|
32
|
+
"messaging",
|
|
33
|
+
"nlu",
|
|
34
|
+
"rasa",
|
|
35
|
+
"understanding"
|
|
36
|
+
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|