Add automatic notifications for incoming messages
- ReceiveMessagesTool now logs notifications when messages arrive - Console output shows: from, subject, and message preview - Automatic real-time alerts via NATS subscription - Enables passive message monitoring without polling 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -75,7 +75,7 @@ export class ReceiveMessagesTool extends ToolHandler<ReceiveMessagesInput, any>
|
|||||||
private messages: any[] = [];
|
private messages: any[] = [];
|
||||||
private subscribed = false;
|
private subscribed = false;
|
||||||
|
|
||||||
constructor(private natsClient: NatsClient) {
|
constructor(private natsClient: NatsClient, private server?: any) {
|
||||||
super(
|
super(
|
||||||
{
|
{
|
||||||
name: 'receive_messages',
|
name: 'receive_messages',
|
||||||
@@ -95,6 +95,9 @@ export class ReceiveMessagesTool extends ToolHandler<ReceiveMessagesInput, any>
|
|||||||
try {
|
try {
|
||||||
this.natsClient.subscribe(channel, (msg) => {
|
this.natsClient.subscribe(channel, (msg) => {
|
||||||
this.messages.push(msg);
|
this.messages.push(msg);
|
||||||
|
|
||||||
|
// Send notification to Claude Code UI
|
||||||
|
this.notifyNewMessage(msg);
|
||||||
});
|
});
|
||||||
this.subscribed = true;
|
this.subscribed = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -102,6 +105,11 @@ export class ReceiveMessagesTool extends ToolHandler<ReceiveMessagesInput, any>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private notifyNewMessage(msg: any) {
|
||||||
|
const preview = msg.message?.substring(0, 100) || '';
|
||||||
|
console.log(`\n📬 NEW MESSAGE from ${msg.from}\n Subject: ${msg.subject}\n Preview: ${preview}...\n`);
|
||||||
|
}
|
||||||
|
|
||||||
protected async handle(input: ReceiveMessagesInput, _context: ToolContext): Promise<any> {
|
protected async handle(input: ReceiveMessagesInput, _context: ToolContext): Promise<any> {
|
||||||
// Setup subscription on first use (after NATS is connected)
|
// Setup subscription on first use (after NATS is connected)
|
||||||
this.setupSubscription();
|
this.setupSubscription();
|
||||||
|
|||||||
Reference in New Issue
Block a user