feat: base shortcut code
This commit is contained in:
32
utils/commands/anthropic.ts
Normal file
32
utils/commands/anthropic.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { getMessage } from '@utils/anthropicClient';
|
||||
import { ShortcutsResponse } from '../types';
|
||||
|
||||
export async function anthropicCommand(
|
||||
parameters: Record<string, string> | undefined
|
||||
): Promise<ShortcutsResponse> {
|
||||
try {
|
||||
if (!parameters || !parameters['question']) {
|
||||
return {
|
||||
success: false,
|
||||
message: 'Sorry. Need to provide a question.'
|
||||
};
|
||||
}
|
||||
|
||||
const response = await getMessage(
|
||||
'I want to know ' +
|
||||
parameters['question'] +
|
||||
'. Structure the response in a manner suitable for spoken communication.'
|
||||
);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: response
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return {
|
||||
success: false,
|
||||
message: 'Sorry. There was a problem with Anthropic.'
|
||||
};
|
||||
}
|
||||
}
|
||||
11
utils/commands/ping.test.ts
Normal file
11
utils/commands/ping.test.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { pingCommand } from './ping';
|
||||
|
||||
describe('Ping Command', () => {
|
||||
it('should return success response', async () => {
|
||||
const response = await pingCommand();
|
||||
|
||||
expect(response.success).toBe(true);
|
||||
expect(response.message).toBe('The system is operational.');
|
||||
expect(response.data).toHaveProperty('timestamp');
|
||||
});
|
||||
});
|
||||
11
utils/commands/ping.ts
Normal file
11
utils/commands/ping.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { ShortcutsResponse } from '../types';
|
||||
|
||||
export async function pingCommand(): Promise<ShortcutsResponse> {
|
||||
return {
|
||||
success: true,
|
||||
message: 'The system is operational.',
|
||||
data: {
|
||||
timestamp: new Date().toISOString()
|
||||
}
|
||||
};
|
||||
}
|
||||
12
utils/commands/time.test.ts
Normal file
12
utils/commands/time.test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { timeCommand } from './time';
|
||||
|
||||
describe('Time Command', () => {
|
||||
it('should return current time', async () => {
|
||||
const response = await timeCommand();
|
||||
|
||||
expect(response.success).toBe(true);
|
||||
expect(response.message).toMatch(/It's currently \d{1,2}:\d{2} [AP]M/);
|
||||
expect(response.data).toHaveProperty('timestamp');
|
||||
expect(response.data).toHaveProperty('formattedTime');
|
||||
});
|
||||
});
|
||||
19
utils/commands/time.ts
Normal file
19
utils/commands/time.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { ShortcutsResponse } from '../types';
|
||||
|
||||
export async function timeCommand(): Promise<ShortcutsResponse> {
|
||||
const now = new Date();
|
||||
const timeString = now.toLocaleTimeString('en-US', {
|
||||
hour: 'numeric',
|
||||
minute: 'numeric',
|
||||
hour12: true
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `It's currently ${timeString}`,
|
||||
data: {
|
||||
timestamp: now.toISOString(),
|
||||
formattedTime: timeString
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user