Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Store Template

The store template provides a complete e-commerce assistant that helps customers browse products, manage shopping carts, and complete purchases through conversational AI.

Topic: E-Commerce & Shopping Assistant

This template is perfect for:

  • Online retail stores
  • Product catalog browsing
  • Shopping cart management
  • Order tracking
  • Customer support for e-commerce

The Code

ADD TOOL "checkout"
ADD TOOL "search-product"
ADD TOOL "add-to-cart"
ADD TOOL "view-cart"
ADD TOOL "track-order"
ADD TOOL "product-details"

data = FIND "products.csv"

CLEAR SUGGESTIONS

ADD SUGGESTION "products" AS "View products"
ADD SUGGESTION "cart" AS "View my cart"
ADD SUGGESTION "checkout" AS "Checkout"
ADD SUGGESTION "orders" AS "Track my order"
ADD SUGGESTION "help" AS "Shopping help"

SET CONTEXT "store" AS "You are a virtual store sales assistant. Help customers browse products, add items to cart, and complete purchases. Be friendly and helpful. Available products: ${TOJSON(data)}"

BEGIN TALK
**Virtual Store**

Welcome! I can help you with:
• Browse our product catalog
• Add items to your cart
• Complete your purchase
• Track your orders

Select an option or tell me what you're looking for.
END TALK

BEGIN SYSTEM PROMPT
You are a friendly sales assistant in our virtual store.

Welcome customers warmly.
Help them find products.
Provide clear product information.
Guide through purchase process.
Offer assistance when needed.

Product catalog is available in context.
Suggest related products when appropriate.
Confirm items before adding to cart.
END SYSTEM PROMPT

Sample Dialogs

These conversations show how the store template works in real-world scenarios.

Dialog 2: Add to Cart and Checkout

Dialog 3: Order Tracking

Dialog 4: Product Recommendations

Keywords Used

KeywordPurpose
ADD TOOLRegister e-commerce tools
FINDLoad product catalog from CSV
ADD SUGGESTIONCreate quick action buttons
SET CONTEXTDefine store context with product data
BEGIN TALKWelcome message block
BEGIN SYSTEM PROMPTSales assistant behavior rules

Template Structure

store.gbai/
├── store.gbdialog/
│   ├── start.bas           # Main entry point
│   └── checkout.bas        # Checkout process
├── store.gbdata/
│   └── products.csv        # Product catalog
└── store.gbot/
    └── config.csv          # Bot configuration

Checkout Tool: checkout.bas

PARAM confirm AS STRING LIKE "yes" DESCRIPTION "Confirm order placement"

DESCRIPTION "Complete the purchase and process payment"

' Get cart from memory
cart = GET BOT MEMORY("cart_" + user_id)

IF UBOUND(cart) = 0 THEN
    TALK "Your cart is empty. Add some items first!"
    RETURN NULL
END IF

' Calculate totals
subtotal = 0
FOR EACH item IN cart
    subtotal = subtotal + (item.price * item.quantity)
NEXT

shipping = 9.99
IF subtotal > 100 THEN
    shipping = 0  ' Free shipping over $100
END IF

total = subtotal + shipping

' Show order summary
TALK "📦 **Order Summary**"
TALK ""
FOR EACH item IN cart
    TALK item.quantity + "x " + item.name + " - $" + FORMAT(item.price * item.quantity, "#,##0.00")
NEXT
TALK ""
TALK "Subtotal: $" + FORMAT(subtotal, "#,##0.00")
IF shipping = 0 THEN
    TALK "Shipping: FREE ✨"
ELSE
    TALK "Shipping: $" + FORMAT(shipping, "#,##0.00")
END IF
TALK "**Total: $" + FORMAT(total, "#,##0.00") + "**"
TALK ""
TALK "Type CONFIRM to place your order."

HEAR confirmation

IF UPPER(confirmation) = "CONFIRM" THEN
    ' Create order
    orderNumber = "ORD-" + FORMAT(NOW(), "YYYY-MMDD") + "-" + FORMAT(RANDOM(100, 999))
    
    WITH order
        id = orderNumber
        user_id = user_id
        items = TOJSON(cart)
        subtotal = subtotal
        shipping = shipping
        total = total
        status = "confirmed"
        created_at = NOW()
    END WITH
    
    SAVE "orders.csv", order
    
    ' Clear cart
    SET BOT MEMORY "cart_" + user_id, []
    
    ' Send confirmation email
    SEND MAIL user_email, "Order Confirmed - " + orderNumber, 
        "Thank you for your order!\n\nOrder: " + orderNumber + "\nTotal: $" + total
    
    TALK "✅ **Order Confirmed!**"
    TALK "Order #" + orderNumber
    TALK "📧 Confirmation sent to your email"
    TALK "🚚 Estimated delivery: 3-5 business days"
    TALK ""
    TALK "Thank you for shopping with us! 🎉"
    
    RETURN orderNumber
ELSE
    TALK "Order cancelled. Your cart items are saved."
    RETURN NULL
END IF

Add to Cart Tool: add-to-cart.bas

PARAM product_id AS STRING LIKE "PROD001" DESCRIPTION "Product ID to add"
PARAM quantity AS INTEGER LIKE 1 DESCRIPTION "Quantity to add"

DESCRIPTION "Add a product to the shopping cart"

IF NOT quantity THEN
    quantity = 1
END IF

' Find product
product = FIND "products.csv", "id = '" + product_id + "'"

IF NOT product THEN
    TALK "Sorry, I couldn't find that product. Please try again."
    RETURN NULL
END IF

' Get current cart
cart = GET BOT MEMORY("cart_" + user_id)
IF NOT cart THEN
    cart = []
END IF

' Check if product already in cart
found = FALSE
FOR i = 1 TO UBOUND(cart)
    IF cart[i].product_id = product_id THEN
        cart[i].quantity = cart[i].quantity + quantity
        found = TRUE
        EXIT FOR
    END IF
NEXT

' Add new item if not found
IF NOT found THEN
    WITH item
        product_id = product_id
        name = product.name
        price = product.price
        quantity = quantity
    END WITH
    
    cart = APPEND(cart, item)
END IF

' Save cart
SET BOT MEMORY "cart_" + user_id, cart

' Calculate cart total
cartTotal = 0
cartCount = 0
FOR EACH item IN cart
    cartTotal = cartTotal + (item.price * item.quantity)
    cartCount = cartCount + item.quantity
NEXT

TALK "✅ Added to cart!"
TALK "**" + product.name + "** - $" + FORMAT(product.price, "#,##0.00")
TALK ""
TALK "🛒 Your cart: " + cartCount + " items ($" + FORMAT(cartTotal, "#,##0.00") + ")"

' Suggest related products
IF product.category THEN
    related = FIND "products.csv", "category = '" + product.category + "' AND id <> '" + product_id + "'"
    IF UBOUND(related) > 0 THEN
        TALK ""
        TALK "You might also like: **" + related[1].name + "** - $" + FORMAT(related[1].price, "#,##0.00")
    END IF
END IF

RETURN cart

Customization Ideas

Add Product Reviews

ADD TOOL "show-reviews"

' In show-reviews.bas
PARAM product_id AS STRING DESCRIPTION "Product to show reviews for"

reviews = FIND "reviews.csv", "product_id = '" + product_id + "'"

IF UBOUND(reviews) = 0 THEN
    TALK "No reviews yet for this product."
    RETURN
END IF

avgRating = 0
FOR EACH review IN reviews
    avgRating = avgRating + review.rating
NEXT
avgRating = avgRating / UBOUND(reviews)

TALK "⭐ **Customer Reviews** (" + FORMAT(avgRating, "#.#") + "/5)"
TALK ""

FOR EACH review IN FIRST(reviews, 3)
    TALK "**" + review.author + "** - " + STRING(review.rating, "⭐")
    TALK review.comment
    TALK ""
NEXT

Add Discount Codes

PARAM code AS STRING DESCRIPTION "Discount code to apply"

discount = FIND "discounts.csv", "code = '" + UPPER(code) + "' AND valid_until >= '" + FORMAT(NOW(), "YYYY-MM-DD") + "'"

IF NOT discount THEN
    TALK "Sorry, that code is invalid or expired."
    RETURN NULL
END IF

SET BOT MEMORY "discount_" + user_id, discount

TALK "✅ Discount applied!"
TALK "**" + discount.description + "**"
IF discount.type = "percent" THEN
    TALK "You'll save " + discount.value + "% on your order!"
ELSE
    TALK "You'll save $" + FORMAT(discount.value, "#,##0.00") + " on your order!"
END IF

Add Wishlist Feature

ADD TOOL "add-to-wishlist"
ADD TOOL "view-wishlist"

' In add-to-wishlist.bas
PARAM product_id AS STRING DESCRIPTION "Product to add to wishlist"

wishlist = GET USER MEMORY("wishlist")
IF NOT wishlist THEN
    wishlist = []
END IF

wishlist = APPEND(wishlist, product_id)
SET USER MEMORY "wishlist", wishlist

product = FIND "products.csv", "id = '" + product_id + "'"
TALK "❤️ Added **" + product.name + "** to your wishlist!"

Add Inventory Check

' Before adding to cart, check stock
stock = FIND "inventory.csv", "product_id = '" + product_id + "'"

IF stock.quantity < quantity THEN
    IF stock.quantity = 0 THEN
        TALK "😔 Sorry, this item is out of stock."
        TALK "Would you like to be notified when it's available?"
    ELSE
        TALK "⚠️ Only " + stock.quantity + " left in stock."
        TALK "Would you like to add " + stock.quantity + " instead?"
    END IF
    RETURN NULL
END IF