Compare commits
3 Commits
5e3631c49d
...
main
Author | SHA1 | Date | |
---|---|---|---|
a7eed530a3 | |||
af15eb1d0b | |||
19674310e7 |
@ -4,12 +4,12 @@ import axios from 'axios';
|
|||||||
|
|
||||||
export default createOperation.query({
|
export default createOperation.query({
|
||||||
input: z.object({
|
input: z.object({
|
||||||
page: z.number().optional(),
|
|
||||||
}),
|
}),
|
||||||
handler: async ({ page = 1 }) => {
|
handler: async () => {
|
||||||
console.log('Making request to Chatwoot API');
|
console.log('Making request to Chatwoot API');
|
||||||
|
|
||||||
const { data } = await axios.get(`https://chatwoot.andert.me/api/v1/accounts/1/contacts?page=${page}`, {
|
const { data } = await axios.get(`https://chatwoot.andert.me/api/v1/accounts/1/contacts`, {
|
||||||
headers: {
|
headers: {
|
||||||
api_access_token: process.env.CHATWOOT_API_ACCESS_TOKEN
|
api_access_token: process.env.CHATWOOT_API_ACCESS_TOKEN
|
||||||
},
|
},
|
||||||
|
20
.wundergraph/operations/getChatwootMessages.ts
Normal file
20
.wundergraph/operations/getChatwootMessages.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// .wundergraph/operations/getChatwootMessages.ts
|
||||||
|
import { createOperation, z } from '../generated/wundergraph.factory';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
export default createOperation.query({
|
||||||
|
input: z.object({
|
||||||
|
conversationId: z.string(),
|
||||||
|
}),
|
||||||
|
handler: async ({ input }) => {
|
||||||
|
console.log('Making request to Chatwoot API');
|
||||||
|
|
||||||
|
const { data } = await axios.get(`https://chatwoot.andert.me/api/v1/accounts/1/conversations/${input.conversationId}/messages`, {
|
||||||
|
headers: {
|
||||||
|
api_access_token: process.env.CHATWOOT_API_ACCESS_TOKEN
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
});
|
@ -10,10 +10,8 @@ export default createOperation.query({
|
|||||||
headers: {
|
headers: {
|
||||||
Authorization: process.env.PAPERLESS_TOKEN,
|
Authorization: process.env.PAPERLESS_TOKEN,
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Add download link, thumbnail link, preview link, PDF data, and metadata to each document
|
// Add download link, thumbnail link, preview link, PDF data, and metadata to each document
|
||||||
const documentsWithLinksDataAndMetadata = await Promise.all(data.results.map(async doc => {
|
const documentsWithLinksDataAndMetadata = await Promise.all(data.results.map(async doc => {
|
||||||
const response = await axios.get(`https://paperless.andert.me/api/documents/${doc.id}/preview/`, {
|
const response = await axios.get(`https://paperless.andert.me/api/documents/${doc.id}/preview/`, {
|
||||||
@ -25,26 +23,35 @@ export default createOperation.query({
|
|||||||
|
|
||||||
const pdfData = Buffer.from(response.data, 'binary').toString('base64');
|
const pdfData = Buffer.from(response.data, 'binary').toString('base64');
|
||||||
|
|
||||||
const correspondentResponse = await axios.get(`https://paperless.andert.me/api/correspondents/${doc.correspondent}/`, {
|
let correspondent = null;
|
||||||
headers: {
|
if (doc.correspondent) {
|
||||||
Authorization: process.env.PAPERLESS_TOKEN,
|
const correspondentResponse = await axios.get(`https://paperless.andert.me/api/correspondents/${doc.correspondent}/`, {
|
||||||
},
|
headers: {
|
||||||
});
|
Authorization: process.env.PAPERLESS_TOKEN,
|
||||||
const correspondent = correspondentResponse.data;
|
},
|
||||||
|
});
|
||||||
|
correspondent = correspondentResponse.data;
|
||||||
|
}
|
||||||
|
|
||||||
const tagsResponse = await Promise.all(doc.tags.map(tag => axios.get(`https://paperless.andert.me/api/tags/${tag}/`, {
|
let tags = [];
|
||||||
headers: {
|
if (doc.tags) {
|
||||||
Authorization: process.env.PAPERLESS_TOKEN,
|
const tagsResponse = await Promise.all(doc.tags.map(tag => axios.get(`https://paperless.andert.me/api/tags/${tag}/`, {
|
||||||
},
|
headers: {
|
||||||
})));
|
Authorization: process.env.PAPERLESS_TOKEN,
|
||||||
const tags = tagsResponse.map(response => response.data);
|
},
|
||||||
|
})));
|
||||||
|
tags = tagsResponse.map(response => response.data);
|
||||||
|
}
|
||||||
|
|
||||||
const documentTypeResponse = await axios.get(`https://paperless.andert.me/api/document_types/${doc.document_type}/`, {
|
let documentType = null;
|
||||||
headers: {
|
if (doc.document_type) {
|
||||||
Authorization: process.env.PAPERLESS_TOKEN,
|
const documentTypeResponse = await axios.get(`https://paperless.andert.me/api/document_types/${doc.document_type}/`, {
|
||||||
},
|
headers: {
|
||||||
});
|
Authorization: process.env.PAPERLESS_TOKEN,
|
||||||
const documentType = documentTypeResponse.data;
|
},
|
||||||
|
});
|
||||||
|
documentType = documentTypeResponse.data;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...doc,
|
...doc,
|
||||||
@ -54,7 +61,7 @@ export default createOperation.query({
|
|||||||
pdfData,
|
pdfData,
|
||||||
correspondent,
|
correspondent,
|
||||||
tags,
|
tags,
|
||||||
document_type: documentType,
|
documentType,
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
13723
pnpm-lock.yaml
generated
13723
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import HeaderMain from "$lib/layouts/HeaderMain.svelte";
|
import HeaderMain from "$lib/layouts/HeaderMain.svelte";
|
||||||
import { createQuery } from "../../lib/wundergraph";
|
|
||||||
import { Avatar } from "@skeletonlabs/skeleton";
|
import { Avatar } from "@skeletonlabs/skeleton";
|
||||||
|
|
||||||
|
import { createQuery } from "../../lib/wundergraph";
|
||||||
|
|
||||||
const meQuery = createQuery({
|
const meQuery = createQuery({
|
||||||
operationName: "Me",
|
operationName: "Me",
|
||||||
});
|
});
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
const contactsQuery = createQuery({
|
const contactsQuery = createQuery({
|
||||||
operationName: "getChatwootContacts",
|
operationName: "getChatwootContacts",
|
||||||
variables: { page: 2 },
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
let selectedConversation = null;
|
let selectedConversation = null;
|
||||||
|
let messagesQuery;
|
||||||
|
|
||||||
function selectConversation(conversation) {
|
function selectConversation(conversation) {
|
||||||
selectedConversation = conversation;
|
selectedConversation = conversation;
|
||||||
}
|
}
|
||||||
@ -15,6 +17,13 @@
|
|||||||
$: if ($conversationsQuery.data && !selectedConversation) {
|
$: if ($conversationsQuery.data && !selectedConversation) {
|
||||||
selectedConversation = $conversationsQuery.data.data.payload[0];
|
selectedConversation = $conversationsQuery.data.data.payload[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: if (selectedConversation) {
|
||||||
|
messagesQuery = createQuery({
|
||||||
|
operationName: "getChatwootMessages",
|
||||||
|
input: { conversationId: selectedConversation.id },
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="h-full w-full overflow-scroll flex">
|
<div class="h-full w-full overflow-scroll flex">
|
||||||
@ -49,24 +58,21 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="space-y-4 px-4">
|
<div class="space-y-4 px-4">
|
||||||
{#each selectedConversation.messages as message (message.id)}
|
{#if $messagesQuery && $messagesQuery.data}
|
||||||
{#if message.content_type == "incoming_email"}
|
{#each $messagesQuery.data.payload as message (message.id)}
|
||||||
{#if selectedConversation.last_non_activity_message.content != message.content}
|
{#if message.content_attributes.email && (message.content_attributes.email.content_type.includes("text/html") || message.content_attributes.email.content_type.includes("multipart/alternative"))}
|
||||||
<MailViewer
|
<MailViewer
|
||||||
html={selectedConversation.last_non_activity_message
|
html={message.content_attributes.email.html_content.full}
|
||||||
.content_attributes.email.html_content.full}
|
/>
|
||||||
/>{/if}
|
{:else}
|
||||||
<MailViewer
|
<div
|
||||||
html={message.content_attributes.email.html_content.full}
|
class="p-4 max-w-xs mx-auto bg-blue-100 rounded-xl shadow-md flex items-center space-x-4"
|
||||||
/>
|
>
|
||||||
{:else}
|
<p class="text-black">{message.content}</p>
|
||||||
{#if selectedConversation.last_non_activity_message.content != message.content}{selectedConversation
|
</div>
|
||||||
.last_non_activity_message.content}{/if}
|
{/if}
|
||||||
<p class="bg-slate-400 py-1 px-2 rounded-sm my-2">
|
{/each}
|
||||||
{message.content}
|
{/if}
|
||||||
</p>
|
|
||||||
{/if}
|
|
||||||
{/each}
|
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<p>Select a conversation to view its details.</p>
|
<p>Select a conversation to view its details.</p>
|
||||||
|
@ -27,10 +27,6 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<HeaderMain>
|
<HeaderMain>
|
||||||
<!-- <div slot="header">
|
|
||||||
<h1>Paperless Documents</h1>
|
|
||||||
</div> -->
|
|
||||||
|
|
||||||
<div slot="main" class="h-full w-full overflow-scroll flex">
|
<div slot="main" class="h-full w-full overflow-scroll flex">
|
||||||
<div class="w-1/4 h-full overflow-scroll">
|
<div class="w-1/4 h-full overflow-scroll">
|
||||||
{#if $paperlessQuery.isLoading}
|
{#if $paperlessQuery.isLoading}
|
||||||
@ -46,9 +42,12 @@
|
|||||||
<h2 class="text-lg font-semibold">
|
<h2 class="text-lg font-semibold">
|
||||||
{document.archived_file_name}
|
{document.archived_file_name}
|
||||||
</h2>
|
</h2>
|
||||||
<p>Correspondent: {document.correspondent.name}</p>
|
<p>Correspondent: {document.correspondent?.name || "N/A"}</p>
|
||||||
<p>Tags: {document.tags.map((tag) => tag.name).join(", ")}</p>
|
<p>
|
||||||
<p>{document.document_type.name}</p>
|
Tags: {document.tags?.map((tag) => tag.name).join(", ") ||
|
||||||
|
"N/A"}
|
||||||
|
</p>
|
||||||
|
<p>{document.documentType?.name || "N/A"}</p>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
{/each}
|
{/each}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { sveltekit } from '@sveltejs/kit/vite';
|
import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import { fetchSchemas } from './.wundergraph/schemas/fetch-schemas';
|
import { fetchSchemas } from './.wundergraph/schemas/fetch-schemas';
|
||||||
import { vitePreprocess } from '@sveltejs/kit/vite';
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
@ -16,4 +15,4 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
Reference in New Issue
Block a user