Skip to content

Commit 4713bbc

Browse files
densumeshcdxker
authored andcommitted
feature: select the currency of the shop to use in chats
cleanup(shopify): add format command and run it
1 parent 05d3b4d commit 4713bbc

17 files changed

Lines changed: 122 additions & 40 deletions

File tree

clients/search-component/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"react-scan": "^0.3.2",
8585
"react-snap-carousel": "^0.5.0",
8686
"tailwind-merge": "^3.0.2",
87-
"trieve-ts-sdk": "0.0.73"
87+
"trieve-ts-sdk": "^0.0.90"
8888
},
8989
"peerDependencies": {
9090
"react": "^18.3.1 || ^19.0.0-rc",

clients/search-component/src/TrieveModal/Chat/SuggestedQuestions.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,20 @@ export const SuggestedQuestions = ({
6565
props.inline && "inline-questions !tv-pb-0",
6666
)}
6767
>
68-
{props.allowRefreshSuggestedQueries && <button
69-
onClick={() => getQuestions()}
70-
disabled={isLoadingSuggestedQueries}
71-
className="suggested-question tv-cursor-pointer tv-border tv-rounded-md tv-p-1 tv-text-xs disabled:tv-cursor-not-allowed tv-text-center"
72-
title="Refresh suggested questions"
73-
>
74-
<ArrowRotateRightIcon
75-
height={15}
76-
width={15}
77-
className="refresh-suggestions-icon"
78-
/>
79-
</button>}{" "}
68+
{props.allowRefreshSuggestedQueries && (
69+
<button
70+
onClick={() => getQuestions()}
71+
disabled={isLoadingSuggestedQueries}
72+
className="suggested-question tv-cursor-pointer tv-border tv-rounded-md tv-p-1 tv-text-xs disabled:tv-cursor-not-allowed tv-text-center"
73+
title="Refresh suggested questions"
74+
>
75+
<ArrowRotateRightIcon
76+
height={15}
77+
width={15}
78+
className="refresh-suggestions-icon"
79+
/>
80+
</button>
81+
)}{" "}
8082
{!suggestedQuestions.length && (
8183
<span className="suggested-question tv-text-nowrap empty-state-loading">
8284
Loading example questions...

clients/search-component/src/utils/hooks/chat-context.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
662662
metadata: {
663663
component_props: props,
664664
},
665+
currency: props.defaultCurrency,
665666
highlight_options: {
666667
...defaultHighlightOptions,
667668
highlight_delimiters: ["?", ",", ".", "!", "\n"],

clients/trieve-shopify-extension/app/processors/getProducts.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ function createChunkFromProduct(
9292
});
9393
}
9494
const metadata = {
95+
currency: product.priceRangeV2?.maxVariantPrice?.currencyCode ?? "USD",
9596
body_html: product.descriptionHtml,
9697
variantName: variantTitle,
9798
handle: product.handle,
@@ -107,6 +108,7 @@ function createChunkFromProduct(
107108
variants: product.variants.nodes.map((v) => ({
108109
id: parseInt(v.id.split("/").pop() || "0"),
109110
price: v.price,
111+
currency: product.priceRangeV2?.maxVariantPrice?.currencyCode ?? "USD",
110112
product_id: parseInt(product.id.split("/").pop() || "0"),
111113
title: v.title,
112114
inventory_quantity: v.inventoryQuantity,
@@ -148,6 +150,7 @@ function createChunkFromProduct(
148150
export function createChunkFromProductWebhook(
149151
product: ProductWebhook,
150152
variant: ProductWebhook["variants"][0],
153+
currency: string,
151154
baseUrl: string,
152155
crawlOptions: ExtendedCrawlOptions,
153156
): ChunkReqPayload {
@@ -231,6 +234,7 @@ export function createChunkFromProductWebhook(
231234
}
232235

233236
const metadata = {
237+
currency,
234238
body_html: product.body_html,
235239
handle: product.handle,
236240
id: product.id,
@@ -244,6 +248,7 @@ export function createChunkFromProductWebhook(
244248
variants: product.variants.map((v) => ({
245249
id: v.id,
246250
price: v.price,
251+
currency: currency,
247252
product_id: product.id,
248253
title: v.title,
249254
inventory_quantity: v.inventory_quantity,
@@ -281,7 +286,18 @@ export async function sendChunksFromWebhook(
281286
crawlOptions: ExtendedCrawlOptions,
282287
) {
283288
const dataChunks = product.variants.map(async (variant) => {
284-
let response = await adminApi(
289+
let response = await adminApi<{
290+
productVariant: {
291+
metafields: { nodes: { key: string; value: string }[] };
292+
product: {
293+
priceRangeV2: {
294+
maxVariantPrice: {
295+
currencyCode: string;
296+
};
297+
};
298+
};
299+
};
300+
}>(
285301
`#graphql
286302
query{
287303
productVariant(id: "${variant.admin_graphql_api_id}") {
@@ -291,27 +307,29 @@ export async function sendChunksFromWebhook(
291307
value
292308
}
293309
}
310+
product {
311+
priceRangeV2 {
312+
maxVariantPrice {
313+
currencyCode
314+
}
315+
}
316+
}
294317
}
295318
}
296319
`,
297320
);
298321
if (response.error) {
299322
throw response.error;
300323
}
301-
let data = (
302-
response as {
303-
data: {
304-
productVariant?: {
305-
metafields: { nodes: { key: string; value: string }[] };
306-
};
307-
};
308-
}
309-
).data;
324+
let data = response.data;
310325

311326
variant.metafields = data?.productVariant?.metafields?.nodes ?? [];
327+
312328
return createChunkFromProductWebhook(
313329
product,
314330
variant,
331+
data?.productVariant?.product?.priceRangeV2?.maxVariantPrice
332+
?.currencyCode ?? "USD",
315333
`https://${session?.shop}`,
316334
crawlOptions,
317335
);
@@ -390,6 +408,11 @@ export const sendChunks = async (
390408
category {
391409
name
392410
}
411+
priceRangeV2 {
412+
maxVariantPrice {
413+
currencyCode
414+
}
415+
}
393416
totalInventory
394417
variants(first: 120) {
395418
nodes {

clients/trieve-shopify-extension/app/routes/webhooks.app.products.create.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
2222
);
2323

2424
const current = payload as ProductWebhook;
25+
2526
const apiKey = await db.apiKey.findFirst({
2627
where: { shop: `${shop}` },
2728
});

clients/trieve-shopify-extension/app/routes/webhooks.app.products.update.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export const action = async ({ request }: ActionFunctionArgs) => {
1010
const { payload, session, topic, shop } = await authenticate.webhook(request);
1111
console.log(`Received ${topic} webhook for ${shop}`);
1212

13+
if (!session) {
14+
console.error(`No session found for ${shop}`);
15+
throw new Error("No session found");
16+
}
17+
1318
const current = payload as ProductWebhook;
1419
const apiKey = await db.apiKey.findFirst({
1520
where: { shop: `${shop}` },

clients/trieve-shopify-extension/app/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ export type Product = {
2323
category: {
2424
name: string;
2525
};
26+
priceRangeV2: {
27+
maxVariantPrice: {
28+
currencyCode: string;
29+
};
30+
};
2631
totalInventory: number;
2732
variants: {
2833
nodes: {

clients/trieve-shopify-extension/app/utils/onboarding.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const DEFAULT_SYSTEM_PROMPT =
1919
"[[personality]]\nYou are a friendly, helpful, and knowledgeable ecommerce sales associate. Your communication style is warm, patient, and enthusiastic without being pushy. You're approachable and conversational while maintaining professionalism. You balance being personable with being efficient, understanding that customers value both connection and their time. You're solution-oriented and genuinely interested in helping customers find the right products for their needs.\n\n[[goal]]\nYour primary goal is to help customers find products that genuinely meet their needs while providing an exceptional shopping experience. You aim to:\n1. Understand customer requirements through thoughtful questions\n2. Provide relevant product recommendations based on customer preferences\n3. Offer detailed, accurate information about products\n4. Address customer concerns and objections respectfully\n5. Guide customers through the purchasing process\n6. Encourage sales without being pushy or manipulative\n7. Create a positive impression that builds long-term customer loyalty\n\n[[response structure]]\n1. Begin with a warm greeting and acknowledgment of the customer's query or concern\n2. Ask clarifying questions if needed to better understand their requirements\n3. Provide concise, relevant information that directly addresses their needs\n4. Include specific product recommendations when appropriate, with brief explanations of why they might be suitable\n5. Address any potential concerns proactively\n6. Close with a helpful next step or question that moves the conversation forward\n7. Keep responses conversational yet efficient, balancing thoroughness with respect for the customer's time.\n";
2020

2121
export const DEFAULT_RAG_PROMPT =
22-
"You may use the retrieved context to help you respond. When discussing products, prioritize information from the provided product data while using your general knowledge to create helpful, natural responses. If a customer asks about products or specifications not mentioned in the context, acknowledge the limitation and offer to check for more information rather than inventing details.";
22+
"You may use the retrieved context to help you respond. When discussing products, prioritize information from the provided product data while using your general knowledge to create helpful, natural responses. If a customer asks about products or specifications not mentioned in the context, acknowledge the limitation and offer to check for more information rather than inventing details. Replace the currency name with the currency symbol in the price from the context.";
2323

2424
export type OnboardingBody = FC<{
2525
goToNextStep: () => void;

clients/trieve-shopify-extension/extensions/global-search/blocks/global_component.liquid

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
defaultAiQuestions = null;
1919
}
2020
21+
const currency = {{ shop.currency | json }};
22+
const currencySymbol = (currency) =>
23+
new Intl.NumberFormat("en-US", { style: 'currency', currency })
24+
.formatToParts(1)
25+
.find(x => x.type === "currency")
26+
.value;
27+
2128
const toBool = (value) => value === 'true' || value === true;
2229
const getValue = (value, defaultValue) => {
2330
if (value === null || value === undefined || value === '') {
@@ -92,15 +99,11 @@
9299
}
93100
]
94101
},
102+
defaultCurrency: currencySymbol(currency),
95103
{% comment %} not on inline {% endcomment %}
96104
showFloatingSearchIcon: toBool(getValue("{{ block.settings.show_floating_search_icon }}", true)),
97105
floatingSearchIconPosition: getValue("{{ block.settings.floating_icon_pos }}", "left"),
98106
allowSwitchingModes: false,
99-
analyticsSelectors: {
100-
checkout: {
101-
querySelector: appMetafieldTrieve.checkout_selector,
102-
},
103-
},
104107
});
105108
}
106109
</script>

clients/trieve-shopify-extension/extensions/global-search/blocks/inline_component.liquid

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
if (trievePDPQuestions && trievePDPQuestions.length > 0) {
3131
defaultAiQuestions = trievePDPQuestions.map((question) => question.text);
3232
}
33+
const currency = {{ shop.currency | json }};
34+
const currencySymbol = (currency) =>
35+
new Intl.NumberFormat("en-US", { style: 'currency', currency })
36+
.formatToParts(1)
37+
.find(x => x.type === "currency")
38+
.value;
3339
3440
const toBool = (value) => value === 'true' || value === true;
3541
const getValue = (value, defaultValue) => {
@@ -73,11 +79,10 @@
7379
typo_options: {
7480
correct_typos: true,
7581
},
76-
filters: {
77-
}
78-
},
79-
chatFilters: {
82+
filters: {}
8083
},
84+
chatFilters: {},
85+
defaultCurrency: currencySymbol(currency),
8186
{% comment %} not on global {% endcomment %}
8287
inlineHeader: "",
8388
inline: true,

0 commit comments

Comments
 (0)