@n8n/chat 0.6.0 → 0.6.1
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/{src/App.vue → App.vue} +2 -2
- package/README.md +27 -4
- package/__stories__/App.stories.d.ts +16 -0
- package/__stories__/App.stories.js +38 -0
- package/__stories__/App.stories.mjs +32 -0
- package/__tests__/index.spec.d.ts +1 -0
- package/__tests__/index.spec.js +146 -0
- package/__tests__/index.spec.mjs +172 -0
- package/__tests__/setup.js +3 -0
- package/__tests__/setup.mjs +1 -0
- package/__tests__/utils/create.d.ts +5 -0
- package/__tests__/utils/create.js +16 -0
- package/__tests__/utils/create.mjs +10 -0
- package/__tests__/utils/fetch.d.ts +3 -0
- package/__tests__/utils/fetch.js +20 -0
- package/__tests__/utils/fetch.mjs +9 -0
- package/__tests__/utils/index.js +38 -0
- package/__tests__/utils/index.mjs +3 -0
- package/__tests__/utils/selectors.d.ts +12 -0
- package/__tests__/utils/selectors.js +58 -0
- package/__tests__/utils/selectors.mjs +41 -0
- package/api/generic.d.ts +6 -0
- package/api/generic.js +68 -0
- package/api/generic.mjs +54 -0
- package/api/index.js +27 -0
- package/api/index.mjs +2 -0
- package/api/message.d.ts +3 -0
- package/api/message.js +33 -0
- package/api/message.mjs +30 -0
- package/chat.bundle.es.js +10753 -0
- package/chat.bundle.umd.js +18 -0
- package/chat.es.js +6864 -0
- package/chat.umd.js +18 -0
- package/components/Button.vue +34 -0
- package/{src/components → components}/Chat.vue +19 -15
- package/components/ChatWindow.vue +104 -0
- package/components/GetStarted.vue +24 -0
- package/{src/components → components}/GetStartedFooter.vue +4 -4
- package/{src/components → components}/Input.vue +35 -40
- package/components/Layout.vue +66 -0
- package/components/Message.vue +94 -0
- package/components/MessageTyping.vue +101 -0
- package/{src/components → components}/MessagesList.vue +8 -8
- package/{src/components → components}/PoweredBy.vue +6 -7
- package/components/index.js +76 -0
- package/components/index.mjs +10 -0
- package/composables/index.js +38 -0
- package/composables/index.mjs +3 -0
- package/composables/useChat.d.ts +1 -0
- package/composables/useChat.js +11 -0
- package/composables/useChat.mjs +5 -0
- package/composables/useI18n.d.ts +4 -0
- package/composables/useI18n.js +23 -0
- package/composables/useI18n.mjs +12 -0
- package/composables/useOptions.d.ts +3 -0
- package/composables/useOptions.js +14 -0
- package/composables/useOptions.mjs +8 -0
- package/constants/defaults.d.ts +3 -0
- package/constants/defaults.js +32 -0
- package/constants/defaults.mjs +26 -0
- package/constants/index.js +38 -0
- package/constants/index.mjs +3 -0
- package/constants/localStorage.d.ts +2 -0
- package/constants/localStorage.js +8 -0
- package/{src/constants/localStorage.ts → constants/localStorage.mjs} +1 -1
- package/constants/symbols.d.ts +3 -0
- package/constants/symbols.js +8 -0
- package/constants/symbols.mjs +2 -0
- package/css/index.css +31 -0
- package/event-buses/chatEventBus.d.ts +1 -0
- package/event-buses/chatEventBus.js +8 -0
- package/event-buses/chatEventBus.mjs +2 -0
- package/event-buses/index.js +16 -0
- package/event-buses/index.mjs +1 -0
- package/index.d.ts +3 -0
- package/index.js +43 -0
- package/index.mjs +36 -0
- package/main.css +151 -0
- package/package.json +41 -5
- package/plugins/chat.d.ts +3 -0
- package/plugins/chat.js +85 -0
- package/plugins/chat.mjs +83 -0
- package/plugins/index.js +16 -0
- package/plugins/index.mjs +1 -0
- package/style.css +1 -0
- package/types/App.vue.d.ts +8 -0
- package/types/__stories__/App.stories.d.ts +17 -0
- package/types/__tests__/index.spec.d.ts +1 -0
- package/types/__tests__/setup.d.ts +0 -0
- package/types/__tests__/utils/create.d.ts +5 -0
- package/types/__tests__/utils/fetch.d.ts +4 -0
- package/types/__tests__/utils/index.d.ts +3 -0
- package/types/__tests__/utils/selectors.d.ts +12 -0
- package/types/api/generic.d.ts +6 -0
- package/types/api/index.d.ts +2 -0
- package/types/api/message.d.ts +3 -0
- package/types/chat.d.ts +11 -0
- package/types/chat.js +1 -0
- package/types/chat.mjs +0 -0
- package/types/components/Button.vue.d.ts +9 -0
- package/types/components/Chat.vue.d.ts +2 -0
- package/types/components/ChatWindow.vue.d.ts +2 -0
- package/types/components/GetStarted.vue.d.ts +2 -0
- package/types/components/GetStartedFooter.vue.d.ts +2 -0
- package/types/components/Input.vue.d.ts +2 -0
- package/types/components/Layout.vue.d.ts +11 -0
- package/types/components/Message.vue.d.ts +21 -0
- package/types/components/MessageTyping.vue.d.ts +15 -0
- package/types/components/MessagesList.vue.d.ts +14 -0
- package/types/components/PoweredBy.vue.d.ts +2 -0
- package/types/components/index.d.ts +10 -0
- package/types/composables/index.d.ts +3 -0
- package/types/composables/useChat.d.ts +2 -0
- package/types/composables/useI18n.d.ts +4 -0
- package/types/composables/useOptions.d.ts +4 -0
- package/types/constants/defaults.d.ts +3 -0
- package/types/constants/index.d.ts +3 -0
- package/types/constants/localStorage.d.ts +2 -0
- package/types/constants/symbols.d.ts +4 -0
- package/types/event-buses/chatEventBus.d.ts +1 -0
- package/types/event-buses/index.d.ts +1 -0
- package/types/index.js +49 -0
- package/types/index.mjs +4 -0
- package/types/messages.d.ts +6 -0
- package/types/messages.js +1 -0
- package/types/messages.mjs +0 -0
- package/types/options.d.ts +25 -0
- package/types/options.js +1 -0
- package/types/options.mjs +0 -0
- package/types/plugins/chat.d.ts +3 -0
- package/types/plugins/index.d.ts +1 -0
- package/types/types/chat.d.ts +11 -0
- package/types/types/index.d.ts +4 -0
- package/types/types/messages.d.ts +6 -0
- package/types/types/options.d.ts +25 -0
- package/types/types/webhook.d.ts +15 -0
- package/types/utils/event-bus.d.ts +8 -0
- package/types/utils/mount.d.ts +1 -0
- package/types/webhook.d.ts +15 -0
- package/types/webhook.js +1 -0
- package/types/webhook.mjs +0 -0
- package/utils/event-bus.d.ts +8 -0
- package/utils/event-bus.js +38 -0
- package/utils/event-bus.mjs +32 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +27 -0
- package/utils/index.mjs +2 -0
- package/utils/mount.d.ts +1 -0
- package/utils/mount.js +19 -0
- package/utils/mount.mjs +13 -0
- package/.eslintignore +0 -2
- package/.eslintrc.cjs +0 -51
- package/.np-config.json +0 -5
- package/.storybook/main.ts +0 -27
- package/.storybook/preview.scss +0 -4
- package/.storybook/preview.ts +0 -16
- package/.vscode/extensions.json +0 -3
- package/env.d.ts +0 -1
- package/index.html +0 -13
- package/resources/workflow.json +0 -293
- package/scripts/pack.js +0 -11
- package/scripts/postbuild.js +0 -16
- package/src/__stories__/App.stories.ts +0 -43
- package/src/__tests__/index.spec.ts +0 -223
- package/src/__tests__/utils/create.ts +0 -16
- package/src/__tests__/utils/fetch.ts +0 -18
- package/src/__tests__/utils/selectors.ts +0 -53
- package/src/api/generic.ts +0 -64
- package/src/api/message.ts +0 -31
- package/src/components/Button.vue +0 -41
- package/src/components/ChatWindow.vue +0 -125
- package/src/components/GetStarted.vue +0 -24
- package/src/components/Layout.vue +0 -82
- package/src/components/Message.vue +0 -97
- package/src/components/MessageTyping.vue +0 -109
- package/src/composables/useChat.ts +0 -7
- package/src/composables/useI18n.ts +0 -16
- package/src/composables/useOptions.ts +0 -11
- package/src/constants/defaults.ts +0 -25
- package/src/constants/symbols.ts +0 -8
- package/src/event-buses/chatEventBus.ts +0 -3
- package/src/index.ts +0 -42
- package/src/main.scss +0 -40
- package/src/plugins/chat.ts +0 -101
- package/src/types/chat.ts +0 -12
- package/src/types/messages.ts +0 -6
- package/src/types/options.ts +0 -23
- package/src/types/webhook.ts +0 -17
- package/src/utils/event-bus.ts +0 -51
- package/src/utils/mount.ts +0 -16
- package/tsconfig.json +0 -27
- package/vite.config.ts +0 -51
- package/vitest.config.ts +0 -20
- /package/{src/__tests__/setup.ts → __tests__/setup.d.ts} +0 -0
- /package/{src/__tests__/utils/index.ts → __tests__/utils/index.d.ts} +0 -0
- /package/{src/api/index.ts → api/index.d.ts} +0 -0
- /package/{src/components/index.ts → components/index.d.ts} +0 -0
- /package/{src/composables/index.ts → composables/index.d.ts} +0 -0
- /package/{src/constants/index.ts → constants/index.d.ts} +0 -0
- /package/{src/event-buses/index.ts → event-buses/index.d.ts} +0 -0
- /package/{public/favicon.ico → favicon.ico} +0 -0
- /package/{src/plugins/index.ts → plugins/index.d.ts} +0 -0
- /package/{src/shims.d.ts → shims.d.ts} +0 -0
- /package/{src/types/index.ts → types/index.d.ts} +0 -0
- /package/{src/utils/index.ts → types/utils/index.d.ts} +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getChatInput = getChatInput;
|
|
7
|
+
exports.getChatInputSendButton = getChatInputSendButton;
|
|
8
|
+
exports.getChatInputTextarea = getChatInputTextarea;
|
|
9
|
+
exports.getChatMessage = getChatMessage;
|
|
10
|
+
exports.getChatMessageByText = getChatMessageByText;
|
|
11
|
+
exports.getChatMessageTyping = getChatMessageTyping;
|
|
12
|
+
exports.getChatMessages = getChatMessages;
|
|
13
|
+
exports.getChatWindowToggle = getChatWindowToggle;
|
|
14
|
+
exports.getChatWindowWrapper = getChatWindowWrapper;
|
|
15
|
+
exports.getChatWrapper = getChatWrapper;
|
|
16
|
+
exports.getGetStartedButton = getGetStartedButton;
|
|
17
|
+
exports.getMountingTarget = getMountingTarget;
|
|
18
|
+
var _vue = require("@testing-library/vue");
|
|
19
|
+
var _constants = require("@n8n/chat/constants");
|
|
20
|
+
function getMountingTarget(target = _constants.defaultMountingTarget) {
|
|
21
|
+
return document.querySelector(target);
|
|
22
|
+
}
|
|
23
|
+
function getChatWindowWrapper() {
|
|
24
|
+
return document.querySelector(".chat-window-wrapper");
|
|
25
|
+
}
|
|
26
|
+
function getChatWindowToggle() {
|
|
27
|
+
return document.querySelector(".chat-window-toggle");
|
|
28
|
+
}
|
|
29
|
+
function getChatWrapper() {
|
|
30
|
+
return document.querySelector(".chat-wrapper");
|
|
31
|
+
}
|
|
32
|
+
function getChatMessages() {
|
|
33
|
+
return document.querySelectorAll(".chat-message:not(.chat-message-typing)");
|
|
34
|
+
}
|
|
35
|
+
function getChatMessage(index) {
|
|
36
|
+
const messages = getChatMessages();
|
|
37
|
+
return index < 0 ? messages[messages.length + index] : messages[index];
|
|
38
|
+
}
|
|
39
|
+
function getChatMessageByText(text) {
|
|
40
|
+
return _vue.screen.queryByText(text, {
|
|
41
|
+
selector: ".chat-message:not(.chat-message-typing) .chat-message-markdown p"
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function getChatMessageTyping() {
|
|
45
|
+
return document.querySelector(".chat-message-typing");
|
|
46
|
+
}
|
|
47
|
+
function getGetStartedButton() {
|
|
48
|
+
return document.querySelector(".chat-get-started .chat-button");
|
|
49
|
+
}
|
|
50
|
+
function getChatInput() {
|
|
51
|
+
return document.querySelector(".chat-input");
|
|
52
|
+
}
|
|
53
|
+
function getChatInputTextarea() {
|
|
54
|
+
return document.querySelector(".chat-input textarea");
|
|
55
|
+
}
|
|
56
|
+
function getChatInputSendButton() {
|
|
57
|
+
return document.querySelector(".chat-input .chat-input-send-button");
|
|
58
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { screen } from "@testing-library/vue";
|
|
2
|
+
import { defaultMountingTarget } from "@n8n/chat/constants";
|
|
3
|
+
export function getMountingTarget(target = defaultMountingTarget) {
|
|
4
|
+
return document.querySelector(target);
|
|
5
|
+
}
|
|
6
|
+
export function getChatWindowWrapper() {
|
|
7
|
+
return document.querySelector(".chat-window-wrapper");
|
|
8
|
+
}
|
|
9
|
+
export function getChatWindowToggle() {
|
|
10
|
+
return document.querySelector(".chat-window-toggle");
|
|
11
|
+
}
|
|
12
|
+
export function getChatWrapper() {
|
|
13
|
+
return document.querySelector(".chat-wrapper");
|
|
14
|
+
}
|
|
15
|
+
export function getChatMessages() {
|
|
16
|
+
return document.querySelectorAll(".chat-message:not(.chat-message-typing)");
|
|
17
|
+
}
|
|
18
|
+
export function getChatMessage(index) {
|
|
19
|
+
const messages = getChatMessages();
|
|
20
|
+
return index < 0 ? messages[messages.length + index] : messages[index];
|
|
21
|
+
}
|
|
22
|
+
export function getChatMessageByText(text) {
|
|
23
|
+
return screen.queryByText(text, {
|
|
24
|
+
selector: ".chat-message:not(.chat-message-typing) .chat-message-markdown p"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export function getChatMessageTyping() {
|
|
28
|
+
return document.querySelector(".chat-message-typing");
|
|
29
|
+
}
|
|
30
|
+
export function getGetStartedButton() {
|
|
31
|
+
return document.querySelector(".chat-get-started .chat-button");
|
|
32
|
+
}
|
|
33
|
+
export function getChatInput() {
|
|
34
|
+
return document.querySelector(".chat-input");
|
|
35
|
+
}
|
|
36
|
+
export function getChatInputTextarea() {
|
|
37
|
+
return document.querySelector(".chat-input textarea");
|
|
38
|
+
}
|
|
39
|
+
export function getChatInputSendButton() {
|
|
40
|
+
return document.querySelector(".chat-input .chat-input-send-button");
|
|
41
|
+
}
|
package/api/generic.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function authenticatedFetch<T>(...args: Parameters<typeof fetch>): Promise<T>;
|
|
2
|
+
export declare function get<T>(url: string, query?: object, options?: RequestInit): Promise<T>;
|
|
3
|
+
export declare function post<T>(url: string, body?: object, options?: RequestInit): Promise<T>;
|
|
4
|
+
export declare function put<T>(url: string, body?: object, options?: RequestInit): Promise<T>;
|
|
5
|
+
export declare function patch<T>(url: string, body?: object, options?: RequestInit): Promise<T>;
|
|
6
|
+
export declare function del<T>(url: string, body?: object, options?: RequestInit): Promise<T>;
|
package/api/generic.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.authenticatedFetch = authenticatedFetch;
|
|
7
|
+
exports.del = del;
|
|
8
|
+
exports.get = get;
|
|
9
|
+
exports.patch = patch;
|
|
10
|
+
exports.post = post;
|
|
11
|
+
exports.put = put;
|
|
12
|
+
async function getAccessToken() {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
async function authenticatedFetch(...args) {
|
|
16
|
+
const accessToken = await getAccessToken();
|
|
17
|
+
const response = await fetch(args[0], {
|
|
18
|
+
...args[1],
|
|
19
|
+
mode: "cors",
|
|
20
|
+
cache: "no-cache",
|
|
21
|
+
headers: {
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
...(accessToken ? {
|
|
24
|
+
authorization: `Bearer ${accessToken}`
|
|
25
|
+
} : {}),
|
|
26
|
+
...args[1]?.headers
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return await response.json();
|
|
30
|
+
}
|
|
31
|
+
async function get(url, query = {}, options = {}) {
|
|
32
|
+
let resolvedUrl = url;
|
|
33
|
+
if (Object.keys(query).length > 0) {
|
|
34
|
+
resolvedUrl = `${resolvedUrl}?${new URLSearchParams(query).toString()}`;
|
|
35
|
+
}
|
|
36
|
+
return authenticatedFetch(resolvedUrl, {
|
|
37
|
+
...options,
|
|
38
|
+
method: "GET"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async function post(url, body = {}, options = {}) {
|
|
42
|
+
return authenticatedFetch(url, {
|
|
43
|
+
...options,
|
|
44
|
+
method: "POST",
|
|
45
|
+
body: JSON.stringify(body)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async function put(url, body = {}, options = {}) {
|
|
49
|
+
return authenticatedFetch(url, {
|
|
50
|
+
...options,
|
|
51
|
+
method: "PUT",
|
|
52
|
+
body: JSON.stringify(body)
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async function patch(url, body = {}, options = {}) {
|
|
56
|
+
return authenticatedFetch(url, {
|
|
57
|
+
...options,
|
|
58
|
+
method: "PATCH",
|
|
59
|
+
body: JSON.stringify(body)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async function del(url, body = {}, options = {}) {
|
|
63
|
+
return authenticatedFetch(url, {
|
|
64
|
+
...options,
|
|
65
|
+
method: "DELETE",
|
|
66
|
+
body: JSON.stringify(body)
|
|
67
|
+
});
|
|
68
|
+
}
|
package/api/generic.mjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
async function getAccessToken() {
|
|
2
|
+
return "";
|
|
3
|
+
}
|
|
4
|
+
export async function authenticatedFetch(...args) {
|
|
5
|
+
const accessToken = await getAccessToken();
|
|
6
|
+
const response = await fetch(args[0], {
|
|
7
|
+
...args[1],
|
|
8
|
+
mode: "cors",
|
|
9
|
+
cache: "no-cache",
|
|
10
|
+
headers: {
|
|
11
|
+
"Content-Type": "application/json",
|
|
12
|
+
...accessToken ? { authorization: `Bearer ${accessToken}` } : {},
|
|
13
|
+
...args[1]?.headers
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return await response.json();
|
|
17
|
+
}
|
|
18
|
+
export async function get(url, query = {}, options = {}) {
|
|
19
|
+
let resolvedUrl = url;
|
|
20
|
+
if (Object.keys(query).length > 0) {
|
|
21
|
+
resolvedUrl = `${resolvedUrl}?${new URLSearchParams(
|
|
22
|
+
query
|
|
23
|
+
).toString()}`;
|
|
24
|
+
}
|
|
25
|
+
return authenticatedFetch(resolvedUrl, { ...options, method: "GET" });
|
|
26
|
+
}
|
|
27
|
+
export async function post(url, body = {}, options = {}) {
|
|
28
|
+
return authenticatedFetch(url, {
|
|
29
|
+
...options,
|
|
30
|
+
method: "POST",
|
|
31
|
+
body: JSON.stringify(body)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export async function put(url, body = {}, options = {}) {
|
|
35
|
+
return authenticatedFetch(url, {
|
|
36
|
+
...options,
|
|
37
|
+
method: "PUT",
|
|
38
|
+
body: JSON.stringify(body)
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export async function patch(url, body = {}, options = {}) {
|
|
42
|
+
return authenticatedFetch(url, {
|
|
43
|
+
...options,
|
|
44
|
+
method: "PATCH",
|
|
45
|
+
body: JSON.stringify(body)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export async function del(url, body = {}, options = {}) {
|
|
49
|
+
return authenticatedFetch(url, {
|
|
50
|
+
...options,
|
|
51
|
+
method: "DELETE",
|
|
52
|
+
body: JSON.stringify(body)
|
|
53
|
+
});
|
|
54
|
+
}
|
package/api/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _generic = require("./generic");
|
|
7
|
+
Object.keys(_generic).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _generic[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _generic[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _message = require("./message");
|
|
18
|
+
Object.keys(_message).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _message[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _message[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
package/api/index.mjs
ADDED
package/api/message.d.ts
ADDED
package/api/message.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.loadPreviousSession = loadPreviousSession;
|
|
7
|
+
exports.sendMessage = sendMessage;
|
|
8
|
+
var _generic = require("@n8n/chat/api/generic");
|
|
9
|
+
async function loadPreviousSession(sessionId, options) {
|
|
10
|
+
const method = options.webhookConfig?.method === "POST" ? _generic.post : _generic.get;
|
|
11
|
+
return method(`${options.webhookUrl}`, {
|
|
12
|
+
action: "loadPreviousSession",
|
|
13
|
+
[options.chatSessionKey]: sessionId,
|
|
14
|
+
...(options.metadata ? {
|
|
15
|
+
metadata: options.metadata
|
|
16
|
+
} : {})
|
|
17
|
+
}, {
|
|
18
|
+
headers: options.webhookConfig?.headers
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async function sendMessage(message, sessionId, options) {
|
|
22
|
+
const method = options.webhookConfig?.method === "POST" ? _generic.post : _generic.get;
|
|
23
|
+
return method(`${options.webhookUrl}`, {
|
|
24
|
+
action: "sendMessage",
|
|
25
|
+
[options.chatSessionKey]: sessionId,
|
|
26
|
+
[options.chatInputKey]: message,
|
|
27
|
+
...(options.metadata ? {
|
|
28
|
+
metadata: options.metadata
|
|
29
|
+
} : {})
|
|
30
|
+
}, {
|
|
31
|
+
headers: options.webhookConfig?.headers
|
|
32
|
+
});
|
|
33
|
+
}
|
package/api/message.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { get, post } from "@n8n/chat/api/generic";
|
|
2
|
+
export async function loadPreviousSession(sessionId, options) {
|
|
3
|
+
const method = options.webhookConfig?.method === "POST" ? post : get;
|
|
4
|
+
return method(
|
|
5
|
+
`${options.webhookUrl}`,
|
|
6
|
+
{
|
|
7
|
+
action: "loadPreviousSession",
|
|
8
|
+
[options.chatSessionKey]: sessionId,
|
|
9
|
+
...options.metadata ? { metadata: options.metadata } : {}
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
headers: options.webhookConfig?.headers
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
export async function sendMessage(message, sessionId, options) {
|
|
17
|
+
const method = options.webhookConfig?.method === "POST" ? post : get;
|
|
18
|
+
return method(
|
|
19
|
+
`${options.webhookUrl}`,
|
|
20
|
+
{
|
|
21
|
+
action: "sendMessage",
|
|
22
|
+
[options.chatSessionKey]: sessionId,
|
|
23
|
+
[options.chatInputKey]: message,
|
|
24
|
+
...options.metadata ? { metadata: options.metadata } : {}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
headers: options.webhookConfig?.headers
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|