@vraksha/bottender-luis 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 +132 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +34 -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 +39 -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,132 @@
|
|
|
1
|
+
# @vraksha/bottender-luis
|
|
2
|
+
|
|
3
|
+
[LUIS](https://www.luis.ai/) integration for Bottender.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can install it with npm:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @vraksha/bottender-luis
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
or Yarn:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
yarn add @vraksha/bottender-luis
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
const { chain } = require('bottender');
|
|
23
|
+
const luis = require('@vraksha/bottender-luis');
|
|
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 Luis = luis({
|
|
34
|
+
appId: 'LUIS_APP_ID',
|
|
35
|
+
appKey: 'LUIS_APP_KEY',
|
|
36
|
+
endpoint: 'https://westus.api.cognitive.microsoft.com',
|
|
37
|
+
actions: {
|
|
38
|
+
greeting: SayHello,
|
|
39
|
+
},
|
|
40
|
+
scoreThreshold: 0.7,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
module.exports = async function App() {
|
|
44
|
+
return chain([
|
|
45
|
+
Luis, //
|
|
46
|
+
Unknown,
|
|
47
|
+
]);
|
|
48
|
+
};
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Reference
|
|
52
|
+
|
|
53
|
+
### appId
|
|
54
|
+
|
|
55
|
+
The LUIS application ID (Guid).
|
|
56
|
+
|
|
57
|
+
Type: `string`.
|
|
58
|
+
Required.
|
|
59
|
+
|
|
60
|
+
### appKey
|
|
61
|
+
|
|
62
|
+
The LUIS application key.
|
|
63
|
+
|
|
64
|
+
Type: `string`.
|
|
65
|
+
Required.
|
|
66
|
+
|
|
67
|
+
### endpoint
|
|
68
|
+
|
|
69
|
+
Supported Cognitive Services endpoints (protocol and hostname, for example: https://westus.api.cognitive.microsoft.com).
|
|
70
|
+
|
|
71
|
+
Type: `string`.
|
|
72
|
+
Required.
|
|
73
|
+
|
|
74
|
+
### actions
|
|
75
|
+
|
|
76
|
+
Actions to be executed when the event matches corresponding intent.
|
|
77
|
+
|
|
78
|
+
Type: `Record<string, Action>`.
|
|
79
|
+
Required.
|
|
80
|
+
|
|
81
|
+
### scoreThreshold
|
|
82
|
+
|
|
83
|
+
Threshold of the answer score. The action only be executed when score is over this threshold.
|
|
84
|
+
|
|
85
|
+
Type: `number`.
|
|
86
|
+
Required.
|
|
87
|
+
|
|
88
|
+
### verbose
|
|
89
|
+
|
|
90
|
+
If true, return all intents instead of just the top scoring intent.
|
|
91
|
+
|
|
92
|
+
Type: `boolean`.
|
|
93
|
+
Optional.
|
|
94
|
+
|
|
95
|
+
### timezoneOffset
|
|
96
|
+
|
|
97
|
+
The timezone offset for the location of the request.
|
|
98
|
+
|
|
99
|
+
Type: `number`.
|
|
100
|
+
Optional.
|
|
101
|
+
|
|
102
|
+
### staging
|
|
103
|
+
|
|
104
|
+
Use the staging endpoint slot.
|
|
105
|
+
|
|
106
|
+
Type: `boolean`.
|
|
107
|
+
Optional.
|
|
108
|
+
|
|
109
|
+
### spellCheck
|
|
110
|
+
|
|
111
|
+
Enable spell checking.
|
|
112
|
+
|
|
113
|
+
Type: `boolean`.
|
|
114
|
+
Optional.
|
|
115
|
+
|
|
116
|
+
### bingSpellCheckSubscriptionKey
|
|
117
|
+
|
|
118
|
+
The subscription key to use when enabling Bing spell check.
|
|
119
|
+
|
|
120
|
+
Type: `string`.
|
|
121
|
+
Optional.
|
|
122
|
+
|
|
123
|
+
### log
|
|
124
|
+
|
|
125
|
+
Log query (default is true).
|
|
126
|
+
|
|
127
|
+
Type: `boolean`.
|
|
128
|
+
Optional.
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
MIT © [Yoctol](https://github.com/Yoctol/bottender)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Action, Context } from '@vraksha/bottender';
|
|
2
|
+
import { EntityModel, IntentModel, Sentiment } from './types';
|
|
3
|
+
declare const _default: ({ appId, appKey, endpoint, scoreThreshold, actions, verbose, timezoneOffset, spellCheck, staging, bingSpellCheckSubscriptionKey, log, }: {
|
|
4
|
+
appId: string;
|
|
5
|
+
appKey: string;
|
|
6
|
+
endpoint: string;
|
|
7
|
+
scoreThreshold: number;
|
|
8
|
+
actions: Record<string, Action<Context, {
|
|
9
|
+
topScoringIntent: IntentModel;
|
|
10
|
+
entities: EntityModel[];
|
|
11
|
+
sentimentAnalysis: Sentiment;
|
|
12
|
+
}>>;
|
|
13
|
+
verbose?: boolean | undefined;
|
|
14
|
+
timezoneOffset?: number | undefined;
|
|
15
|
+
spellCheck?: boolean | undefined;
|
|
16
|
+
staging?: boolean | undefined;
|
|
17
|
+
bingSpellCheckSubscriptionKey?: string | undefined;
|
|
18
|
+
log?: boolean | undefined;
|
|
19
|
+
}) => Action<Context>;
|
|
20
|
+
export = _default;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAa,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAc,SAAS,EAAE,MAAM,SAAS,CAAC;;WA+BjE,MAAM;YACL,MAAM;cACJ,MAAM;oBACA,MAAM;aACb,OACP,MAAM,EACN,OACE,OAAO,EACP;QACE,gBAAgB,EAAE,WAAW,CAAC;QAC9B,QAAQ,EAAE,WAAW,EAAE,CAAC;QACxB,iBAAiB,EAAE,SAAS,CAAC;KAC9B,CACF,CACF;;;;;;;MAOC,OAAO,OAAO,CAAC;AAlCnB,kBAoGE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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 invariant_1 = __importDefault(require("invariant"));
|
|
16
|
+
const bottender_1 = require("@vraksha/bottender");
|
|
17
|
+
module.exports = function luis({ appId, appKey, endpoint, scoreThreshold, actions, verbose = true, timezoneOffset, spellCheck, staging, bingSpellCheckSubscriptionKey, log, }) {
|
|
18
|
+
(0, invariant_1.default)(typeof appId === 'string' && appId.length > 0, 'luis: `appId` is a required parameter.');
|
|
19
|
+
(0, invariant_1.default)(typeof appKey === 'string' && appKey.length > 0, 'luis: `appKey` is a required parameter.');
|
|
20
|
+
(0, invariant_1.default)(typeof endpoint === 'string' && endpoint.length > 0, 'luis: `endpoint` is a required parameter.');
|
|
21
|
+
return function Luis(context, { next }) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
if (!context.event.isText) {
|
|
24
|
+
return next;
|
|
25
|
+
}
|
|
26
|
+
const params = {
|
|
27
|
+
timezoneOffset,
|
|
28
|
+
verbose,
|
|
29
|
+
spellCheck,
|
|
30
|
+
staging,
|
|
31
|
+
'bing-spell-check-subscription-key': bingSpellCheckSubscriptionKey,
|
|
32
|
+
log,
|
|
33
|
+
q: context.event.text,
|
|
34
|
+
};
|
|
35
|
+
const { data } = yield axios_1.default.get(`${endpoint}/luis/v2.0/apps/${appId}`, {
|
|
36
|
+
params,
|
|
37
|
+
headers: {
|
|
38
|
+
'Ocp-Apim-Subscription-Key': appKey,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const { topScoringIntent, entities, sentimentAnalysis } = data;
|
|
42
|
+
if (topScoringIntent && topScoringIntent.score > scoreThreshold) {
|
|
43
|
+
context.setIntent(topScoringIntent.intent);
|
|
44
|
+
context.setAsHandled();
|
|
45
|
+
const TargetAction = actions[topScoringIntent.intent];
|
|
46
|
+
if (TargetAction) {
|
|
47
|
+
return (0, bottender_1.withProps)(TargetAction, {
|
|
48
|
+
topScoringIntent,
|
|
49
|
+
entities,
|
|
50
|
+
sentimentAnalysis,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
context.setAsNotHandled();
|
|
56
|
+
}
|
|
57
|
+
return next;
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,0DAAkC;AAClC,kDAAgE;AAoBhE,iBAAS,SAAS,IAAI,CAAC,EACrB,KAAK,EACL,MAAM,EACN,QAAQ,EACR,cAAc,EACd,OAAO,EACP,OAAO,GAAG,IAAI,EACd,cAAc,EACd,UAAU,EACV,OAAO,EACP,6BAA6B,EAC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,qBAAS,EAAC,YAAY,EAAE;wBAC7B,gBAAgB;wBAChB,QAAQ;wBACR,iBAAiB;qBAClB,CAAC,CAAC;iBACJ;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,34 @@
|
|
|
1
|
+
export type LuisResult = {
|
|
2
|
+
alteredQuery: string;
|
|
3
|
+
compositeEntities: CompositeEntityModel[];
|
|
4
|
+
connectedServiceResult: LuisResult;
|
|
5
|
+
entities: EntityModel[];
|
|
6
|
+
intents: IntentModel[];
|
|
7
|
+
query: string;
|
|
8
|
+
sentimentAnalysis: Sentiment;
|
|
9
|
+
topScoringIntent: IntentModel;
|
|
10
|
+
};
|
|
11
|
+
export type CompositeEntityModel = {
|
|
12
|
+
children: CompositeChildModel[];
|
|
13
|
+
parentType: string;
|
|
14
|
+
value: string;
|
|
15
|
+
};
|
|
16
|
+
export type CompositeChildModel = {
|
|
17
|
+
type: string;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
export type IntentModel = {
|
|
21
|
+
intent: string;
|
|
22
|
+
score: number;
|
|
23
|
+
};
|
|
24
|
+
export type EntityModel = {
|
|
25
|
+
endIndex: number;
|
|
26
|
+
entity: string;
|
|
27
|
+
startIndex: number;
|
|
28
|
+
type: string;
|
|
29
|
+
};
|
|
30
|
+
export type Sentiment = {
|
|
31
|
+
label: string;
|
|
32
|
+
score: number;
|
|
33
|
+
};
|
|
34
|
+
//# 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,UAAU,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,oBAAoB,EAAE,CAAC;IAC1C,sBAAsB,EAAE,UAAU,CAAC;IACnC,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,SAAS,CAAC;IAC7B,gBAAgB,EAAE,WAAW,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,mBAAmB,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,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,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vraksha/bottender-luis",
|
|
3
|
+
"version": "1.7.0",
|
|
4
|
+
"description": "LUIS 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
|
+
"axios": "^0.21.4",
|
|
18
|
+
"invariant": "^2.2.4"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@vraksha/bottender": ">= 1.2.0-0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@vraksha/bottender": "1.7.0"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"bot",
|
|
28
|
+
"bottender",
|
|
29
|
+
"chatbot",
|
|
30
|
+
"language",
|
|
31
|
+
"luis",
|
|
32
|
+
"messaging",
|
|
33
|
+
"nlu",
|
|
34
|
+
"understanding"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
}
|
|
39
|
+
}
|