From c1b46d0b5151caeb0bf0942da1add538aa651423 Mon Sep 17 00:00:00 2001 From: Harish Mohan Raj Date: Wed, 3 Jul 2024 19:43:10 +0530 Subject: [PATCH] Get smart suggestions from server (#335) --- app/src/server/actions.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/src/server/actions.ts b/app/src/server/actions.ts index ca53fa5..5687ae2 100644 --- a/app/src/server/actions.ts +++ b/app/src/server/actions.ts @@ -124,17 +124,28 @@ export const createNewChat: CreateNewChat = async ( throw new HttpError(500, 'No Subscription Found'); } + let smartSuggestions: string[] = []; + try { + const response = await fetch( + `${ADS_SERVER_URL}/smart-suggestions?user_id=${context.user.id}`, + { + method: 'GET', + } + ); + if (!response.ok) { + throw new Error('Failed to fetch smart suggestions'); + } + smartSuggestions = (await response.json()) as string[]; + } catch (error) { + smartSuggestions = []; + } + const chat = await context.entities.Chat.create({ data: { user: { connect: { id: context.user.id } }, smartSuggestions: { type: 'manyOf', - suggestions: [ - 'Boost sales', - 'Increase brand awareness', - 'Drive website traffic', - 'Promote a product or service', - ], + suggestions: smartSuggestions, }, }, });