Skip to content

Commit

Permalink
Get smart suggestions from server (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj authored Jul 3, 2024
1 parent b89a3d0 commit c1b46d0
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions app/src/server/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,28 @@ export const createNewChat: CreateNewChat<void, Chat> = 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,
},
},
});
Expand Down

0 comments on commit c1b46d0

Please sign in to comment.