mirror of
https://github.com/n8n-io/n8n.git
synced 2026-06-03 10:17:00 +02:00
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { get, post } from '@n8n/chat/api/generic';
|
|
import type {
|
|
ChatOptions,
|
|
LoadPreviousSessionResponse,
|
|
SendMessageResponse,
|
|
} from '@n8n/chat/types';
|
|
|
|
export async function loadPreviousSession(sessionId: string, options: ChatOptions) {
|
|
const method = options.webhookConfig?.method === 'POST' ? post : get;
|
|
return await method<LoadPreviousSessionResponse>(
|
|
`${options.webhookUrl}`,
|
|
{
|
|
action: 'loadPreviousSession',
|
|
[options.chatSessionKey as string]: sessionId,
|
|
...(options.metadata ? { metadata: options.metadata } : {}),
|
|
},
|
|
{
|
|
headers: options.webhookConfig?.headers,
|
|
},
|
|
);
|
|
}
|
|
|
|
export async function sendMessage(message: string, sessionId: string, options: ChatOptions) {
|
|
const method = options.webhookConfig?.method === 'POST' ? post : get;
|
|
return await method<SendMessageResponse>(
|
|
`${options.webhookUrl}`,
|
|
{
|
|
action: 'sendMessage',
|
|
[options.chatSessionKey as string]: sessionId,
|
|
[options.chatInputKey as string]: message,
|
|
...(options.metadata ? { metadata: options.metadata } : {}),
|
|
},
|
|
{
|
|
headers: options.webhookConfig?.headers,
|
|
},
|
|
);
|
|
}
|