@memberjunction/communication-types 2.43.0 → 2.45.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/README.md +308 -0
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
# @memberjunction/communication-types
|
|
2
|
+
|
|
3
|
+
MemberJunction Communication Framework Library Generic Types - Base types and interfaces for building communication providers and engines in the MemberJunction ecosystem.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides the foundational types, base classes, and interfaces for implementing communication functionality within MemberJunction applications. It includes base classes for communication engines and providers, message handling, and integration with the MemberJunction metadata system.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @memberjunction/communication-types
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Key Components
|
|
16
|
+
|
|
17
|
+
### CommunicationEngineBase
|
|
18
|
+
|
|
19
|
+
The core engine class that manages communication metadata and orchestrates communication operations across different providers.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { CommunicationEngineBase } from '@memberjunction/communication-types';
|
|
23
|
+
|
|
24
|
+
// Get the singleton instance
|
|
25
|
+
const engine = CommunicationEngineBase.Instance;
|
|
26
|
+
|
|
27
|
+
// Configure the engine (required before use)
|
|
28
|
+
await engine.Config(false, userInfo);
|
|
29
|
+
|
|
30
|
+
// Access communication metadata
|
|
31
|
+
const providers = engine.Providers;
|
|
32
|
+
const messageTypes = engine.BaseMessageTypes;
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### BaseCommunicationProvider
|
|
36
|
+
|
|
37
|
+
Abstract base class for implementing communication providers (email, SMS, social media, etc.).
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { BaseCommunicationProvider, ProcessedMessage, MessageResult } from '@memberjunction/communication-types';
|
|
41
|
+
|
|
42
|
+
export class MyEmailProvider extends BaseCommunicationProvider {
|
|
43
|
+
public async SendSingleMessage(message: ProcessedMessage): Promise<MessageResult> {
|
|
44
|
+
// Implement provider-specific sending logic
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public async GetMessages(params: GetMessagesParams): Promise<GetMessagesResult> {
|
|
48
|
+
// Implement message retrieval
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public async ForwardMessage(params: ForwardMessageParams): Promise<ForwardMessageResult> {
|
|
52
|
+
// Implement message forwarding
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public async ReplyToMessage(params: ReplyToMessageParams): Promise<ReplyToMessageResult> {
|
|
56
|
+
// Implement message replies
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Message Classes
|
|
62
|
+
|
|
63
|
+
#### Message
|
|
64
|
+
Base class for message data:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { Message } from '@memberjunction/communication-types';
|
|
68
|
+
|
|
69
|
+
const message = new Message();
|
|
70
|
+
message.From = "sender@example.com";
|
|
71
|
+
message.To = "recipient@example.com";
|
|
72
|
+
message.Subject = "Hello";
|
|
73
|
+
message.Body = "Message content";
|
|
74
|
+
message.HTMLBody = "<p>HTML content</p>";
|
|
75
|
+
|
|
76
|
+
// Using templates
|
|
77
|
+
message.BodyTemplate = templateEntity;
|
|
78
|
+
message.SubjectTemplate = subjectTemplateEntity;
|
|
79
|
+
message.ContextData = { name: "John", company: "Acme Corp" };
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### ProcessedMessage
|
|
83
|
+
Abstract class for messages that have been processed (templates rendered, etc.):
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
export class MyProcessedMessage extends ProcessedMessage {
|
|
87
|
+
public async Process(forceTemplateRefresh?: boolean, contextUser?: UserInfo): Promise<{Success: boolean, Message?: string}> {
|
|
88
|
+
// Implement template processing logic
|
|
89
|
+
this.ProcessedBody = // processed body
|
|
90
|
+
this.ProcessedHTMLBody = // processed HTML
|
|
91
|
+
this.ProcessedSubject = // processed subject
|
|
92
|
+
return { Success: true };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### MessageRecipient
|
|
98
|
+
Information about a message recipient:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { MessageRecipient } from '@memberjunction/communication-types';
|
|
102
|
+
|
|
103
|
+
const recipient = new MessageRecipient();
|
|
104
|
+
recipient.To = "user@example.com";
|
|
105
|
+
recipient.FullName = "John Doe";
|
|
106
|
+
recipient.ContextData = { customField: "value" };
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Types and Interfaces
|
|
110
|
+
|
|
111
|
+
### GetMessagesParams
|
|
112
|
+
Parameters for retrieving messages:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
type GetMessagesParams<T = Record<string, any>> = {
|
|
116
|
+
NumMessages: number;
|
|
117
|
+
UnreadOnly?: boolean;
|
|
118
|
+
ContextData?: T;
|
|
119
|
+
};
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### GetMessagesResult
|
|
123
|
+
Result structure for retrieved messages:
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
type GetMessagesResult<T = Record<string, any>> = {
|
|
127
|
+
Success: boolean;
|
|
128
|
+
ErrorMessage?: string;
|
|
129
|
+
SourceData?: T[];
|
|
130
|
+
Messages: GetMessageMessage[];
|
|
131
|
+
};
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### ForwardMessageParams
|
|
135
|
+
Parameters for forwarding messages:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
type ForwardMessageParams = {
|
|
139
|
+
MessageID: string;
|
|
140
|
+
Message?: string;
|
|
141
|
+
ToRecipients: string[];
|
|
142
|
+
CCRecipients?: string[];
|
|
143
|
+
BCCRecipients?: string[];
|
|
144
|
+
};
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### ReplyToMessageParams
|
|
148
|
+
Parameters for replying to messages:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
type ReplyToMessageParams<T = Record<string, any>> = {
|
|
152
|
+
MessageID: string;
|
|
153
|
+
Message: ProcessedMessage;
|
|
154
|
+
ContextData?: T;
|
|
155
|
+
};
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Usage Examples
|
|
159
|
+
|
|
160
|
+
### Setting up the Communication Engine
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { CommunicationEngineBase } from '@memberjunction/communication-types';
|
|
164
|
+
import { UserInfo } from '@memberjunction/core';
|
|
165
|
+
|
|
166
|
+
async function initializeCommunications(user: UserInfo) {
|
|
167
|
+
const engine = CommunicationEngineBase.Instance;
|
|
168
|
+
|
|
169
|
+
// Configure the engine
|
|
170
|
+
await engine.Config(false, user);
|
|
171
|
+
|
|
172
|
+
// Access available providers
|
|
173
|
+
const providers = engine.Providers;
|
|
174
|
+
console.log(`Available providers: ${providers.map(p => p.Name).join(', ')}`);
|
|
175
|
+
|
|
176
|
+
// Get message types for a specific provider
|
|
177
|
+
const emailProvider = providers.find(p => p.Name === 'Email');
|
|
178
|
+
const messageTypes = emailProvider?.MessageTypes;
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Creating a Custom Communication Provider
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import {
|
|
186
|
+
BaseCommunicationProvider,
|
|
187
|
+
ProcessedMessage,
|
|
188
|
+
MessageResult,
|
|
189
|
+
GetMessagesParams,
|
|
190
|
+
GetMessagesResult
|
|
191
|
+
} from '@memberjunction/communication-types';
|
|
192
|
+
|
|
193
|
+
export class CustomSMSProvider extends BaseCommunicationProvider {
|
|
194
|
+
public async SendSingleMessage(message: ProcessedMessage): Promise<MessageResult> {
|
|
195
|
+
try {
|
|
196
|
+
// Implement SMS sending logic
|
|
197
|
+
const result = await this.sendSMS(message.To, message.ProcessedBody);
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
Message: message,
|
|
201
|
+
Success: true,
|
|
202
|
+
Error: null
|
|
203
|
+
};
|
|
204
|
+
} catch (error) {
|
|
205
|
+
return {
|
|
206
|
+
Message: message,
|
|
207
|
+
Success: false,
|
|
208
|
+
Error: error.message
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
public async GetMessages(params: GetMessagesParams): Promise<GetMessagesResult> {
|
|
214
|
+
// Implement SMS retrieval logic
|
|
215
|
+
const messages = await this.fetchSMSMessages(params.NumMessages);
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
Success: true,
|
|
219
|
+
Messages: messages.map(m => ({
|
|
220
|
+
From: m.sender,
|
|
221
|
+
To: m.recipient,
|
|
222
|
+
Body: m.text,
|
|
223
|
+
ExternalSystemRecordID: m.id
|
|
224
|
+
}))
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
public async ForwardMessage(params: ForwardMessageParams): Promise<ForwardMessageResult> {
|
|
229
|
+
// SMS forwarding implementation
|
|
230
|
+
return { Success: true };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
public async ReplyToMessage(params: ReplyToMessageParams): Promise<ReplyToMessageResult> {
|
|
234
|
+
// SMS reply implementation
|
|
235
|
+
return { Success: true };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private async sendSMS(to: string, message: string): Promise<any> {
|
|
239
|
+
// Provider-specific implementation
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private async fetchSMSMessages(count: number): Promise<any[]> {
|
|
243
|
+
// Provider-specific implementation
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Integration with MemberJunction
|
|
249
|
+
|
|
250
|
+
This package integrates seamlessly with other MemberJunction packages:
|
|
251
|
+
|
|
252
|
+
- **@memberjunction/core**: Provides base entity functionality and metadata system integration
|
|
253
|
+
- **@memberjunction/core-entities**: Contains the entity definitions for communication-related data
|
|
254
|
+
- **@memberjunction/templates-base-types**: Enables template-based message content
|
|
255
|
+
- **@memberjunction/global**: Provides utility functions and global registry
|
|
256
|
+
|
|
257
|
+
### Working with Communication Logs
|
|
258
|
+
|
|
259
|
+
The engine provides methods for tracking communication activities:
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
// Start a communication run
|
|
263
|
+
const run = await engine.StartRun();
|
|
264
|
+
|
|
265
|
+
// Log individual messages
|
|
266
|
+
const log = await engine.StartLog(processedMessage, run);
|
|
267
|
+
|
|
268
|
+
// Complete the run
|
|
269
|
+
await engine.EndRun(run);
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Dependencies
|
|
273
|
+
|
|
274
|
+
- `@memberjunction/global`: ^2.43.0
|
|
275
|
+
- `@memberjunction/core`: ^2.43.0
|
|
276
|
+
- `@memberjunction/templates-base-types`: ^2.43.0
|
|
277
|
+
- `@memberjunction/core-entities`: ^2.43.0
|
|
278
|
+
- `rxjs`: ^7.8.1
|
|
279
|
+
|
|
280
|
+
## Development
|
|
281
|
+
|
|
282
|
+
### Building
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
npm run build
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Development Mode
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
npm start
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
## Extended Entity Support
|
|
295
|
+
|
|
296
|
+
The package includes an extended Communication Provider entity that automatically links message types:
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
import { CommunicationProviderEntityExtended } from '@memberjunction/communication-types';
|
|
300
|
+
|
|
301
|
+
// The extended entity automatically includes related message types
|
|
302
|
+
const provider = await md.GetEntityObject<CommunicationProviderEntityExtended>('Communication Providers');
|
|
303
|
+
const messageTypes = provider.MessageTypes; // Automatically populated
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## License
|
|
307
|
+
|
|
308
|
+
ISC
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/communication-types",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.45.0",
|
|
4
4
|
"description": "MemberJunction: Communication Framework Library Generic Types",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"typescript": "^5.4.5"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@memberjunction/global": "2.
|
|
23
|
-
"@memberjunction/core": "2.
|
|
24
|
-
"@memberjunction/templates-base-types": "2.
|
|
25
|
-
"@memberjunction/core-entities": "2.
|
|
22
|
+
"@memberjunction/global": "2.45.0",
|
|
23
|
+
"@memberjunction/core": "2.45.0",
|
|
24
|
+
"@memberjunction/templates-base-types": "2.45.0",
|
|
25
|
+
"@memberjunction/core-entities": "2.45.0",
|
|
26
26
|
"rxjs": "^7.8.1"
|
|
27
27
|
}
|
|
28
28
|
}
|