Added Email, Contacts and ChatGPT
This commit is contained in:
20
.wundergraph/operations/getChatwootContacts.ts
Normal file
20
.wundergraph/operations/getChatwootContacts.ts
Normal file
@ -0,0 +1,20 @@
|
||||
// .wundergraph/operations/getChatwootContacts.ts
|
||||
import { createOperation, z } from '../generated/wundergraph.factory';
|
||||
import axios from 'axios';
|
||||
|
||||
export default createOperation.query({
|
||||
input: z.object({
|
||||
page: z.number().optional(),
|
||||
}),
|
||||
handler: async ({ page = 1 }) => {
|
||||
console.log('Making request to Chatwoot API');
|
||||
|
||||
const { data } = await axios.get(`https://chatwoot.andert.me/api/v1/accounts/1/contacts?page=${page}`, {
|
||||
headers: {
|
||||
api_access_token: process.env.CHATWOOT_API_ACCESS_TOKEN
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
19
.wundergraph/operations/getChatwootConversations.ts
Normal file
19
.wundergraph/operations/getChatwootConversations.ts
Normal file
@ -0,0 +1,19 @@
|
||||
// .wundergraph/operations/getChatwootConversations.ts
|
||||
import { createOperation, z } from '../generated/wundergraph.factory';
|
||||
import axios from 'axios';
|
||||
|
||||
export default createOperation.query({
|
||||
input: z.object({}),
|
||||
handler: async () => {
|
||||
console.log('Making request to Chatwoot API');
|
||||
|
||||
const { data } = await axios.get('https://chatwoot.andert.me/api/v1/accounts/1/conversations?status=open&sort_by=last_activity_at', {
|
||||
headers: {
|
||||
api_access_token: process.env.CHATWOOT_API_ACCESS_TOKEN
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
@ -6,34 +6,58 @@ export default createOperation.query({
|
||||
input: z.object({}),
|
||||
handler: async () => {
|
||||
console.log('Making request to Paperless API');
|
||||
|
||||
const { data } = await axios.get('https://paperless.andert.me/api/documents/', {
|
||||
headers: {
|
||||
Authorization: process.env.PAPERLESS_TOKEN,
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
console.log('Received response:', data.results);
|
||||
|
||||
// Add download link, thumbnail link, preview link, and PDF data to each document
|
||||
const documentsWithLinksAndData = await Promise.all(data.results.map(async doc => {
|
||||
// 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 response = await axios.get(`https://paperless.andert.me/api/documents/${doc.id}/preview/`, {
|
||||
responseType: 'arraybuffer',
|
||||
headers: {
|
||||
Authorization: process.env.PAPERLESS_TOKEN,
|
||||
},
|
||||
});
|
||||
|
||||
const pdfData = Buffer.from(response.data, 'binary').toString('base64');
|
||||
|
||||
const correspondentResponse = await axios.get(`https://paperless.andert.me/api/correspondents/${doc.correspondent}/`, {
|
||||
headers: {
|
||||
Authorization: process.env.PAPERLESS_TOKEN,
|
||||
},
|
||||
});
|
||||
const correspondent = correspondentResponse.data;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
return {
|
||||
...doc,
|
||||
downloadLink: `https://paperless.andert.me/api/documents/${doc.id}/download/`,
|
||||
thumbnailLink: `https://paperless.andert.me/api/documents/${doc.id}/thumb/`,
|
||||
previewLink: `https://paperless.andert.me/api/documents/${doc.id}/preview/`,
|
||||
pdfData,
|
||||
correspondent,
|
||||
tags,
|
||||
document_type: documentType,
|
||||
};
|
||||
}));
|
||||
|
||||
return documentsWithLinksAndData;
|
||||
return documentsWithLinksDataAndMetadata;
|
||||
},
|
||||
});
|
Reference in New Issue
Block a user