kozz-module-maker 0.1.1 → 0.1.3
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/Instance/Basic/index.d.ts +40 -0
- package/dist/Instance/Basic/index.js +43 -0
- package/dist/Instance/Basic/index.js.map +1 -0
- package/dist/Instance/BasicController/index.d.ts +40 -0
- package/dist/Instance/BasicController/index.js +43 -0
- package/dist/Instance/BasicController/index.js.map +1 -0
- package/dist/Instance/CommandHandler/index.d.ts +20 -0
- package/dist/Instance/CommandHandler/index.js +26 -0
- package/dist/Instance/CommandHandler/index.js.map +1 -0
- package/dist/Instance/Common/ResourceMap/index.d.ts +12 -0
- package/dist/Instance/Common/ResourceMap/index.js +19 -0
- package/dist/Instance/Common/ResourceMap/index.js.map +1 -0
- package/dist/Instance/Common/UseFns/index.d.ts +10 -0
- package/dist/Instance/Common/UseFns/index.js +16 -0
- package/dist/Instance/Common/UseFns/index.js.map +1 -0
- package/dist/Instance/Common/index.js +10 -0
- package/dist/Instance/Common/index.js.map +1 -0
- package/dist/Instance/Common/onEvent/index.d.ts +8 -0
- package/dist/Instance/Common/onEvent/index.js +87 -0
- package/dist/Instance/Common/onEvent/index.js.map +1 -0
- package/dist/Instance/GeneralHandler/index.d.ts +19 -0
- package/dist/Instance/GeneralHandler/index.js +49 -0
- package/dist/Instance/GeneralHandler/index.js.map +1 -0
- package/dist/Instance/GeneralModule/index.d.ts +53 -0
- package/dist/Instance/GeneralModule/index.js +55 -0
- package/dist/Instance/GeneralModule/index.js.map +1 -0
- package/dist/Instance/Handler/index.d.ts +23 -0
- package/dist/Instance/Handler/index.js +26 -0
- package/dist/Instance/Handler/index.js.map +1 -0
- package/dist/Instance/Proxy/index.d.ts +22 -0
- package/dist/Instance/Proxy/index.js +36 -0
- package/dist/Instance/Proxy/index.js.map +1 -0
- package/dist/Instance/index.d.ts +14 -0
- package/dist/Instance/index.js +20 -0
- package/dist/Instance/index.js.map +1 -0
- package/dist/Message/FromTemplate/index.d.ts +33 -0
- package/dist/Message/FromTemplate/index.js +62 -0
- package/dist/Message/FromTemplate/index.js.map +1 -0
- package/dist/Message/PayloadCreation/Media.d.ts +7 -0
- package/dist/Message/PayloadCreation/Media.js +44 -0
- package/dist/Message/PayloadCreation/Media.js.map +1 -0
- package/dist/Message/PayloadCreation/React.d.ts +3 -0
- package/dist/Message/PayloadCreation/React.js +13 -0
- package/dist/Message/PayloadCreation/React.js.map +1 -0
- package/dist/Message/PayloadCreation/Reply.d.ts +5 -0
- package/dist/Message/PayloadCreation/Reply.js +47 -0
- package/dist/Message/PayloadCreation/Reply.js.map +1 -0
- package/dist/Message/PayloadCreation/ReplyWithSticker.d.ts +0 -0
- package/dist/Message/PayloadCreation/ReplyWithSticker.js +1 -0
- package/dist/Message/PayloadCreation/ReplyWithText.d.ts +2 -0
- package/dist/Message/PayloadCreation/ReplyWithText.js +15 -0
- package/dist/Message/PayloadCreation/index.js +18 -0
- package/dist/Message/PayloadCreation/index.js.map +1 -0
- package/dist/Message/PayloadCreation/sendMessage.d.ts +2 -0
- package/dist/Message/PayloadCreation/sendMessage.js +24 -0
- package/dist/Message/PayloadCreation/sendMessage.js.map +1 -0
- package/dist/Message/ProxiedMessage/index.d.ts +42 -0
- package/dist/Message/ProxiedMessage/index.js +15 -0
- package/dist/Message/ProxiedMessage/index.js.map +1 -0
- package/dist/Message/RoutineCreation/AskResource/AskResourceApi/index.d.ts +14 -0
- package/dist/Message/RoutineCreation/AskResource/AskResourceApi/index.js +28 -0
- package/dist/Message/RoutineCreation/AskResource/AskResourceApi/index.js.map +1 -0
- package/dist/Message/RoutineCreation/AskResource/index.d.ts +16 -0
- package/dist/Message/RoutineCreation/AskResource/index.js +60 -0
- package/dist/Message/RoutineCreation/AskResource/index.js.map +1 -0
- package/dist/Message/RoutineCreation/Reply/WithMedia.d.ts +11 -0
- package/dist/Message/RoutineCreation/Reply/WithMedia.js +34 -0
- package/dist/Message/RoutineCreation/Reply/WithMedia.js.map +1 -0
- package/dist/Message/RoutineCreation/Reply/WithSticke.d.ts +3 -0
- package/dist/Message/RoutineCreation/Reply/WithSticke.js +9 -0
- package/dist/Message/RoutineCreation/Reply/WithSticke.js.map +1 -0
- package/dist/Message/RoutineCreation/Reply/WithSticker.d.ts +3 -0
- package/dist/Message/RoutineCreation/Reply/WithSticker.js +9 -0
- package/dist/Message/RoutineCreation/Reply/WithSticker.js.map +1 -0
- package/dist/Message/RoutineCreation/Reply/WithTemplate.d.ts +3 -0
- package/dist/Message/RoutineCreation/Reply/WithTemplate.js +20 -0
- package/dist/Message/RoutineCreation/Reply/WithTemplate.js.map +1 -0
- package/dist/Message/RoutineCreation/Reply/index.js +10 -0
- package/dist/Message/RoutineCreation/Reply/index.js.map +1 -0
- package/dist/Message/RoutineCreation/SendMessage/index.d.ts +10 -0
- package/dist/Message/RoutineCreation/SendMessage/index.js +25 -0
- package/dist/Message/RoutineCreation/SendMessage/index.js.map +1 -0
- package/dist/Message/RoutineCreation/reply.d.ts +15 -0
- package/dist/Message/RoutineCreation/reply.js +18 -0
- package/dist/Message/RoutineCreation/reply.js.map +1 -0
- package/dist/Message/index.d.ts +42 -0
- package/dist/Message/index.js +46 -0
- package/dist/Message/index.js.map +1 -0
- package/dist/Message/kozz-md.parser/index.d.ts +41 -0
- package/dist/Message/kozz-md.parser/index.js +122 -0
- package/dist/Message/kozz-md.parser/index.js.map +1 -0
- package/dist/Message/zap-md.parser/index.d.ts +1 -0
- package/dist/Message/zap-md.parser/index.js +2 -0
- package/dist/Schema/index.d.ts +37 -0
- package/dist/Schema/index.js +21 -0
- package/dist/Schema/index.js.map +1 -0
- package/dist/Socket/Events/Command.d.ts +3 -0
- package/dist/Socket/Events/Command.js +19 -0
- package/dist/Socket/Events/Command.js.map +1 -0
- package/dist/Socket/Events/Emit/ForwardEvent.d.ts +6 -0
- package/dist/Socket/Events/Emit/ForwardEvent.js +21 -0
- package/dist/Socket/Events/Emit/ForwardEvent.js.map +1 -0
- package/dist/Socket/Events/Emit/Introduction.d.ts +10 -0
- package/dist/Socket/Events/Emit/Introduction.js +21 -0
- package/dist/Socket/Events/Emit/Introduction.js.map +1 -0
- package/dist/Socket/Events/Emit/ProxyRequest.d.ts +0 -0
- package/dist/Socket/Events/Emit/ProxyRequest.js +2 -0
- package/dist/Socket/Events/Emit/ProxyRequest.js.map +1 -0
- package/dist/Socket/Events/Emit/RequestProxy.d.ts +18 -0
- package/dist/Socket/Events/Emit/RequestProxy.js +22 -0
- package/dist/Socket/Events/Emit/RequestProxy.js.map +1 -0
- package/dist/Socket/Events/Emit/RevokeProxy.d.ts +8 -0
- package/dist/Socket/Events/Emit/RevokeProxy.js +16 -0
- package/dist/Socket/Events/Emit/RevokeProxy.js.map +1 -0
- package/dist/Socket/Events/Handle/AskResource.d.ts +8 -0
- package/dist/Socket/Events/Handle/AskResource.js +36 -0
- package/dist/Socket/Events/Handle/AskResource.js.map +1 -0
- package/dist/Socket/Events/Handle/Command.d.ts +14 -0
- package/dist/Socket/Events/Handle/Command.js +48 -0
- package/dist/Socket/Events/Handle/Command.js.map +1 -0
- package/dist/Socket/Events/Handle/ProxiedMessage.d.ts +10 -0
- package/dist/Socket/Events/Handle/ProxiedMessage.js +18 -0
- package/dist/Socket/Events/Handle/ProxiedMessage.js.map +1 -0
- package/dist/Socket/Events/Introduction.d.ts +3 -0
- package/dist/Socket/Events/Introduction.js +15 -0
- package/dist/Socket/Events/Introduction.js.map +1 -0
- package/dist/Socket/Events/ProxiedMessage.d.ts +2 -0
- package/dist/Socket/Events/ProxiedMessage.js +10 -0
- package/dist/Socket/Events/ProxiedMessage.js.map +1 -0
- package/dist/Socket/Messages/Command.d.ts +2 -0
- package/dist/Socket/Messages/Command.js +6 -0
- package/dist/Socket/Messages/Command.js.map +1 -0
- package/dist/Socket/Messages/Introduction.d.ts +3 -0
- package/dist/Socket/Messages/Introduction.js +15 -0
- package/dist/Socket/Messages/Introduction.js.map +1 -0
- package/dist/Socket/index.d.ts +6 -0
- package/dist/Socket/index.js +19 -0
- package/dist/Socket/index.js.map +1 -0
- package/dist/Validator/index.d.ts +16 -0
- package/dist/Validator/index.js +55 -0
- package/dist/Validator/index.js.map +1 -0
- package/dist/debugIndex.d.ts +1 -0
- package/dist/debugIndex.js +21 -0
- package/dist/debugIndex.js.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/util/index.d.ts +25 -0
- package/dist/util/index.js +81 -0
- package/dist/util/index.js.map +1 -0
- package/dist/util.d.ts +8 -0
- package/dist/util.js +36 -0
- package/dist/util.js.map +1 -0
- package/package.json +1 -1
- package/src/Instance/Common/ResourceMap/index.ts +0 -26
- package/src/Instance/Common/UseFns/index.ts +0 -22
- package/src/Instance/Common/onEvent/index.ts +0 -105
- package/src/Instance/GeneralModule/index.ts +0 -98
- package/src/Message/FromTemplate/index.ts +0 -74
- package/src/Message/PayloadCreation/Media.ts +0 -62
- package/src/Message/PayloadCreation/React.ts +0 -16
- package/src/Message/PayloadCreation/Reply.ts +0 -63
- package/src/Message/PayloadCreation/sendMessage.ts +0 -27
- package/src/Message/ProxiedMessage/index.ts +0 -27
- package/src/Message/RoutineCreation/AskResource/AskResourceApi/index.ts +0 -43
- package/src/Message/RoutineCreation/AskResource/index.ts +0 -85
- package/src/Message/RoutineCreation/Reply/WithMedia.ts +0 -63
- package/src/Message/RoutineCreation/Reply/WithSticker.ts +0 -9
- package/src/Message/RoutineCreation/Reply/WithTemplate.ts +0 -28
- package/src/Message/RoutineCreation/SendMessage/index.ts +0 -64
- package/src/Message/RoutineCreation/reply.ts +0 -23
- package/src/Message/index.ts +0 -44
- package/src/Message/kozz-md.parser/index.ts +0 -138
- package/src/Schema/index.ts +0 -102
- package/src/Socket/Events/Emit/ForwardEvent.ts +0 -22
- package/src/Socket/Events/Emit/Introduction.ts +0 -28
- package/src/Socket/Events/Emit/RequestProxy.ts +0 -38
- package/src/Socket/Events/Emit/RevokeProxy.ts +0 -15
- package/src/Socket/Events/Handle/AskResource.ts +0 -37
- package/src/Socket/Events/Handle/Command.ts +0 -68
- package/src/Socket/Events/Handle/ProxiedMessage.ts +0 -28
- package/src/Socket/index.ts +0 -40
- package/src/Validator/index.ts +0 -81
- package/src/messages.kozz.md +0 -52
- package/src/util/index.ts +0 -89
- /package/{src/Instance/Common/index.ts → dist/Instance/Common/index.d.ts} +0 -0
- /package/{src/Message/PayloadCreation/index.ts → dist/Message/PayloadCreation/index.d.ts} +0 -0
- /package/{src/Message/RoutineCreation/Reply/index.ts → dist/Message/RoutineCreation/Reply/index.d.ts} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Socket } from 'socket.io-client';
|
|
2
|
-
import { AskResourcePayload, ProvideResourcePayload } from 'kozz-types';
|
|
3
|
-
|
|
4
|
-
type RequestData = {
|
|
5
|
-
[key in keyof AskResourcePayload]: key extends 'request'
|
|
6
|
-
? Omit<AskResourcePayload[key], 'id'>
|
|
7
|
-
: AskResourcePayload[key];
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Promisified interface for askin resource to other entities connected to the
|
|
12
|
-
* gateway
|
|
13
|
-
* @param socket
|
|
14
|
-
* @param requestData
|
|
15
|
-
* @returns {Promise<ProvideResourcePayload>}
|
|
16
|
-
*/
|
|
17
|
-
export const ask = async (
|
|
18
|
-
socket: Socket,
|
|
19
|
-
requestData: RequestData
|
|
20
|
-
): Promise<ProvideResourcePayload> => {
|
|
21
|
-
const requestId: `${string}/${number}` = `${requestData.responder.id}/${
|
|
22
|
-
requestData.timestamp * 100 + Math.random() * 100
|
|
23
|
-
}`;
|
|
24
|
-
|
|
25
|
-
const requestPayload: AskResourcePayload = {
|
|
26
|
-
...requestData,
|
|
27
|
-
request: {
|
|
28
|
-
...requestData.request,
|
|
29
|
-
id: requestId,
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
socket.emit('ask_resource', requestPayload);
|
|
34
|
-
|
|
35
|
-
return new Promise(resolve => {
|
|
36
|
-
socket.once(
|
|
37
|
-
`reply_resource/${requestId}`,
|
|
38
|
-
(payload: ProvideResourcePayload) => {
|
|
39
|
-
resolve(payload);
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
};
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { AskResourcePayload } from 'kozz-types/dist';
|
|
2
|
-
import { Socket } from 'socket.io-client';
|
|
3
|
-
import { ask as askResourceFn } from './AskResourceApi';
|
|
4
|
-
|
|
5
|
-
type RequestResourceArgs = {
|
|
6
|
-
requester: AskResourcePayload['requester'];
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
type AskResourceArgs = {
|
|
10
|
-
resource: Omit<AskResourcePayload['request'], 'id'>;
|
|
11
|
-
responder: AskResourcePayload['responder'];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const createAskResource = (
|
|
15
|
-
socket: Socket,
|
|
16
|
-
args: RequestResourceArgs
|
|
17
|
-
) => {
|
|
18
|
-
const ask = async (askArgs: AskResourceArgs) => {
|
|
19
|
-
const response = await askResourceFn(socket, {
|
|
20
|
-
request: askArgs.resource,
|
|
21
|
-
responder: askArgs.responder,
|
|
22
|
-
requester: args.requester,
|
|
23
|
-
timestamp: new Date().getTime(),
|
|
24
|
-
});
|
|
25
|
-
return response;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
ask.boundary = (
|
|
29
|
-
boundaryId: string,
|
|
30
|
-
resourceName: string,
|
|
31
|
-
requestArgs: AskResourceArgs['resource']['data'] = {}
|
|
32
|
-
) => {
|
|
33
|
-
return askResourceFn(socket, {
|
|
34
|
-
request: {
|
|
35
|
-
resource: resourceName,
|
|
36
|
-
data: requestArgs,
|
|
37
|
-
},
|
|
38
|
-
requester: args.requester,
|
|
39
|
-
timestamp: new Date().getTime(),
|
|
40
|
-
responder: {
|
|
41
|
-
id: boundaryId,
|
|
42
|
-
type: 'Boundary',
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
ask.handler = (
|
|
48
|
-
handlerId: string,
|
|
49
|
-
resourceName: string,
|
|
50
|
-
requestArgs: AskResourceArgs['resource']['data'] = {}
|
|
51
|
-
) => {
|
|
52
|
-
return askResourceFn(socket, {
|
|
53
|
-
request: {
|
|
54
|
-
resource: resourceName,
|
|
55
|
-
data: requestArgs,
|
|
56
|
-
},
|
|
57
|
-
requester: args.requester,
|
|
58
|
-
timestamp: new Date().getTime(),
|
|
59
|
-
responder: {
|
|
60
|
-
id: handlerId,
|
|
61
|
-
type: 'Handler',
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
ask.gateway = (
|
|
67
|
-
resourceName: string,
|
|
68
|
-
requestArgs: AskResourceArgs['resource']['data'] = {}
|
|
69
|
-
) => {
|
|
70
|
-
return askResourceFn(socket, {
|
|
71
|
-
request: {
|
|
72
|
-
resource: resourceName,
|
|
73
|
-
data: requestArgs,
|
|
74
|
-
},
|
|
75
|
-
requester: args.requester,
|
|
76
|
-
timestamp: new Date().getTime(),
|
|
77
|
-
responder: {
|
|
78
|
-
id: 'Gateway',
|
|
79
|
-
type: 'Gateway',
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
return ask;
|
|
85
|
-
};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Command, Media, MessageReceivedByGateway } from 'kozz-types/dist';
|
|
2
|
-
import { Socket } from 'socket.io-client';
|
|
3
|
-
import { replyWithMedia } from '../../../Message/PayloadCreation';
|
|
4
|
-
import {
|
|
5
|
-
MimeType,
|
|
6
|
-
loadMediaFromPath,
|
|
7
|
-
createMediaFromBuffer,
|
|
8
|
-
createMediaFromB64,
|
|
9
|
-
createMediaFromUrl,
|
|
10
|
-
} from '../../../Message/PayloadCreation/Media';
|
|
11
|
-
|
|
12
|
-
export const withMedia = (
|
|
13
|
-
socket: Socket,
|
|
14
|
-
messagePayload: MessageReceivedByGateway
|
|
15
|
-
) => {
|
|
16
|
-
/**
|
|
17
|
-
* Replies with a media
|
|
18
|
-
* @param {Media} media
|
|
19
|
-
* @param {string} caption
|
|
20
|
-
*/
|
|
21
|
-
const replyMedia = (media: Media, caption?: string) => {
|
|
22
|
-
socket.emit(
|
|
23
|
-
'reply_with_media',
|
|
24
|
-
replyWithMedia(messagePayload, media, caption)
|
|
25
|
-
);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
replyMedia.fromPath = async (
|
|
29
|
-
path: string,
|
|
30
|
-
mimeType: MimeType,
|
|
31
|
-
caption?: string
|
|
32
|
-
) => {
|
|
33
|
-
const media = await loadMediaFromPath(path, mimeType);
|
|
34
|
-
replyMedia(media, caption);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
replyMedia.fromBuffer = (
|
|
38
|
-
buffer: Buffer,
|
|
39
|
-
mimeType: MimeType,
|
|
40
|
-
caption?: string,
|
|
41
|
-
fileName?: string
|
|
42
|
-
) => {
|
|
43
|
-
const media = createMediaFromBuffer(buffer, mimeType, fileName);
|
|
44
|
-
replyMedia(media, caption);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
replyMedia.fromB64 = (
|
|
48
|
-
b64: string,
|
|
49
|
-
mimeType: MimeType,
|
|
50
|
-
caption?: string,
|
|
51
|
-
fileName?: string
|
|
52
|
-
) => {
|
|
53
|
-
const media = createMediaFromB64(b64, mimeType, fileName);
|
|
54
|
-
replyMedia(media, caption);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
replyMedia.fromUrl = (url: string, mimeType: MimeType, caption?: string) => {
|
|
58
|
-
const media = createMediaFromUrl(url, mimeType);
|
|
59
|
-
replyMedia(media, caption);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
return replyMedia;
|
|
63
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Media, Command, MessageReceivedByGateway } from 'kozz-types/dist';
|
|
2
|
-
import { Socket } from 'socket.io-client';
|
|
3
|
-
import { replyWithSticker } from '../../PayloadCreation';
|
|
4
|
-
|
|
5
|
-
export const withSticker =
|
|
6
|
-
(socket: Socket, messagePayload: MessageReceivedByGateway) =>
|
|
7
|
-
(media: Media) => {
|
|
8
|
-
socket.emit('reply_with_sticker', replyWithSticker(messagePayload, media));
|
|
9
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Command, MessageReceivedByGateway } from 'kozz-types/dist';
|
|
2
|
-
import { Socket } from 'socket.io-client';
|
|
3
|
-
import { loadTemplates } from '../../../Message/FromTemplate';
|
|
4
|
-
import { replyWithText } from '../../../Message/PayloadCreation';
|
|
5
|
-
|
|
6
|
-
export const withTemplate =
|
|
7
|
-
(
|
|
8
|
-
socket: Socket,
|
|
9
|
-
messagePayload: MessageReceivedByGateway,
|
|
10
|
-
templatePath?: string
|
|
11
|
-
) =>
|
|
12
|
-
(templateName: string, templateData: Record<string, any> = {}) => {
|
|
13
|
-
if (!templatePath) {
|
|
14
|
-
throw 'Trying to reply with template but no template path was provided';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
loadTemplates(templatePath)
|
|
18
|
-
.getTextFromTemplate(templateName, templateData)
|
|
19
|
-
.then(textResponse => {
|
|
20
|
-
if (!textResponse) {
|
|
21
|
-
throw `Error while trying to reply from template ${templateName}, could not find it's template in ${templatePath}`;
|
|
22
|
-
}
|
|
23
|
-
socket.emit(
|
|
24
|
-
'reply_with_text',
|
|
25
|
-
replyWithText(messagePayload, textResponse)
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Command, Media, MessageReceivedByGateway } from 'kozz-types';
|
|
2
|
-
import { Socket } from 'socket.io-client';
|
|
3
|
-
import { createSendMessagePayload } from '../../../Message/PayloadCreation/sendMessage';
|
|
4
|
-
|
|
5
|
-
export const sendMessageToContactOnRequesterObject = (
|
|
6
|
-
socket: Socket,
|
|
7
|
-
handlerName: string,
|
|
8
|
-
boundaryId: string
|
|
9
|
-
) => {
|
|
10
|
-
const sendMessage = (contactId: string, body: string) => {
|
|
11
|
-
socket.emit(
|
|
12
|
-
'send_message',
|
|
13
|
-
createSendMessagePayload(handlerName, contactId, boundaryId, body)
|
|
14
|
-
);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
sendMessage.withMedia = (
|
|
18
|
-
contactId: string,
|
|
19
|
-
caption: string,
|
|
20
|
-
media: Media
|
|
21
|
-
) => {
|
|
22
|
-
socket.emit(
|
|
23
|
-
'send_message',
|
|
24
|
-
createSendMessagePayload(
|
|
25
|
-
handlerName,
|
|
26
|
-
contactId,
|
|
27
|
-
boundaryId,
|
|
28
|
-
caption,
|
|
29
|
-
media
|
|
30
|
-
)
|
|
31
|
-
);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
return sendMessage;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const sendMessageToContact = (socket: Socket, handlerName: string) => {
|
|
38
|
-
const sendMessage = (contactId: string, boundaryId: string, body: string) => {
|
|
39
|
-
socket.emit(
|
|
40
|
-
'send_message',
|
|
41
|
-
createSendMessagePayload(handlerName, contactId, boundaryId, body)
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
sendMessage.withMedia = (
|
|
46
|
-
contactId: string,
|
|
47
|
-
boundaryId: string,
|
|
48
|
-
caption: string,
|
|
49
|
-
media: Media
|
|
50
|
-
) => {
|
|
51
|
-
socket.emit(
|
|
52
|
-
'send_message',
|
|
53
|
-
createSendMessagePayload(
|
|
54
|
-
handlerName,
|
|
55
|
-
contactId,
|
|
56
|
-
boundaryId,
|
|
57
|
-
caption,
|
|
58
|
-
media
|
|
59
|
-
)
|
|
60
|
-
);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return sendMessage;
|
|
64
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Command, MessageReceivedByGateway } from 'kozz-types';
|
|
2
|
-
import { Socket } from 'socket.io-client';
|
|
3
|
-
import { replyWithText } from '../PayloadCreation';
|
|
4
|
-
|
|
5
|
-
import { withMedia } from './Reply/WithMedia';
|
|
6
|
-
import { withSticker } from './Reply/WithSticker';
|
|
7
|
-
import { withTemplate } from './Reply/WithTemplate';
|
|
8
|
-
|
|
9
|
-
export const createReply = (
|
|
10
|
-
socket: Socket,
|
|
11
|
-
messagePayload: MessageReceivedByGateway,
|
|
12
|
-
templatePath?: string
|
|
13
|
-
) => {
|
|
14
|
-
const reply = (text: string) => {
|
|
15
|
-
socket.emit('reply_with_text', replyWithText(messagePayload, text));
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
reply.withSticker = withSticker(socket, messagePayload);
|
|
19
|
-
reply.withTemplate = withTemplate(socket, messagePayload, templatePath);
|
|
20
|
-
reply.withMedia = withMedia(socket, messagePayload);
|
|
21
|
-
|
|
22
|
-
return reply;
|
|
23
|
-
};
|
package/src/Message/index.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Command, MessageReceivedByGateway } from 'kozz-types';
|
|
2
|
-
import { Socket } from 'socket.io-client';
|
|
3
|
-
import { createReply } from './RoutineCreation/reply';
|
|
4
|
-
import { createAskResource } from './RoutineCreation/AskResource';
|
|
5
|
-
import { sendMessageToContactOnRequesterObject } from './RoutineCreation/SendMessage';
|
|
6
|
-
import { createReact } from './PayloadCreation/React';
|
|
7
|
-
export * from './FromTemplate';
|
|
8
|
-
|
|
9
|
-
export type MessageObj = ReturnType<typeof createMessageObject>;
|
|
10
|
-
|
|
11
|
-
export const createMessageObject = (
|
|
12
|
-
socket: Socket,
|
|
13
|
-
messagePayload: MessageReceivedByGateway,
|
|
14
|
-
handlerId: string,
|
|
15
|
-
templatePath?: string,
|
|
16
|
-
command?: Command
|
|
17
|
-
) => {
|
|
18
|
-
/**
|
|
19
|
-
* Replies the requester of the command.
|
|
20
|
-
*/
|
|
21
|
-
const reply = createReply(socket, messagePayload, templatePath);
|
|
22
|
-
const sendMessage = sendMessageToContactOnRequesterObject(
|
|
23
|
-
socket,
|
|
24
|
-
handlerId,
|
|
25
|
-
messagePayload.from
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
const ask = createAskResource(socket, {
|
|
29
|
-
requester: {
|
|
30
|
-
id: handlerId,
|
|
31
|
-
type: 'Handler',
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
const react = createReact(socket, messagePayload);
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
ask,
|
|
38
|
-
sendMessage,
|
|
39
|
-
react,
|
|
40
|
-
rawCommand: command,
|
|
41
|
-
message: messagePayload,
|
|
42
|
-
reply,
|
|
43
|
-
};
|
|
44
|
-
};
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import * as A from 'arcsecond';
|
|
2
|
-
|
|
3
|
-
// _________________
|
|
4
|
-
// Utility functions
|
|
5
|
-
// -----------------
|
|
6
|
-
|
|
7
|
-
const anything = A.regex(/^.*/);
|
|
8
|
-
|
|
9
|
-
const exceptChars = (chars: string) => new RegExp(`^[^${chars}\n]+`);
|
|
10
|
-
|
|
11
|
-
const betweenStrings = <Ident extends string>(
|
|
12
|
-
stringLeft: string,
|
|
13
|
-
stringRight: string,
|
|
14
|
-
identifier: Ident
|
|
15
|
-
) =>
|
|
16
|
-
A.sequenceOf([
|
|
17
|
-
A.str(stringLeft),
|
|
18
|
-
A.regex(exceptChars(stringRight)),
|
|
19
|
-
A.str(stringRight),
|
|
20
|
-
]).map(
|
|
21
|
-
x =>
|
|
22
|
-
({
|
|
23
|
-
style: identifier,
|
|
24
|
-
text: x[1],
|
|
25
|
-
} as const)
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
type TemplateData = {
|
|
29
|
-
[key: string]: unknown;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
let injectableData: TemplateData = {};
|
|
33
|
-
|
|
34
|
-
// _________________
|
|
35
|
-
// Parser itself ...
|
|
36
|
-
// -----------------
|
|
37
|
-
const paragraph = A.sequenceOf([A.str('#'), A.whitespace, anything]).map(
|
|
38
|
-
x =>
|
|
39
|
-
({
|
|
40
|
-
style: 'paragraph',
|
|
41
|
-
text: x[2],
|
|
42
|
-
} as const)
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const italic = betweenStrings('_', '_', 'italic');
|
|
46
|
-
const stroke = betweenStrings('~', '~', 'stroke');
|
|
47
|
-
const bold = betweenStrings('**', '**', 'bold');
|
|
48
|
-
const boldAndItalic = betweenStrings('**_', '_**', 'boldAndItalic');
|
|
49
|
-
const code = betweenStrings('`', '`', 'code');
|
|
50
|
-
const template = betweenStrings('{{', '}}', 'template').map(x => ({
|
|
51
|
-
...x,
|
|
52
|
-
text: `${injectableData[x.text]}`,
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
const normalText = A.regex(exceptChars('`~_*{>')).map(
|
|
56
|
-
x =>
|
|
57
|
-
({
|
|
58
|
-
style: 'normal',
|
|
59
|
-
text: x,
|
|
60
|
-
} as const)
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const listItem = A.sequenceOf([A.str('-'), A.whitespace, anything]).map(
|
|
64
|
-
x =>
|
|
65
|
-
({
|
|
66
|
-
style: 'listItem',
|
|
67
|
-
text: x[2],
|
|
68
|
-
} as const)
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const lineBreak = A.str('<br>').map(
|
|
72
|
-
() =>
|
|
73
|
-
({
|
|
74
|
-
style: 'lineBreak',
|
|
75
|
-
text: '',
|
|
76
|
-
} as const)
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
const textLine = A.sequenceOf([
|
|
80
|
-
A.many(A.whitespace),
|
|
81
|
-
A.many1(
|
|
82
|
-
A.choice([
|
|
83
|
-
paragraph,
|
|
84
|
-
stroke,
|
|
85
|
-
listItem,
|
|
86
|
-
boldAndItalic,
|
|
87
|
-
bold,
|
|
88
|
-
italic,
|
|
89
|
-
code,
|
|
90
|
-
template,
|
|
91
|
-
lineBreak,
|
|
92
|
-
normalText,
|
|
93
|
-
])
|
|
94
|
-
),
|
|
95
|
-
A.many(A.str('\n')),
|
|
96
|
-
]).map(x => ({
|
|
97
|
-
line: x[1],
|
|
98
|
-
}));
|
|
99
|
-
|
|
100
|
-
const messageDeclaration = A.sequenceOf([
|
|
101
|
-
A.str('>'),
|
|
102
|
-
A.whitespace,
|
|
103
|
-
A.str('@'),
|
|
104
|
-
anything,
|
|
105
|
-
]).map(x => x[3]);
|
|
106
|
-
|
|
107
|
-
const messageEnd = A.sequenceOf([
|
|
108
|
-
A.str('>'),
|
|
109
|
-
A.whitespace,
|
|
110
|
-
A.str('---'),
|
|
111
|
-
A.many(A.str('-')),
|
|
112
|
-
A.many(A.str('\n')),
|
|
113
|
-
]);
|
|
114
|
-
|
|
115
|
-
const message = A.sequenceOf([
|
|
116
|
-
A.many(A.str('\n')),
|
|
117
|
-
messageDeclaration,
|
|
118
|
-
A.many1(textLine),
|
|
119
|
-
A.many(A.str('\n')),
|
|
120
|
-
messageEnd,
|
|
121
|
-
]).map(x => ({
|
|
122
|
-
messageName: x[1],
|
|
123
|
-
messageBody: x[2],
|
|
124
|
-
}));
|
|
125
|
-
|
|
126
|
-
const document = A.many(message);
|
|
127
|
-
|
|
128
|
-
const parseDocument = (documentInString: string, data: TemplateData) => {
|
|
129
|
-
injectableData = data;
|
|
130
|
-
const result = document.run(documentInString);
|
|
131
|
-
if (result.isError) {
|
|
132
|
-
throw result.error;
|
|
133
|
-
} else {
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export default parseDocument;
|
package/src/Schema/index.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { MessageObj } from '../Message';
|
|
2
|
-
|
|
3
|
-
export type PrimaryTypeString = 'string' | 'number' | 'boolean';
|
|
4
|
-
export type ArrayTypeString =
|
|
5
|
-
| `${PrimaryTypeString}[]`
|
|
6
|
-
| `${PrimaryTypeString}[]?`;
|
|
7
|
-
|
|
8
|
-
export type OptionalTypeString =
|
|
9
|
-
| `${ArrayTypeString}?`
|
|
10
|
-
| `${PrimaryTypeString}?`;
|
|
11
|
-
|
|
12
|
-
export type TypeString =
|
|
13
|
-
| PrimaryTypeString
|
|
14
|
-
| ArrayTypeString
|
|
15
|
-
| OptionalTypeString;
|
|
16
|
-
|
|
17
|
-
export type StringTypeVariants =
|
|
18
|
-
| 'string'
|
|
19
|
-
| 'string[]'
|
|
20
|
-
| 'string[]?'
|
|
21
|
-
| 'string?';
|
|
22
|
-
|
|
23
|
-
export type NumberTypeVariants =
|
|
24
|
-
| 'number'
|
|
25
|
-
| 'number[]'
|
|
26
|
-
| 'number[]?'
|
|
27
|
-
| 'number?';
|
|
28
|
-
|
|
29
|
-
export type BooleanTypeVariants =
|
|
30
|
-
| 'boolean'
|
|
31
|
-
| 'boolean[]'
|
|
32
|
-
| 'boolean[]?'
|
|
33
|
-
| 'boolean?';
|
|
34
|
-
|
|
35
|
-
type ToPrimary<T extends TypeString> = T extends StringTypeVariants
|
|
36
|
-
? string
|
|
37
|
-
: T extends NumberTypeVariants
|
|
38
|
-
? number
|
|
39
|
-
: T extends BooleanTypeVariants
|
|
40
|
-
? boolean
|
|
41
|
-
: never;
|
|
42
|
-
|
|
43
|
-
type ToArray<T extends ArrayTypeString> = T extends ArrayTypeString
|
|
44
|
-
? ToPrimary<T>[]
|
|
45
|
-
: ToPrimary<T>;
|
|
46
|
-
|
|
47
|
-
type ToOptional<T extends OptionalTypeString> = T extends ArrayTypeString
|
|
48
|
-
? ToArray<T> | undefined
|
|
49
|
-
: T extends OptionalTypeString
|
|
50
|
-
? ToPrimary<T> | undefined
|
|
51
|
-
: T extends PrimaryTypeString
|
|
52
|
-
? ToPrimary<T>
|
|
53
|
-
: never;
|
|
54
|
-
|
|
55
|
-
type TypeFromString<T extends TypeString> = T extends OptionalTypeString
|
|
56
|
-
? ToOptional<T>
|
|
57
|
-
: T extends ArrayTypeString
|
|
58
|
-
? ToArray<T>
|
|
59
|
-
: T extends PrimaryTypeString
|
|
60
|
-
? ToPrimary<T>
|
|
61
|
-
: never;
|
|
62
|
-
|
|
63
|
-
export type MethodCreator = <
|
|
64
|
-
const T extends { [key: string]: TypeString },
|
|
65
|
-
const Name extends string
|
|
66
|
-
>(
|
|
67
|
-
name: Name,
|
|
68
|
-
callback: (
|
|
69
|
-
requester: MessageObj,
|
|
70
|
-
args: { [key in keyof T]: TypeFromString<T[key]> }
|
|
71
|
-
) => any,
|
|
72
|
-
args?: T
|
|
73
|
-
) => MethodMap<Name, T>;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Creates a command that can be inserted in any command Handler
|
|
77
|
-
* @param name
|
|
78
|
-
* @param callback
|
|
79
|
-
* @param args
|
|
80
|
-
* @returns
|
|
81
|
-
*/
|
|
82
|
-
//@ts-ignore
|
|
83
|
-
export const createMethod: MethodCreator = (name, callback, args = {}) => {
|
|
84
|
-
return {
|
|
85
|
-
[name]: {
|
|
86
|
-
args,
|
|
87
|
-
func: callback,
|
|
88
|
-
} as const,
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export type Method<T extends { [key: string]: TypeString }> = {
|
|
93
|
-
readonly args: T;
|
|
94
|
-
readonly func: (message: MessageObj, args: any) => any;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export type MethodMap<
|
|
98
|
-
Name extends string,
|
|
99
|
-
T extends { [key: string]: TypeString }
|
|
100
|
-
> = {
|
|
101
|
-
[key in `${Name}`]: Method<T>;
|
|
102
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ForwardEventPayload } from 'kozz-types';
|
|
2
|
-
import { Socket } from 'socket.io-client';
|
|
3
|
-
|
|
4
|
-
type EventCallback = (payload: any) => any;
|
|
5
|
-
|
|
6
|
-
export const listenBoundary =
|
|
7
|
-
(gatewaySocket: Socket, instanceName: string) => (boundaryId: string) => {
|
|
8
|
-
return {
|
|
9
|
-
when: (eventName: string, callback: EventCallback) => {
|
|
10
|
-
const payload: ForwardEventPayload = {
|
|
11
|
-
destination: {
|
|
12
|
-
id: instanceName,
|
|
13
|
-
type: 'Handler',
|
|
14
|
-
},
|
|
15
|
-
eventName,
|
|
16
|
-
sourceId: boundaryId,
|
|
17
|
-
};
|
|
18
|
-
gatewaySocket.emit('event_forward_request', payload);
|
|
19
|
-
gatewaySocket.on(eventName, callback);
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { HandlerIntroduction, SignaturelessPayload } from 'kozz-types/dist';
|
|
2
|
-
import { Socket } from 'socket.io-client';
|
|
3
|
-
import { Method, TypeString } from '../../../Schema';
|
|
4
|
-
import { signPayload } from 'src/util';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Emits the introduction payload to the gateway
|
|
8
|
-
* @param socket
|
|
9
|
-
* @param handlerName
|
|
10
|
-
* @param methods
|
|
11
|
-
* @param signature
|
|
12
|
-
*/
|
|
13
|
-
export const introduce = <
|
|
14
|
-
T extends Record<string, Method<Record<string, TypeString>>>
|
|
15
|
-
>(
|
|
16
|
-
socket: Socket,
|
|
17
|
-
handlerName: string,
|
|
18
|
-
methods: T,
|
|
19
|
-
signature?: string
|
|
20
|
-
) => {
|
|
21
|
-
const payload: SignaturelessPayload<HandlerIntroduction> = {
|
|
22
|
-
methods: Object.keys(methods),
|
|
23
|
-
name: handlerName,
|
|
24
|
-
role: 'handler',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
socket.emit('introduction', signPayload(payload, signature));
|
|
28
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ProxyRequestPayload, Source } from 'kozz-types';
|
|
2
|
-
import { Socket } from 'socket.io-client';
|
|
3
|
-
import { onProxiedMessage } from '../Handle/ProxiedMessage';
|
|
4
|
-
import { ProxiedMessageObject } from 'src/Message/ProxiedMessage';
|
|
5
|
-
|
|
6
|
-
export type ProxyInitParams = {
|
|
7
|
-
address: string;
|
|
8
|
-
source: Source;
|
|
9
|
-
name: string;
|
|
10
|
-
destinationOverride?: string;
|
|
11
|
-
signature?: string;
|
|
12
|
-
onMessage: (message: ProxiedMessageObject) => any;
|
|
13
|
-
keepProxyAlive?: boolean;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const createProxyRequestPayload = (
|
|
17
|
-
proxyInitParams: ProxyInitParams
|
|
18
|
-
): ProxyRequestPayload => {
|
|
19
|
-
return {
|
|
20
|
-
source: proxyInitParams.source,
|
|
21
|
-
keepAlive: proxyInitParams.keepProxyAlive,
|
|
22
|
-
destination: proxyInitParams.destinationOverride || proxyInitParams.name,
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Request proxy for a given
|
|
28
|
-
* @param socket
|
|
29
|
-
* @param proxyInitParams
|
|
30
|
-
*/
|
|
31
|
-
export const requestProxy = (
|
|
32
|
-
socket: Socket,
|
|
33
|
-
proxyInitParams: ProxyInitParams
|
|
34
|
-
) => {
|
|
35
|
-
onProxiedMessage(socket, proxyInitParams.source, proxyInitParams.onMessage);
|
|
36
|
-
|
|
37
|
-
socket.emit('request_proxy', createProxyRequestPayload(proxyInitParams));
|
|
38
|
-
};
|