Programmatic Messages

Send a message as the user without them typing. Opens the widget automatically if it's closed. Useful for buttons like "Ask about this product" or "Get help with checkout".

Vanilla JS

widget.send("Tell me more about the Enterprise plan");

Bind to a button

<button id="ask-bot">Ask about this product</button>
 
<script>
  document.querySelector("#ask-bot").addEventListener("click", () => {
    widget.send(`What can you tell me about ${productName}?`);
  });
</script>

React example

"use client";
 
export function AskBotButton({ productName }: { productName: string }) {
  return (
    <button
      onClick={() => {
        // Use the event API since <BitPalmAgent /> doesn't expose a ref
        window.dispatchEvent(
          new CustomEvent("bitpalm-send", {
            detail: {
              slug: "your-agent-slug",
              message: `What can you tell me about ${productName}?`,
            },
          })
        );
      }}
    >
      Ask about this product
    </button>
  );
}

What happens

  1. Widget opens (if it was closed)
  2. The message appears in the chat as if the user typed it
  3. The AI responds normally
  4. All event listeners (message_sent, etc.) fire

When to use it

  • Product page CTA: "Ask about this product"
  • Pricing page: "Which plan fits me?"
  • Empty cart state: "Help me find something"
  • Error page: "What went wrong?"

The pattern works because the message is contextually relevant — the user clicked a button because they have that question.

Combining with Custom Context

For best results, set the relevant context before sending:

widget.context({ product: { name: "Nike Air Max 90", id: "p_123" } });
widget.send("Is this available in size 42?");

The AI then has both the question and the structured product data.

See also