@memberjunction/ng-chat 2.32.2 → 2.33.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 +194 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Chat Component
|
|
2
|
+
|
|
3
|
+
The Chat Component is a reusable Angular component designed for building chat interfaces in MemberJunction applications. It can be used for AI-assisted conversations or peer-to-peer chat applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Flexible Message System**: Display both user and AI messages with appropriate styling
|
|
8
|
+
- **Markdown Support**: Render chat messages with markdown formatting support
|
|
9
|
+
- **Welcome Screen**: Customizable welcome screen with suggested questions/prompts
|
|
10
|
+
- **Auto-Scrolling**: Keeps the conversation scrolled to the bottom with a scroll-to-bottom button
|
|
11
|
+
- **Loading Indicator**: Visual feedback during AI response generation
|
|
12
|
+
- **Responsive Design**: Adapts to different screen sizes
|
|
13
|
+
- **Auto-Resizing Input**: Text input automatically expands as the user types
|
|
14
|
+
- **Clear Conversation**: Option to clear the entire conversation history
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @memberjunction/ng-chat
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Import the Module
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { ChatModule } from '@memberjunction/ng-chat';
|
|
28
|
+
|
|
29
|
+
@NgModule({
|
|
30
|
+
imports: [
|
|
31
|
+
ChatModule,
|
|
32
|
+
// other imports
|
|
33
|
+
],
|
|
34
|
+
// ...
|
|
35
|
+
})
|
|
36
|
+
export class YourModule { }
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Basic Component Usage
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<mj-chat
|
|
43
|
+
[AIImageURL]="'assets/bot-avatar.png'"
|
|
44
|
+
[InitialMessage]="'How can I help you today?'"
|
|
45
|
+
(MessageAdded)="handleNewMessage($event)"
|
|
46
|
+
(ClearChatRequested)="handleClearChat()">
|
|
47
|
+
</mj-chat>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Welcome Questions Example
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// Component
|
|
54
|
+
import { ChatWelcomeQuestion } from '@memberjunction/ng-chat';
|
|
55
|
+
|
|
56
|
+
@Component({
|
|
57
|
+
selector: 'app-ai-assistant',
|
|
58
|
+
template: `
|
|
59
|
+
<mj-chat
|
|
60
|
+
[AIImageURL]="'assets/bot-avatar.png'"
|
|
61
|
+
[AILargeImageURL]="'assets/bot-large.png'"
|
|
62
|
+
[WelcomeQuestions]="welcomeQuestions"
|
|
63
|
+
(MessageAdded)="handleNewMessage($event)"
|
|
64
|
+
(ClearChatRequested)="handleClearChat()">
|
|
65
|
+
</mj-chat>
|
|
66
|
+
`
|
|
67
|
+
})
|
|
68
|
+
export class AIAssistantComponent {
|
|
69
|
+
welcomeQuestions: ChatWelcomeQuestion[] = [
|
|
70
|
+
{
|
|
71
|
+
topLine: 'Generate a report',
|
|
72
|
+
bottomLine: 'Create a sales summary for Q2',
|
|
73
|
+
prompt: 'Generate a sales report for Q2'
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
topLine: 'Find information',
|
|
77
|
+
bottomLine: 'Search for customer details',
|
|
78
|
+
prompt: 'Find information about customer XYZ'
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
topLine: 'Summarize data',
|
|
82
|
+
bottomLine: 'Give me the key points from the data',
|
|
83
|
+
prompt: 'Summarize the key metrics from my dashboard'
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
topLine: 'Help with a task',
|
|
87
|
+
bottomLine: 'Walk me through creating a new entity',
|
|
88
|
+
prompt: 'Help me create a new entity in MemberJunction'
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
handleNewMessage(message: ChatMessage) {
|
|
93
|
+
// Process the new message
|
|
94
|
+
console.log('New message:', message);
|
|
95
|
+
|
|
96
|
+
if (message.senderType === 'user') {
|
|
97
|
+
// Send to AI service and handle response
|
|
98
|
+
this.processUserMessage(message.message);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
handleClearChat() {
|
|
103
|
+
// Implement chat clearing logic
|
|
104
|
+
console.log('Chat cleared');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async processUserMessage(message: string) {
|
|
108
|
+
// Set loading state
|
|
109
|
+
this.chatComponent.ShowWaitingIndicator = true;
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
// Call your AI or chat service
|
|
113
|
+
const response = await this.aiService.getResponse(message);
|
|
114
|
+
|
|
115
|
+
// Add AI response to chat
|
|
116
|
+
this.chatComponent.SendMessage(
|
|
117
|
+
response,
|
|
118
|
+
'Assistant',
|
|
119
|
+
'ai',
|
|
120
|
+
null
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.error('Error getting AI response:', error);
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
// End loading state
|
|
128
|
+
this.chatComponent.ShowWaitingIndicator = false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## API Reference
|
|
135
|
+
|
|
136
|
+
### Inputs
|
|
137
|
+
|
|
138
|
+
- `InitialMessage`: string - Initial message shown before any messages are added
|
|
139
|
+
- `Messages`: ChatMessage[] - Array of messages to display
|
|
140
|
+
- `AIImageURL`: string - URL for the AI's avatar image (small version)
|
|
141
|
+
- `AILargeImageURL`: string - URL for the AI's large avatar image (welcome screen)
|
|
142
|
+
- `WelcomeQuestions`: ChatWelcomeQuestion[] - Array of up to 4 welcome questions/prompts
|
|
143
|
+
- `ClearAllMessagesPrompt`: string - Confirmation message when clearing the chat
|
|
144
|
+
- `AllowSend`: boolean - Enable/disable sending messages
|
|
145
|
+
- `Placeholder`: string - Placeholder text for the input field
|
|
146
|
+
- `ShowWaitingIndicator`: boolean - Show/hide the loading spinner
|
|
147
|
+
|
|
148
|
+
### Outputs
|
|
149
|
+
|
|
150
|
+
- `MessageAdded`: EventEmitter<ChatMessage> - Fires when a new message is added
|
|
151
|
+
- `ClearChatRequested`: EventEmitter<void> - Fires when user confirms clearing the chat
|
|
152
|
+
|
|
153
|
+
### Classes
|
|
154
|
+
|
|
155
|
+
#### ChatMessage
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
export class ChatMessage {
|
|
159
|
+
public message: string;
|
|
160
|
+
public senderName: string;
|
|
161
|
+
public senderType: 'user' | 'ai';
|
|
162
|
+
public id?: any;
|
|
163
|
+
|
|
164
|
+
constructor(message: string, senderName: string, senderType: 'user' | 'ai', id: any = null);
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### ChatWelcomeQuestion
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
export class ChatWelcomeQuestion {
|
|
172
|
+
public topLine: string = "";
|
|
173
|
+
public bottomLine: string = "";
|
|
174
|
+
public prompt: string = "";
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Methods
|
|
179
|
+
|
|
180
|
+
- `SendCurrentMessage()`: Sends the current message in the input field
|
|
181
|
+
- `SendMessage(message, senderName, senderType, id, fireEvent)`: Sends a specified message
|
|
182
|
+
- `SendUserMessage(message)`: Convenience method to send a user message
|
|
183
|
+
- `ClearAllMessages()`: Clears all messages from the chat interface
|
|
184
|
+
|
|
185
|
+
## Styling
|
|
186
|
+
|
|
187
|
+
The component includes default styles that you can override using CSS. The component uses a clean and modern design with different styling for user and AI messages.
|
|
188
|
+
|
|
189
|
+
## Dependencies
|
|
190
|
+
|
|
191
|
+
- `ngx-markdown`: For rendering markdown in chat messages
|
|
192
|
+
- `@progress/kendo-angular-indicators`: For the loading spinner
|
|
193
|
+
- `@progress/kendo-angular-buttons`: For buttons
|
|
194
|
+
- `@progress/kendo-angular-dialog`: For the clear confirmation dialog
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ng-chat",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.33.0",
|
|
4
4
|
"description": "MemberJunction: Reusable Chat Component - can be used for AI or peer to peer chat applications.",
|
|
5
5
|
"main": "./dist/public-api.js",
|
|
6
6
|
"typings": "./dist/public-api.d.ts",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"@angular/forms": "18.0.2"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@memberjunction/core": "2.
|
|
28
|
-
"@memberjunction/ng-container-directives": "2.
|
|
27
|
+
"@memberjunction/core": "2.33.0",
|
|
28
|
+
"@memberjunction/ng-container-directives": "2.33.0",
|
|
29
29
|
"@progress/kendo-angular-indicators": "16.2.0",
|
|
30
30
|
"@progress/kendo-angular-buttons": "16.2.0",
|
|
31
31
|
"@progress/kendo-angular-dialog": "16.2.0",
|