@magmamath/students-features 0.3.1-rc.0 → 0.3.1-rc.1
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/dist/commonjs/features/chatbot/model/DefaultMessageCreator.js +48 -0
- package/dist/commonjs/features/chatbot/model/DefaultMessageCreator.js.map +1 -0
- package/dist/module/features/chatbot/model/DefaultMessageCreator.js +43 -0
- package/dist/module/features/chatbot/model/DefaultMessageCreator.js.map +1 -0
- package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts +21 -0
- package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -0
- package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts +21 -0
- package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/features/chatbot/model/DefaultMessageCreator.ts +57 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DefaultMessagesCreator = void 0;
|
|
7
|
+
var _effector = require("effector");
|
|
8
|
+
class DefaultMessagesCreator {
|
|
9
|
+
languageChanged = (0, _effector.createEvent)();
|
|
10
|
+
list = new Map();
|
|
11
|
+
constructor({
|
|
12
|
+
textGetter
|
|
13
|
+
}) {
|
|
14
|
+
this.getter = textGetter;
|
|
15
|
+
this.languageChanged.watch(() => {
|
|
16
|
+
this.list.forEach((key, chatMessage) => {
|
|
17
|
+
if ('message' in chatMessage) {
|
|
18
|
+
chatMessage.message = this.getter(key);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
chatMessage.text = this.getter(key);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
createMessage(key, {
|
|
26
|
+
isOwn = false
|
|
27
|
+
} = {}) {
|
|
28
|
+
const message = {
|
|
29
|
+
id: this.list.size.toString(),
|
|
30
|
+
message: this.getter(key),
|
|
31
|
+
threadId: '',
|
|
32
|
+
options: [],
|
|
33
|
+
isOwnMessage: isOwn
|
|
34
|
+
};
|
|
35
|
+
this.list.set(message, key);
|
|
36
|
+
return message;
|
|
37
|
+
}
|
|
38
|
+
createOption(key) {
|
|
39
|
+
const option = {
|
|
40
|
+
text: this.getter(key),
|
|
41
|
+
promptKey: ''
|
|
42
|
+
};
|
|
43
|
+
this.list.set(option, key);
|
|
44
|
+
return option;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.DefaultMessagesCreator = DefaultMessagesCreator;
|
|
48
|
+
//# sourceMappingURL=DefaultMessageCreator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_effector","require","DefaultMessagesCreator","languageChanged","createEvent","list","Map","constructor","textGetter","getter","watch","forEach","key","chatMessage","message","text","createMessage","isOwn","id","size","toString","threadId","options","isOwnMessage","set","createOption","option","promptKey","exports"],"sourceRoot":"../../../../../src","sources":["features/chatbot/model/DefaultMessageCreator.ts"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AAeO,MAAMC,sBAAsB,CAAmB;EACpCC,eAAe,GAAG,IAAAC,qBAAW,EAAC,CAAC;EAE9BC,IAAI,GAAG,IAAIC,GAAG,CAA8B,CAAC;EAG9DC,WAAWA,CAAC;IAAEC;EAA0C,CAAC,EAAE;IACzD,IAAI,CAACC,MAAM,GAAGD,UAAU;IAExB,IAAI,CAACL,eAAe,CAACO,KAAK,CAAC,MAAM;MAC/B,IAAI,CAACL,IAAI,CAACM,OAAO,CAAC,CAACC,GAAG,EAAEC,WAAW,KAAK;QACtC,IAAI,SAAS,IAAIA,WAAW,EAAE;UAC5BA,WAAW,CAACC,OAAO,GAAG,IAAI,CAACL,MAAM,CAACG,GAAG,CAAC;UACtC;QACF;QACAC,WAAW,CAACE,IAAI,GAAG,IAAI,CAACN,MAAM,CAACG,GAAG,CAAC;MACrC,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;EAEOI,aAAaA,CAACJ,GAAM,EAAE;IAAEK,KAAK,GAAG;EAA8B,CAAC,GAAG,CAAC,CAAC,EAAE;IAC3E,MAAMH,OAAoB,GAAG;MAC3BI,EAAE,EAAE,IAAI,CAACb,IAAI,CAACc,IAAI,CAACC,QAAQ,CAAC,CAAC;MAC7BN,OAAO,EAAE,IAAI,CAACL,MAAM,CAACG,GAAG,CAAC;MACzBS,QAAQ,EAAE,EAAE;MACZC,OAAO,EAAE,EAAE;MACXC,YAAY,EAAEN;IAChB,CAAC;IACD,IAAI,CAACZ,IAAI,CAACmB,GAAG,CAACV,OAAO,EAAEF,GAAG,CAAC;IAC3B,OAAOE,OAAO;EAChB;EAEOW,YAAYA,CAACb,GAAM,EAAE;IAC1B,MAAMc,MAAkB,GAAG;MACzBX,IAAI,EAAE,IAAI,CAACN,MAAM,CAACG,GAAG,CAAC;MACtBe,SAAS,EAAE;IACb,CAAC;IACD,IAAI,CAACtB,IAAI,CAACmB,GAAG,CAACE,MAAM,EAAEd,GAAG,CAAC;IAC1B,OAAOc,MAAM;EACf;AACF;AAACE,OAAA,CAAA1B,sBAAA,GAAAA,sBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { createEvent } from 'effector';
|
|
4
|
+
export class DefaultMessagesCreator {
|
|
5
|
+
languageChanged = createEvent();
|
|
6
|
+
list = new Map();
|
|
7
|
+
constructor({
|
|
8
|
+
textGetter
|
|
9
|
+
}) {
|
|
10
|
+
this.getter = textGetter;
|
|
11
|
+
this.languageChanged.watch(() => {
|
|
12
|
+
this.list.forEach((key, chatMessage) => {
|
|
13
|
+
if ('message' in chatMessage) {
|
|
14
|
+
chatMessage.message = this.getter(key);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
chatMessage.text = this.getter(key);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
createMessage(key, {
|
|
22
|
+
isOwn = false
|
|
23
|
+
} = {}) {
|
|
24
|
+
const message = {
|
|
25
|
+
id: this.list.size.toString(),
|
|
26
|
+
message: this.getter(key),
|
|
27
|
+
threadId: '',
|
|
28
|
+
options: [],
|
|
29
|
+
isOwnMessage: isOwn
|
|
30
|
+
};
|
|
31
|
+
this.list.set(message, key);
|
|
32
|
+
return message;
|
|
33
|
+
}
|
|
34
|
+
createOption(key) {
|
|
35
|
+
const option = {
|
|
36
|
+
text: this.getter(key),
|
|
37
|
+
promptKey: ''
|
|
38
|
+
};
|
|
39
|
+
this.list.set(option, key);
|
|
40
|
+
return option;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=DefaultMessageCreator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createEvent","DefaultMessagesCreator","languageChanged","list","Map","constructor","textGetter","getter","watch","forEach","key","chatMessage","message","text","createMessage","isOwn","id","size","toString","threadId","options","isOwnMessage","set","createOption","option","promptKey"],"sourceRoot":"../../../../../src","sources":["features/chatbot/model/DefaultMessageCreator.ts"],"mappings":";;AACA,SAASA,WAAW,QAAQ,UAAU;AAetC,OAAO,MAAMC,sBAAsB,CAAmB;EACpCC,eAAe,GAAGF,WAAW,CAAC,CAAC;EAE9BG,IAAI,GAAG,IAAIC,GAAG,CAA8B,CAAC;EAG9DC,WAAWA,CAAC;IAAEC;EAA0C,CAAC,EAAE;IACzD,IAAI,CAACC,MAAM,GAAGD,UAAU;IAExB,IAAI,CAACJ,eAAe,CAACM,KAAK,CAAC,MAAM;MAC/B,IAAI,CAACL,IAAI,CAACM,OAAO,CAAC,CAACC,GAAG,EAAEC,WAAW,KAAK;QACtC,IAAI,SAAS,IAAIA,WAAW,EAAE;UAC5BA,WAAW,CAACC,OAAO,GAAG,IAAI,CAACL,MAAM,CAACG,GAAG,CAAC;UACtC;QACF;QACAC,WAAW,CAACE,IAAI,GAAG,IAAI,CAACN,MAAM,CAACG,GAAG,CAAC;MACrC,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;EAEOI,aAAaA,CAACJ,GAAM,EAAE;IAAEK,KAAK,GAAG;EAA8B,CAAC,GAAG,CAAC,CAAC,EAAE;IAC3E,MAAMH,OAAoB,GAAG;MAC3BI,EAAE,EAAE,IAAI,CAACb,IAAI,CAACc,IAAI,CAACC,QAAQ,CAAC,CAAC;MAC7BN,OAAO,EAAE,IAAI,CAACL,MAAM,CAACG,GAAG,CAAC;MACzBS,QAAQ,EAAE,EAAE;MACZC,OAAO,EAAE,EAAE;MACXC,YAAY,EAAEN;IAChB,CAAC;IACD,IAAI,CAACZ,IAAI,CAACmB,GAAG,CAACV,OAAO,EAAEF,GAAG,CAAC;IAC3B,OAAOE,OAAO;EAChB;EAEOW,YAAYA,CAACb,GAAM,EAAE;IAC1B,MAAMc,MAAkB,GAAG;MACzBX,IAAI,EAAE,IAAI,CAACN,MAAM,CAACG,GAAG,CAAC;MACtBe,SAAS,EAAE;IACb,CAAC;IACD,IAAI,CAACtB,IAAI,CAACmB,GAAG,CAACE,MAAM,EAAEd,GAAG,CAAC;IAC1B,OAAOc,MAAM;EACf;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ChatAnswer, PostMessageResponse } from '../types/api.types';
|
|
2
|
+
type ChatMessage = PostMessageResponse & {
|
|
3
|
+
id: string;
|
|
4
|
+
isOwnMessage: boolean;
|
|
5
|
+
};
|
|
6
|
+
type DefaultMessageSettings = {
|
|
7
|
+
isOwn?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type DefaultMessageCreatorProps<K extends string> = {
|
|
10
|
+
textGetter: (key: K) => string;
|
|
11
|
+
};
|
|
12
|
+
export declare class DefaultMessagesCreator<K extends string> {
|
|
13
|
+
readonly languageChanged: import("effector").EventCallable<void>;
|
|
14
|
+
private readonly list;
|
|
15
|
+
private readonly getter;
|
|
16
|
+
constructor({ textGetter }: DefaultMessageCreatorProps<K>);
|
|
17
|
+
createMessage(key: K, { isOwn }?: DefaultMessageSettings): ChatMessage;
|
|
18
|
+
createOption(key: K): ChatAnswer;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=DefaultMessageCreator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultMessageCreator.d.ts","sourceRoot":"","sources":["../../../../../../src/features/chatbot/model/DefaultMessageCreator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAGpE,KAAK,WAAW,GAAG,mBAAmB,GAAG;IACvC,EAAE,EAAE,MAAM,CAAA;IACV,YAAY,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,KAAK,sBAAsB,GAAG;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,KAAK,0BAA0B,CAAC,CAAC,SAAS,MAAM,IAAI;IAClD,UAAU,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM,CAAA;CAC/B,CAAA;AAED,qBAAa,sBAAsB,CAAC,CAAC,SAAS,MAAM;IAClD,SAAgB,eAAe,yCAAgB;IAE/C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAyC;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAA;gBAEX,EAAE,UAAU,EAAE,EAAE,0BAA0B,CAAC,CAAC,CAAC;IAclD,aAAa,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,KAAa,EAAE,GAAE,sBAA2B;IAYpE,YAAY,CAAC,GAAG,EAAE,CAAC;CAQ3B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ChatAnswer, PostMessageResponse } from '../types/api.types';
|
|
2
|
+
type ChatMessage = PostMessageResponse & {
|
|
3
|
+
id: string;
|
|
4
|
+
isOwnMessage: boolean;
|
|
5
|
+
};
|
|
6
|
+
type DefaultMessageSettings = {
|
|
7
|
+
isOwn?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type DefaultMessageCreatorProps<K extends string> = {
|
|
10
|
+
textGetter: (key: K) => string;
|
|
11
|
+
};
|
|
12
|
+
export declare class DefaultMessagesCreator<K extends string> {
|
|
13
|
+
readonly languageChanged: import("effector").EventCallable<void>;
|
|
14
|
+
private readonly list;
|
|
15
|
+
private readonly getter;
|
|
16
|
+
constructor({ textGetter }: DefaultMessageCreatorProps<K>);
|
|
17
|
+
createMessage(key: K, { isOwn }?: DefaultMessageSettings): ChatMessage;
|
|
18
|
+
createOption(key: K): ChatAnswer;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=DefaultMessageCreator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultMessageCreator.d.ts","sourceRoot":"","sources":["../../../../../../src/features/chatbot/model/DefaultMessageCreator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAGpE,KAAK,WAAW,GAAG,mBAAmB,GAAG;IACvC,EAAE,EAAE,MAAM,CAAA;IACV,YAAY,EAAE,OAAO,CAAA;CACtB,CAAA;AAED,KAAK,sBAAsB,GAAG;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,KAAK,0BAA0B,CAAC,CAAC,SAAS,MAAM,IAAI;IAClD,UAAU,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM,CAAA;CAC/B,CAAA;AAED,qBAAa,sBAAsB,CAAC,CAAC,SAAS,MAAM;IAClD,SAAgB,eAAe,yCAAgB;IAE/C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAyC;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAA;gBAEX,EAAE,UAAU,EAAE,EAAE,0BAA0B,CAAC,CAAC,CAAC;IAclD,aAAa,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,KAAa,EAAE,GAAE,sBAA2B;IAYpE,YAAY,CAAC,GAAG,EAAE,CAAC;CAQ3B"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ChatAnswer, PostMessageResponse } from '../types/api.types'
|
|
2
|
+
import { createEvent } from 'effector'
|
|
3
|
+
|
|
4
|
+
type ChatMessage = PostMessageResponse & {
|
|
5
|
+
id: string
|
|
6
|
+
isOwnMessage: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type DefaultMessageSettings = {
|
|
10
|
+
isOwn?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type DefaultMessageCreatorProps<K extends string> = {
|
|
14
|
+
textGetter: (key: K) => string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class DefaultMessagesCreator<K extends string> {
|
|
18
|
+
public readonly languageChanged = createEvent()
|
|
19
|
+
|
|
20
|
+
private readonly list = new Map<ChatMessage | ChatAnswer, K>()
|
|
21
|
+
private readonly getter
|
|
22
|
+
|
|
23
|
+
constructor({ textGetter }: DefaultMessageCreatorProps<K>) {
|
|
24
|
+
this.getter = textGetter
|
|
25
|
+
|
|
26
|
+
this.languageChanged.watch(() => {
|
|
27
|
+
this.list.forEach((key, chatMessage) => {
|
|
28
|
+
if ('message' in chatMessage) {
|
|
29
|
+
chatMessage.message = this.getter(key)
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
chatMessage.text = this.getter(key)
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public createMessage(key: K, { isOwn = false }: DefaultMessageSettings = {}) {
|
|
38
|
+
const message: ChatMessage = {
|
|
39
|
+
id: this.list.size.toString(),
|
|
40
|
+
message: this.getter(key),
|
|
41
|
+
threadId: '',
|
|
42
|
+
options: [],
|
|
43
|
+
isOwnMessage: isOwn,
|
|
44
|
+
}
|
|
45
|
+
this.list.set(message, key)
|
|
46
|
+
return message
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public createOption(key: K) {
|
|
50
|
+
const option: ChatAnswer = {
|
|
51
|
+
text: this.getter(key),
|
|
52
|
+
promptKey: '',
|
|
53
|
+
}
|
|
54
|
+
this.list.set(option, key)
|
|
55
|
+
return option
|
|
56
|
+
}
|
|
57
|
+
}
|