diff --git a/.wundergraph/operations/getChatwootContacts.ts b/.wundergraph/operations/getChatwootContacts.ts index dcadfa5..1d572df 100644 --- a/.wundergraph/operations/getChatwootContacts.ts +++ b/.wundergraph/operations/getChatwootContacts.ts @@ -4,12 +4,12 @@ import axios from 'axios'; export default createOperation.query({ input: z.object({ - page: z.number().optional(), + }), - handler: async ({ page = 1 }) => { + handler: async () => { 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: { api_access_token: process.env.CHATWOOT_API_ACCESS_TOKEN }, diff --git a/.wundergraph/operations/getChatwootMessages.ts b/.wundergraph/operations/getChatwootMessages.ts new file mode 100644 index 0000000..01b695b --- /dev/null +++ b/.wundergraph/operations/getChatwootMessages.ts @@ -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; + }, +}); \ No newline at end of file diff --git a/src/routes/me/contacts/+page.svelte b/src/routes/me/contacts/+page.svelte index a2ba506..e98ae87 100644 --- a/src/routes/me/contacts/+page.svelte +++ b/src/routes/me/contacts/+page.svelte @@ -5,7 +5,6 @@ const contactsQuery = createQuery({ operationName: "getChatwootContacts", - variables: { page: 2 }, }); diff --git a/src/routes/me/conversations/+page.svelte b/src/routes/me/conversations/+page.svelte index c9dcc60..71452f2 100644 --- a/src/routes/me/conversations/+page.svelte +++ b/src/routes/me/conversations/+page.svelte @@ -8,6 +8,8 @@ }); let selectedConversation = null; + let messagesQuery; + function selectConversation(conversation) { selectedConversation = conversation; } @@ -15,6 +17,13 @@ $: if ($conversationsQuery.data && !selectedConversation) { selectedConversation = $conversationsQuery.data.data.payload[0]; } + + $: if (selectedConversation) { + messagesQuery = createQuery({ + operationName: "getChatwootMessages", + input: { conversationId: selectedConversation.id }, + }); + }
- {message.content} -
- {/if} - {/each} + html={message.content_attributes.email.html_content.full} + /> + {:else} +{message.content}
+Select a conversation to view its details.