@hazeljs/messaging 0.2.0-beta.30
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 +192 -0
- package/README.md +186 -0
- package/dist/adapters/telegram.adapter.d.ts +24 -0
- package/dist/adapters/telegram.adapter.d.ts.map +1 -0
- package/dist/adapters/telegram.adapter.js +70 -0
- package/dist/adapters/telegram.adapter.js.map +1 -0
- package/dist/adapters/telegram.adapter.test.d.ts +2 -0
- package/dist/adapters/telegram.adapter.test.d.ts.map +1 -0
- package/dist/adapters/telegram.adapter.test.js +110 -0
- package/dist/adapters/telegram.adapter.test.js.map +1 -0
- package/dist/adapters/viber.adapter.d.ts +29 -0
- package/dist/adapters/viber.adapter.d.ts.map +1 -0
- package/dist/adapters/viber.adapter.js +98 -0
- package/dist/adapters/viber.adapter.js.map +1 -0
- package/dist/adapters/viber.adapter.test.d.ts +2 -0
- package/dist/adapters/viber.adapter.test.d.ts.map +1 -0
- package/dist/adapters/viber.adapter.test.js +73 -0
- package/dist/adapters/viber.adapter.test.js.map +1 -0
- package/dist/adapters/whatsapp.adapter.d.ts +26 -0
- package/dist/adapters/whatsapp.adapter.d.ts.map +1 -0
- package/dist/adapters/whatsapp.adapter.js +87 -0
- package/dist/adapters/whatsapp.adapter.js.map +1 -0
- package/dist/adapters/whatsapp.adapter.test.d.ts +2 -0
- package/dist/adapters/whatsapp.adapter.test.d.ts.map +1 -0
- package/dist/adapters/whatsapp.adapter.test.js +198 -0
- package/dist/adapters/whatsapp.adapter.test.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/messaging-kafka.bootstrap.d.ts +14 -0
- package/dist/messaging-kafka.bootstrap.d.ts.map +1 -0
- package/dist/messaging-kafka.bootstrap.js +42 -0
- package/dist/messaging-kafka.bootstrap.js.map +1 -0
- package/dist/messaging-kafka.bootstrap.test.d.ts +2 -0
- package/dist/messaging-kafka.bootstrap.test.d.ts.map +1 -0
- package/dist/messaging-kafka.bootstrap.test.js +34 -0
- package/dist/messaging-kafka.bootstrap.test.js.map +1 -0
- package/dist/messaging-kafka.consumer.d.ts +10 -0
- package/dist/messaging-kafka.consumer.d.ts.map +1 -0
- package/dist/messaging-kafka.consumer.js +80 -0
- package/dist/messaging-kafka.consumer.js.map +1 -0
- package/dist/messaging-kafka.consumer.test.d.ts +2 -0
- package/dist/messaging-kafka.consumer.test.d.ts.map +1 -0
- package/dist/messaging-kafka.consumer.test.js +129 -0
- package/dist/messaging-kafka.consumer.test.js.map +1 -0
- package/dist/messaging-kafka.types.d.ts +10 -0
- package/dist/messaging-kafka.types.d.ts.map +1 -0
- package/dist/messaging-kafka.types.js +5 -0
- package/dist/messaging-kafka.types.js.map +1 -0
- package/dist/messaging-kafka.types.test.d.ts +2 -0
- package/dist/messaging-kafka.types.test.d.ts.map +1 -0
- package/dist/messaging-kafka.types.test.js +12 -0
- package/dist/messaging-kafka.types.test.js.map +1 -0
- package/dist/messaging.controller.d.ts +27 -0
- package/dist/messaging.controller.d.ts.map +1 -0
- package/dist/messaging.controller.js +151 -0
- package/dist/messaging.controller.js.map +1 -0
- package/dist/messaging.controller.test.d.ts +2 -0
- package/dist/messaging.controller.test.d.ts.map +1 -0
- package/dist/messaging.controller.test.js +184 -0
- package/dist/messaging.controller.test.js.map +1 -0
- package/dist/messaging.module.d.ts +69 -0
- package/dist/messaging.module.d.ts.map +1 -0
- package/dist/messaging.module.js +152 -0
- package/dist/messaging.module.js.map +1 -0
- package/dist/messaging.module.test.d.ts +2 -0
- package/dist/messaging.module.test.d.ts.map +1 -0
- package/dist/messaging.module.test.js +97 -0
- package/dist/messaging.module.test.js.map +1 -0
- package/dist/messaging.service.d.ts +42 -0
- package/dist/messaging.service.d.ts.map +1 -0
- package/dist/messaging.service.js +109 -0
- package/dist/messaging.service.js.map +1 -0
- package/dist/messaging.service.test.d.ts +2 -0
- package/dist/messaging.service.test.d.ts.map +1 -0
- package/dist/messaging.service.test.js +163 -0
- package/dist/messaging.service.test.js.map +1 -0
- package/dist/store/conversation-context.interface.d.ts +17 -0
- package/dist/store/conversation-context.interface.d.ts.map +1 -0
- package/dist/store/conversation-context.interface.js +7 -0
- package/dist/store/conversation-context.interface.js.map +1 -0
- package/dist/store/memory-conversation-context.d.ts +11 -0
- package/dist/store/memory-conversation-context.d.ts.map +1 -0
- package/dist/store/memory-conversation-context.js +22 -0
- package/dist/store/memory-conversation-context.js.map +1 -0
- package/dist/store/memory-conversation-context.test.d.ts +2 -0
- package/dist/store/memory-conversation-context.test.d.ts.map +1 -0
- package/dist/store/memory-conversation-context.test.js +69 -0
- package/dist/store/memory-conversation-context.test.js.map +1 -0
- package/dist/store/redis-conversation-context.d.ts +24 -0
- package/dist/store/redis-conversation-context.d.ts.map +1 -0
- package/dist/store/redis-conversation-context.js +37 -0
- package/dist/store/redis-conversation-context.js.map +1 -0
- package/dist/store/redis-conversation-context.test.d.ts +2 -0
- package/dist/store/redis-conversation-context.test.d.ts.map +1 -0
- package/dist/store/redis-conversation-context.test.js +85 -0
- package/dist/store/redis-conversation-context.test.js.map +1 -0
- package/dist/types/message.types.d.ts +55 -0
- package/dist/types/message.types.d.ts.map +1 -0
- package/dist/types/message.types.js +7 -0
- package/dist/types/message.types.js.map +1 -0
- package/dist/types/response-handler.types.d.ts +47 -0
- package/dist/types/response-handler.types.d.ts.map +1 -0
- package/dist/types/response-handler.types.js +3 -0
- package/dist/types/response-handler.types.js.map +1 -0
- package/package.json +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Copyright 2024 HazelJS Team
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
22
|
+
|
|
23
|
+
1. Definitions.
|
|
24
|
+
|
|
25
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
26
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
27
|
+
|
|
28
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
29
|
+
the copyright owner that is granting the License.
|
|
30
|
+
|
|
31
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
32
|
+
other entities that control, are controlled by, or are under common
|
|
33
|
+
control with that entity. For the purposes of this definition,
|
|
34
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
35
|
+
direction or management of such entity, whether by contract or
|
|
36
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
37
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
38
|
+
|
|
39
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
40
|
+
exercising permissions granted by this License.
|
|
41
|
+
|
|
42
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
43
|
+
including but not limited to software source code, documentation
|
|
44
|
+
source, and configuration files.
|
|
45
|
+
|
|
46
|
+
"Object" form shall mean any form resulting from mechanical
|
|
47
|
+
transformation or translation of a Source form, including but
|
|
48
|
+
not limited to compiled object code, generated documentation,
|
|
49
|
+
and conversions to other media types.
|
|
50
|
+
|
|
51
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
52
|
+
Object form, made available under the License, as indicated by a
|
|
53
|
+
copyright notice that is included in or attached to the work
|
|
54
|
+
(an example is provided in the Appendix below).
|
|
55
|
+
|
|
56
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
57
|
+
form, that is based on (or derived from) the Work and for which the
|
|
58
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
59
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
60
|
+
of this License, Derivative Works shall not include works that remain
|
|
61
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
62
|
+
the Work and Derivative Works thereof.
|
|
63
|
+
|
|
64
|
+
"Contribution" shall mean any work of authorship, including
|
|
65
|
+
the original version of the Work and any modifications or additions
|
|
66
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
67
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
68
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
69
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
70
|
+
means any form of electronic, verbal, or written communication sent
|
|
71
|
+
to the Licensor or its representatives, including but not limited to
|
|
72
|
+
communication on electronic mailing lists, source code control systems,
|
|
73
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
74
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
75
|
+
excluding communication that is conspicuously marked or otherwise
|
|
76
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
77
|
+
|
|
78
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
79
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
80
|
+
subsequently incorporated within the Work.
|
|
81
|
+
|
|
82
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
83
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
84
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
85
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
86
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
87
|
+
Work and such Derivative Works in Source or Object form.
|
|
88
|
+
|
|
89
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
90
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
91
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
92
|
+
(except as stated in this section) patent license to make, have made,
|
|
93
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
94
|
+
where such license applies only to those patent claims licensable
|
|
95
|
+
by such Contributor that are necessarily infringed by their
|
|
96
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
97
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
98
|
+
institute patent litigation against any entity (including a
|
|
99
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
100
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
101
|
+
or contributory patent infringement, then any patent licenses
|
|
102
|
+
granted to You under this License for that Work shall terminate
|
|
103
|
+
as of the date such litigation is filed.
|
|
104
|
+
|
|
105
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
106
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
107
|
+
modifications, and in Source or Object form, provided that You
|
|
108
|
+
meet the following conditions:
|
|
109
|
+
|
|
110
|
+
(a) You must give any other recipients of the Work or
|
|
111
|
+
Derivative Works a copy of this License; and
|
|
112
|
+
|
|
113
|
+
(b) You must cause any modified files to carry prominent notices
|
|
114
|
+
stating that You changed the files; and
|
|
115
|
+
|
|
116
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
117
|
+
that You distribute, all copyright, patent, trademark, and
|
|
118
|
+
attribution notices from the Source form of the Work,
|
|
119
|
+
excluding those notices that do not pertain to any part of
|
|
120
|
+
the Derivative Works; and
|
|
121
|
+
|
|
122
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
123
|
+
distribution, then any Derivative Works that You distribute must
|
|
124
|
+
include a readable copy of the attribution notices contained
|
|
125
|
+
within such NOTICE file, excluding those notices that do not
|
|
126
|
+
pertain to any part of the Derivative Works, in at least one
|
|
127
|
+
of the following places: within a NOTICE text file distributed
|
|
128
|
+
as part of the Derivative Works; within the Source form or
|
|
129
|
+
documentation, if provided along with the Derivative Works; or,
|
|
130
|
+
within a display generated by the Derivative Works, if and
|
|
131
|
+
wherever such third-party notices normally appear. The contents
|
|
132
|
+
of the NOTICE file are for informational purposes only and
|
|
133
|
+
do not modify the License. You may add Your own attribution
|
|
134
|
+
notices within Derivative Works that You distribute, alongside
|
|
135
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
136
|
+
that such additional attribution notices cannot be construed
|
|
137
|
+
as modifying the License.
|
|
138
|
+
|
|
139
|
+
You may add Your own copyright statement to Your modifications and
|
|
140
|
+
may provide additional or different license terms and conditions
|
|
141
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
142
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
143
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
144
|
+
the conditions stated in this License.
|
|
145
|
+
|
|
146
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
147
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
148
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
149
|
+
this License, without any additional terms or conditions.
|
|
150
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
151
|
+
the terms of any separate license agreement you may have executed
|
|
152
|
+
with Licensor regarding such Contributions.
|
|
153
|
+
|
|
154
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
155
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
156
|
+
except as required for reasonable and customary use in describing the
|
|
157
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
158
|
+
|
|
159
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
160
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
161
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
162
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
163
|
+
implied, including, without limitation, any warranties or conditions
|
|
164
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
165
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
166
|
+
appropriateness of using or redistributing the Work and assume any
|
|
167
|
+
risks associated with Your exercise of permissions under this License.
|
|
168
|
+
|
|
169
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
170
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
171
|
+
unless required by applicable law (such as deliberate and grossly
|
|
172
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
173
|
+
liable to You for damages, including any direct, indirect, special,
|
|
174
|
+
incidental, or consequential damages of any character arising as a
|
|
175
|
+
result of this License or out of the use or inability to use the
|
|
176
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
177
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
178
|
+
other commercial damages or losses), even if such Contributor
|
|
179
|
+
has been advised of the possibility of such damages.
|
|
180
|
+
|
|
181
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
182
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
183
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
184
|
+
or other liability obligations and/or rights consistent with this
|
|
185
|
+
License. However, in accepting such obligations, You may act only
|
|
186
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
187
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
188
|
+
defend, and hold each Contributor harmless for any liability
|
|
189
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
190
|
+
of your accepting any such warranty or additional liability.
|
|
191
|
+
|
|
192
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# @hazeljs/messaging
|
|
2
|
+
|
|
3
|
+
Multichannel messaging for HazelJS: WhatsApp, Telegram, Viber with LLM-powered bot responses.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Channel adapters** – Telegram (Telegraf), WhatsApp Cloud API, Viber (optional)
|
|
8
|
+
- **Unified message format** – Channel-agnostic `IncomingMessage` / `OutgoingMessage`
|
|
9
|
+
- **LLM integration** – Uses `@hazeljs/ai` providers (OpenAI, Anthropic, etc.) for conversational responses
|
|
10
|
+
- **Conversation context** – Memory (dev) or **Redis** (production, horizontally scalable)
|
|
11
|
+
- **Kafka processing** – Optional async flow for horizontally scalable message handling
|
|
12
|
+
- **Webhook controller** – Single endpoint per channel for incoming messages
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @hazeljs/messaging @hazeljs/ai @hazeljs/core
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
For **Redis context** (horizontal scaling):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install ioredis
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
For **Kafka async processing** (horizontal scaling):
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @hazeljs/kafka
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
For Viber support:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install viber-bot
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { HazelApp } from '@hazeljs/core';
|
|
42
|
+
import { MessagingModule } from '@hazeljs/messaging';
|
|
43
|
+
import { OpenAIProvider } from '@hazeljs/ai';
|
|
44
|
+
|
|
45
|
+
const app = new HazelApp({
|
|
46
|
+
imports: [
|
|
47
|
+
MessagingModule.forRoot({
|
|
48
|
+
aiProvider: new OpenAIProvider(process.env.OPENAI_API_KEY),
|
|
49
|
+
systemPrompt: 'You are a helpful support assistant. Keep responses concise.',
|
|
50
|
+
model: 'gpt-4o-mini',
|
|
51
|
+
channels: {
|
|
52
|
+
telegram: { botToken: process.env.TELEGRAM_BOT_TOKEN! },
|
|
53
|
+
whatsapp: {
|
|
54
|
+
accessToken: process.env.WHATSAPP_ACCESS_TOKEN!,
|
|
55
|
+
phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID!,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
app.listen(3000);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Scalable Configuration (Redis + Kafka)
|
|
66
|
+
|
|
67
|
+
For horizontal scalability, use Redis for context and Kafka for async processing:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import Redis from 'ioredis';
|
|
71
|
+
|
|
72
|
+
MessagingModule.forRoot({
|
|
73
|
+
aiProvider: new OpenAIProvider(),
|
|
74
|
+
channels: { telegram: { botToken: process.env.TELEGRAM_BOT_TOKEN! } },
|
|
75
|
+
redis: {
|
|
76
|
+
host: process.env.REDIS_HOST ?? 'localhost',
|
|
77
|
+
port: parseInt(process.env.REDIS_PORT ?? '6379', 10),
|
|
78
|
+
password: process.env.REDIS_PASSWORD,
|
|
79
|
+
ttlSeconds: 86400, // 24h
|
|
80
|
+
},
|
|
81
|
+
kafka: {
|
|
82
|
+
brokers: (process.env.KAFKA_BROKERS ?? 'localhost:9092').split(','),
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
- **Redis**: Stores conversation history; any instance can serve any session.
|
|
88
|
+
- **Kafka**: Webhook returns 200 immediately; consumers process messages asynchronously (scale workers independently).
|
|
89
|
+
|
|
90
|
+
## Webhook URLs
|
|
91
|
+
|
|
92
|
+
| Channel | Method | URL |
|
|
93
|
+
|-----------|--------|----------------------------------|
|
|
94
|
+
| Telegram | POST | `/api/messaging/webhook/telegram` |
|
|
95
|
+
| WhatsApp | GET | `/api/messaging/webhook/whatsapp` (verification) |
|
|
96
|
+
| WhatsApp | POST | `/api/messaging/webhook/whatsapp` |
|
|
97
|
+
| Viber | POST | `/api/messaging/webhook/viber` |
|
|
98
|
+
|
|
99
|
+
## Configuration
|
|
100
|
+
|
|
101
|
+
### MessagingModuleOptions
|
|
102
|
+
|
|
103
|
+
- `aiProvider` – `IAIProvider` from `@hazeljs/ai` (e.g. `OpenAIProvider`)
|
|
104
|
+
- `systemPrompt` – System prompt for the LLM
|
|
105
|
+
- `model` – Model name (default: `gpt-4o-mini`)
|
|
106
|
+
- `temperature` – 0–1 (default: 0.7)
|
|
107
|
+
- `maxTokens` – Max response tokens (default: 500)
|
|
108
|
+
- `maxContextTurns` – Conversation turns to keep (default: 10)
|
|
109
|
+
- `customHandler` – Override LLM with a custom `(msg) => string | Promise<string>`
|
|
110
|
+
- `channels` – Channel config (see below)
|
|
111
|
+
|
|
112
|
+
### WhatsApp
|
|
113
|
+
|
|
114
|
+
- Requires [WhatsApp Business API](https://developers.facebook.com/docs/whatsapp/cloud-api) access
|
|
115
|
+
- Set `WHATSAPP_VERIFY_TOKEN` in env for webhook verification
|
|
116
|
+
- `accessToken`, `phoneNumberId` from Meta for Developers
|
|
117
|
+
|
|
118
|
+
### Telegram
|
|
119
|
+
|
|
120
|
+
- Create a bot via [@BotFather](https://t.me/BotFather)
|
|
121
|
+
- Set webhook: `https://api.telegram.org/bot<token>/setWebhook?url=https://your-domain/api/messaging/webhook/telegram`
|
|
122
|
+
|
|
123
|
+
### Viber
|
|
124
|
+
|
|
125
|
+
- Create a bot on [Viber Developers](https://developers.viber.com)
|
|
126
|
+
- Install optional peer: `npm install viber-bot`
|
|
127
|
+
|
|
128
|
+
## RAG and Agent Integration
|
|
129
|
+
|
|
130
|
+
### RAG-augmented responses
|
|
131
|
+
|
|
132
|
+
Use a knowledge base to ground responses. Compatible with `@hazeljs/rag` RAGService:
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { RAGService } from '@hazeljs/rag';
|
|
136
|
+
// ... set up RAGService with vector store, embeddings, etc.
|
|
137
|
+
|
|
138
|
+
MessagingModule.forRoot({
|
|
139
|
+
aiProvider: new OpenAIProvider(),
|
|
140
|
+
ragService: myRAGService,
|
|
141
|
+
ragTopK: 5,
|
|
142
|
+
ragMinScore: 0.5,
|
|
143
|
+
channels: { telegram: { botToken: process.env.TELEGRAM_BOT_TOKEN! } },
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Agent handler (CSR-style: tools, RAG, external APIs)
|
|
148
|
+
|
|
149
|
+
Wire your CSRService or AgentRuntime for full control—tools, RAG, external lookups:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { MessagingModule } from '@hazeljs/messaging';
|
|
153
|
+
import { CSRService } from './csr'; // your CSRService like hazeljs-csr-example
|
|
154
|
+
|
|
155
|
+
const csrService = new CSRService(...);
|
|
156
|
+
|
|
157
|
+
MessagingModule.forRoot({
|
|
158
|
+
agentHandler: async ({ message, sessionId }) => {
|
|
159
|
+
const result = await csrService.chat(message.text, sessionId, message.userId);
|
|
160
|
+
return { response: result.response, sources: result.sources };
|
|
161
|
+
},
|
|
162
|
+
channels: { telegram: { botToken: process.env.TELEGRAM_BOT_TOKEN! } },
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The agent handler receives `{ message, sessionId, conversationTurns }` and can:
|
|
167
|
+
- Call `AgentRuntime.execute()` with tools and RAG
|
|
168
|
+
- Use external services (orders, inventory, tickets)
|
|
169
|
+
- Return `string` or `{ response, sources }`
|
|
170
|
+
|
|
171
|
+
## Extending
|
|
172
|
+
|
|
173
|
+
### Custom handler
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
MessagingModule.forRoot({
|
|
177
|
+
customHandler: async (msg) => {
|
|
178
|
+
if (msg.text === '/help') return 'Available commands: /help, /status';
|
|
179
|
+
return 'Use /help for commands.';
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Custom adapter
|
|
185
|
+
|
|
186
|
+
Implement `IChannelAdapter` and register via providers.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram channel adapter using Telegraf
|
|
3
|
+
*/
|
|
4
|
+
import { Telegraf } from 'telegraf';
|
|
5
|
+
import type { IChannelAdapter, IncomingMessage, OutgoingMessage, MessagingChannel } from '../types/message.types';
|
|
6
|
+
export interface TelegramAdapterConfig {
|
|
7
|
+
botToken: string;
|
|
8
|
+
}
|
|
9
|
+
/** Telegram adapter - uses Telegraf for webhook handling */
|
|
10
|
+
export declare class TelegramAdapter implements IChannelAdapter {
|
|
11
|
+
readonly channel: MessagingChannel;
|
|
12
|
+
private bot;
|
|
13
|
+
private config;
|
|
14
|
+
constructor(config: TelegramAdapterConfig);
|
|
15
|
+
/** Get Telegraf instance for webhook middleware */
|
|
16
|
+
getBot(): Telegraf;
|
|
17
|
+
/** Parse Telegram update (from webhook) into IncomingMessage */
|
|
18
|
+
parseIncoming(payload: unknown): IncomingMessage | IncomingMessage[] | null;
|
|
19
|
+
/** Send response via Telegram Bot API */
|
|
20
|
+
send(message: OutgoingMessage): Promise<void>;
|
|
21
|
+
/** Register handler that receives IncomingMessage and sends response via this adapter */
|
|
22
|
+
onMessage(handler: (msg: IncomingMessage) => Promise<string> | string): void;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=telegram.adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram.adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/telegram.adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,4DAA4D;AAC5D,qBAAa,eAAgB,YAAW,eAAe;IACrD,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAc;IAChD,OAAO,CAAC,GAAG,CAAW;IACtB,OAAO,CAAC,MAAM,CAAwB;gBAE1B,MAAM,EAAE,qBAAqB;IAKzC,mDAAmD;IACnD,MAAM,IAAI,QAAQ;IAIlB,gEAAgE;IAChE,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,GAAG,eAAe,EAAE,GAAG,IAAI;IA4C3E,yCAAyC;IACnC,IAAI,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IASnD,yFAAyF;IACzF,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI;CAc7E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TelegramAdapter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Telegram channel adapter using Telegraf
|
|
6
|
+
*/
|
|
7
|
+
const telegraf_1 = require("telegraf");
|
|
8
|
+
/** Telegram adapter - uses Telegraf for webhook handling */
|
|
9
|
+
class TelegramAdapter {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.channel = 'telegram';
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.bot = new telegraf_1.Telegraf(config.botToken);
|
|
14
|
+
}
|
|
15
|
+
/** Get Telegraf instance for webhook middleware */
|
|
16
|
+
getBot() {
|
|
17
|
+
return this.bot;
|
|
18
|
+
}
|
|
19
|
+
/** Parse Telegram update (from webhook) into IncomingMessage */
|
|
20
|
+
parseIncoming(payload) {
|
|
21
|
+
const update = payload;
|
|
22
|
+
const msg = update.message ?? update.edited_message;
|
|
23
|
+
if (!msg?.text)
|
|
24
|
+
return null;
|
|
25
|
+
const from = msg.from;
|
|
26
|
+
const chat = msg.chat;
|
|
27
|
+
const fromAny = from;
|
|
28
|
+
const name = [fromAny?.first_name, fromAny?.last_name].filter(Boolean).join(' ') || fromAny?.username;
|
|
29
|
+
const chatAny = chat;
|
|
30
|
+
return {
|
|
31
|
+
id: String(msg.message_id),
|
|
32
|
+
channel: 'telegram',
|
|
33
|
+
conversationId: String(chat.id),
|
|
34
|
+
userId: String(from?.id ?? ''),
|
|
35
|
+
userName: name || undefined,
|
|
36
|
+
text: msg.text,
|
|
37
|
+
rawPayload: payload,
|
|
38
|
+
timestamp: new Date((msg.date ?? 0) * 1000),
|
|
39
|
+
sessionId: `telegram:${chat.id}`,
|
|
40
|
+
metadata: { chatType: chatAny.type },
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Send response via Telegram Bot API */
|
|
44
|
+
async send(message) {
|
|
45
|
+
const chatId = message.conversationId;
|
|
46
|
+
const opts = {};
|
|
47
|
+
if (message.replyToMessageId) {
|
|
48
|
+
opts.reply_to_message_id = parseInt(message.replyToMessageId, 10);
|
|
49
|
+
}
|
|
50
|
+
await this.bot.telegram.sendMessage(chatId, message.text, opts);
|
|
51
|
+
}
|
|
52
|
+
/** Register handler that receives IncomingMessage and sends response via this adapter */
|
|
53
|
+
onMessage(handler) {
|
|
54
|
+
this.bot.on('text', async (ctx) => {
|
|
55
|
+
const normalized = this.parseIncoming(ctx.update);
|
|
56
|
+
if (!normalized || Array.isArray(normalized))
|
|
57
|
+
return;
|
|
58
|
+
const response = await handler(normalized);
|
|
59
|
+
if (response) {
|
|
60
|
+
await this.send({
|
|
61
|
+
conversationId: normalized.conversationId,
|
|
62
|
+
text: response,
|
|
63
|
+
replyToMessageId: normalized.id,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.TelegramAdapter = TelegramAdapter;
|
|
70
|
+
//# sourceMappingURL=telegram.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram.adapter.js","sourceRoot":"","sources":["../../src/adapters/telegram.adapter.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,uCAAoC;AAYpC,4DAA4D;AAC5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src/adapters/telegram.adapter.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* TelegramAdapter tests
|
|
5
|
+
*/
|
|
6
|
+
const telegram_adapter_1 = require("./telegram.adapter");
|
|
7
|
+
const telegraf_1 = require("telegraf");
|
|
8
|
+
// Mock Telegraf to avoid actual Telegram API calls
|
|
9
|
+
jest.mock('telegraf', () => {
|
|
10
|
+
const mockSendMessage = jest.fn().mockResolvedValue(undefined);
|
|
11
|
+
return {
|
|
12
|
+
Telegraf: jest.fn().mockImplementation(() => ({
|
|
13
|
+
telegram: { sendMessage: mockSendMessage },
|
|
14
|
+
})),
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
describe('TelegramAdapter', () => {
|
|
18
|
+
let adapter;
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
adapter = new telegram_adapter_1.TelegramAdapter({ botToken: 'test-token' });
|
|
21
|
+
});
|
|
22
|
+
describe('channel', () => {
|
|
23
|
+
it('has channel telegram', () => {
|
|
24
|
+
expect(adapter.channel).toBe('telegram');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('getBot', () => {
|
|
28
|
+
it('returns Telegraf instance', () => {
|
|
29
|
+
const bot = adapter.getBot();
|
|
30
|
+
expect(bot).toBeDefined();
|
|
31
|
+
expect(bot.telegram).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe('parseIncoming', () => {
|
|
35
|
+
it('returns null when no text message', () => {
|
|
36
|
+
expect(adapter.parseIncoming({})).toBeNull();
|
|
37
|
+
expect(adapter.parseIncoming({ message: { chat: {}, from: {} } })).toBeNull();
|
|
38
|
+
});
|
|
39
|
+
it('parses message from update.message', () => {
|
|
40
|
+
const payload = {
|
|
41
|
+
message: {
|
|
42
|
+
message_id: 42,
|
|
43
|
+
chat: { id: -100123, type: 'group' },
|
|
44
|
+
from: { id: 12345, username: 'johndoe', first_name: 'John', last_name: 'Doe' },
|
|
45
|
+
text: 'Hello bot',
|
|
46
|
+
date: 1609459200,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const result = adapter.parseIncoming(payload);
|
|
50
|
+
expect(result).not.toBeNull();
|
|
51
|
+
const msg = Array.isArray(result) ? result[0] : result;
|
|
52
|
+
expect(msg?.id).toBe('42');
|
|
53
|
+
expect(msg?.channel).toBe('telegram');
|
|
54
|
+
expect(msg?.conversationId).toBe('-100123');
|
|
55
|
+
expect(msg?.userId).toBe('12345');
|
|
56
|
+
expect(msg?.userName).toBe('John Doe');
|
|
57
|
+
expect(msg?.text).toBe('Hello bot');
|
|
58
|
+
expect(msg?.sessionId).toBe('telegram:-100123');
|
|
59
|
+
expect(msg?.metadata?.chatType).toBe('group');
|
|
60
|
+
});
|
|
61
|
+
it('parses edited_message', () => {
|
|
62
|
+
const payload = {
|
|
63
|
+
edited_message: {
|
|
64
|
+
message_id: 43,
|
|
65
|
+
chat: { id: 999 },
|
|
66
|
+
from: { id: 1 },
|
|
67
|
+
text: 'Edited text',
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const result = adapter.parseIncoming(payload);
|
|
71
|
+
expect(result).not.toBeNull();
|
|
72
|
+
const msg = Array.isArray(result) ? result[0] : result;
|
|
73
|
+
expect(msg?.text).toBe('Edited text');
|
|
74
|
+
expect(msg?.id).toBe('43');
|
|
75
|
+
});
|
|
76
|
+
it('uses username when first/last name not available', () => {
|
|
77
|
+
const payload = {
|
|
78
|
+
message: {
|
|
79
|
+
message_id: 1,
|
|
80
|
+
chat: { id: 1 },
|
|
81
|
+
from: { id: 1, username: 'bob' },
|
|
82
|
+
text: 'Hi',
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
const result = adapter.parseIncoming(payload);
|
|
86
|
+
const msg = Array.isArray(result) ? result[0] : result;
|
|
87
|
+
expect(msg?.userName).toBe('bob');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
describe('send', () => {
|
|
91
|
+
it('sends message via Telegraf', async () => {
|
|
92
|
+
const mockInstance = telegraf_1.Telegraf.mock.results[0]?.value;
|
|
93
|
+
await adapter.send({
|
|
94
|
+
conversationId: '123',
|
|
95
|
+
text: 'Hello user',
|
|
96
|
+
replyToMessageId: '42',
|
|
97
|
+
});
|
|
98
|
+
expect(mockInstance.telegram.sendMessage).toHaveBeenCalledWith('123', 'Hello user', expect.objectContaining({ reply_to_message_id: 42 }));
|
|
99
|
+
});
|
|
100
|
+
it('sends without reply when replyToMessageId not provided', async () => {
|
|
101
|
+
const mockInstance = telegraf_1.Telegraf.mock.results[0]?.value;
|
|
102
|
+
await adapter.send({
|
|
103
|
+
conversationId: '456',
|
|
104
|
+
text: 'Standalone',
|
|
105
|
+
});
|
|
106
|
+
expect(mockInstance.telegram.sendMessage).toHaveBeenCalledWith('456', 'Standalone', {});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=telegram.adapter.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram.adapter.test.js","sourceRoot":"","sources":["../../src/adapters/telegram.adapter.test.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,yDAAqD;AACrD,uCAAoC;AAEpC,mDAAmD;AACnD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE;IACzB,MAAM,eAAe,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC/D,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,CAAC;YAC5C,QAAQ,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE;SAC3C,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,iBAAiB,EAAE,GAA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CAAC,MAAM,EAAE,GAAG,EAAE;QACpB,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC1C,MAAM,YAAY,GAAI,mBAAiC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;YAE/E,MAAM,OAAO,CAAC,IAAI,CAAC;gBACjB,cAAc,EAAE,KAAK;gBACrB,IAAI,EAAE,YAAY;gBAClB,gBAAgB,EAAE,IAAI;aACvB,CAAC,CAAC;YAEH,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAC5D,KAAK,EACL,YAAY,EACZ,MAAM,CAAC,gBAAgB,CAAC,EAAE,mBAAmB,EAAE,EAAE,EAAE,CAAC,CACrD,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wDAAwD,EAAE,KAAK,IAAI,EAAE;YACtE,MAAM,YAAY,GAAI,mBAAiC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;YAE/E,MAAM,OAAO,CAAC,IAAI,CAAC;gBACjB,cAAc,EAAE,KAAK;gBACrB,IAAI,EAAE,YAAY;aACnB,CAAC,CAAC;YAEH,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC;QAC1F,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Viber channel adapter
|
|
3
|
+
* Uses viber-bot (optional dependency)
|
|
4
|
+
*/
|
|
5
|
+
import type { IChannelAdapter, IncomingMessage, OutgoingMessage, MessagingChannel } from '../types/message.types';
|
|
6
|
+
export interface ViberAdapterConfig {
|
|
7
|
+
authToken: string;
|
|
8
|
+
/** Webhook path, e.g. /viber/webhook */
|
|
9
|
+
webhookPath?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Viber adapter - requires viber-bot to be installed */
|
|
12
|
+
export declare class ViberAdapter implements IChannelAdapter {
|
|
13
|
+
readonly channel: MessagingChannel;
|
|
14
|
+
private config;
|
|
15
|
+
private bot;
|
|
16
|
+
constructor(config: ViberAdapterConfig);
|
|
17
|
+
private initBot;
|
|
18
|
+
/** Get raw viber-bot instance for advanced use */
|
|
19
|
+
getBot(): unknown;
|
|
20
|
+
/** Parse Viber webhook payload into IncomingMessage */
|
|
21
|
+
parseIncoming(payload: unknown): IncomingMessage | IncomingMessage[] | null;
|
|
22
|
+
/** Send response via Viber API */
|
|
23
|
+
send(message: OutgoingMessage): Promise<void>;
|
|
24
|
+
/** Register message handler - use with viber-bot middleware */
|
|
25
|
+
onMessage(handler: (msg: IncomingMessage) => Promise<string> | string): void;
|
|
26
|
+
/** Express/Hazel middleware for Viber webhook */
|
|
27
|
+
webhookMiddleware(): (req: unknown, res: unknown, next?: () => void) => void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=viber.adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viber.adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/viber.adapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,yDAAyD;AACzD,qBAAa,YAAa,YAAW,eAAe;IAClD,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAW;IAC7C,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,GAAG,CAAiB;gBAEhB,MAAM,EAAE,kBAAkB;IAKtC,OAAO,CAAC,OAAO;IAcf,kDAAkD;IAClD,MAAM,IAAI,OAAO;IAIjB,uDAAuD;IACvD,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,GAAG,eAAe,EAAE,GAAG,IAAI;IAyB3E,kCAAkC;IAC5B,IAAI,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAUnD,+DAA+D;IAC/D,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI;IAkC5E,iDAAiD;IACjD,iBAAiB,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI;CAW7E"}
|