Docs
GuidesAPI referenceWebhooksWeb widget

Examples

Order status line

Answer “Where’s my order?” during the call. Look up the order in your shop with a code tool.

  1. #Create the tool

    On Tools, create a code tool named check_order with the description "Look up an order by its number. Use it whenever the caller asks where their order is." Add one required parameter:

    order_numberstringrequired
    The order number, usually 4 digits, e.g. 1042

    Add an environment variable SHOP_TOKEN with your shop's API token.

  2. #Write the code

    TypeScript
    export default async function ({ args, env }) {
      const r = await fetch(`https://shop.example.com/api/orders/${encodeURIComponent(args.order_number)}`, {
        headers: { authorization: `Bearer ${env.SHOP_TOKEN}` },
      })
      if (r.status === 404) return { found: false }
      if (!r.ok) throw new Error(`shop answered ${r.status}`)
      const o = await r.json()
      return { found: true, status: o.status, carrier: o.carrier, expected: o.delivery_date }
    }
  3. #Set the messages

    starttext
    "One moment, I'll look that up."
    failedtext
    "Sorry, I can't reach our order system right now. Can I take a message and have someone call you back?"
  4. #Test it

    Run it in the tool's test panel with a real order number, then switch it on for the assistant and add a line to the instructions: "For delivery questions, ask for the order number and check it before answering."