Thursday, September 25, 2025

RapidTextAI Chatbots for WordPress — Complete Setup & Real-World Examples (Bookings, Support, Lead-Gen, and More)



What you’ll build

  • A production-ready chatbot widget you can drop anywhere in WordPress (page, post, sidebar).
  • A tools system so the bot can do things: create bookings, open support tickets, capture leads, query posts/products, call external APIs, and hand off to humans.
  • Optional Retrieval-Augmented answers from your own WordPress content.

This tutorial assumes you have the RapidTextAI – AI Text Block plugin installed from WP.org or GitHub and the Chatbots extension enabled inside it. If you don’t, install/enable it first. (WordPress.org)


1) Install & enable the Chatbots extension

  1. Install the plugin

    • From WordPress: Plugins → Add New → “AI Content Writer & Auto Post Generator (RapidTextAI)” → Install → Activate. (WordPress.org)
    • Or clone the repo (developer workflow).
  2. Connect RapidTextAI

    • Go to Settings → RapidTextAI and paste your RapidTextAI API key.
    • Pick default model(s) (e.g., GPT-4/5, Gemini 2.5, DeepSeek V3, Grok-2)—RapidTextAI supports multi-model combos. (app.rapidtextai.com)
  3. Enable Chatbots

    • In the plugin’s settings, turn Chatbots on (extension inside the plugin).

Tip: Keep a low-cost model for small talk and switch to a higher-IQ model for tasks (the examples below show how to route per-tool).


2) Create your first chatbot

  1. Go to RapidTextAI → Chatbots → Add New.
  2. Fill the key fields:

    • Name/Slug: e.g., Site Support Bot.
    • System Prompt (persona):

      “You are a concise, helpful assistant for {site_name}. Answer clearly. If the user requests a booking, call the book_appointment tool. For support issues, call open_ticket. For product queries, call search_products first. If unsure, ask one question.”

    • Knowledge sources (optional): enable WordPress retrieval (posts, pages, docs).
    • Tools: toggle the tools you want (we’ll add custom ones in §5–§7).
    • Routing (optional):

      • Chit-chat → economical model
      • Tool calls / “high stakes” → your best model
  3. Save the chatbot; note the Chatbot ID (you’ll use it in shortcodes/blocks).

3) Embed the chatbot on a page

Option A — Gutenberg block

  • Edit a page and insert RapidTextAI Chatbot block, select your Chatbot ID.

Option B — Shortcode

[rapidtextai_chatbot id="site-support" theme="clean" position="bottom-right" welcome="Hi! How can I help?"]

Option C — Anywhere via PHP (widget/theme)

echo do_shortcode('[rapidtextai_chatbot id="site-support"]');

Most sites go with the block or shortcode. If you need a floating launcher on every page, place the shortcode in a reusable block or your theme footer.


4) Train the bot on your content (optional but powerful)

Turn on Knowledge / Retrieval inside your Chatbot:

  • Scope to Posts, Pages, Docs, or a specific category like “Help Center.”
  • Set chunking size (e.g., 500–1,000 chars) and “max passages” (e.g., 5–10).
  • Rebuild the index after bulk edits for freshness.

This yields on-brand answers and reduces hallucinations.


5) Add a Bookings tool (create appointments from chat)

Below is a minimal, production-friendly tool that:

  • validates user inputs,
  • creates a “booking” custom post (or calls an external API),
  • returns a confirmation back to the chatbot.

You can swap the “storage” layer for WooCommerce Bookings, Amelia, Calendly, Google Calendar, etc. The pattern stays the same—only the inside of the handler changes.

5.1 – Register a REST action the chatbot can call

Add to a small mu-plugin or your theme’s functions.php:

/**
 * Tool: book_appointment
 * Endpoint: /wp-json/rapidtextai/v1/tool/book_appointment
 */
add_action('rest_api_init', function () {
  register_rest_route('rapidtextai/v1', '/tool/book_appointment', [
    'methods'  => 'POST',
    'permission_callback' => '__return_true',
    'callback' => function ($request) {
      $p = $request->get_json_params();

      // Basic validation
      $name  = sanitize_text_field($p['name']  ?? '');
      $email = sanitize_email($p['email'] ?? '');
      $date  = sanitize_text_field($p['date']  ?? '');
      $time  = sanitize_text_field($p['time']  ?? '');
      if (!$name || !$email || !$date || !$time) {
        return new WP_REST_Response([
          'ok' => false,
          'error' => 'Missing required fields: name, email, date, time.'
        ], 400);
      }

      // Create booking CPT (or integrate external API here)
      $booking_id = wp_insert_post([
        'post_type'   => 'booking',
        'post_status' => 'publish',
        'post_title'  => "Booking for $name on $date $time",
        'meta_input'  => compact('name','email','date','time')
      ]);

      if (is_wp_error($booking_id)) {
        return new WP_REST_Response(['ok' => false, 'error' => $booking_id->get_error_message()], 500);
      }

      // Email the team/user (optional)
      wp_mail(get_option('admin_email'), 'New Booking', "Name: $name\nEmail: $email\nDate: $date $time");

      return ['ok' => true, 'booking_id' => $booking_id, 'message' => 'Booked successfully.'];
    }
  ]);
});

5.2 – Expose the tool to the chatbot

Tell the bot what this tool expects/returns. Many chatbot frameworks (including yours) let you register tools via a filter or settings. In your plugin’s Chatbot → Tools UI, add:

  • Tool Name: book_appointment
  • Description: “Create an appointment. Requires name, email, date, time.”
  • Method: POST
  • URL: /wp-json/rapidtextai/v1/tool/book_appointment
  • JSON schema (for the model):
{
  "type": "object",
  "properties": {
    "name":  { "type": "string", "description": "Customer full name" },
    "email": { "type": "string", "description": "Customer email" },
    "date":  { "type": "string", "description": "ISO date e.g. 2025-09-25" },
    "time":  { "type": "string", "description": "24h time e.g. 14:30" }
  },
  "required": ["name","email","date","time"]
}

Result: The model can autonomously choose book_appointment during a chat (“I want a slot on Friday at 2 PM”) and your endpoint will create it.


6) Add a Support tool (open tickets from chat)

Use the same pattern to create tickets in your favorite system: your own CPT, Freshdesk, HelpScout, Zendesk, or a WP helpdesk plugin.

6.1 – Minimal ticket tool (CPT)

/**
 * Tool: open_ticket
 * Endpoint: /wp-json/rapidtextai/v1/tool/open_ticket
 */
add_action('rest_api_init', function () {
  register_rest_route('rapidtextai/v1', '/tool/open_ticket', [
    'methods'  => 'POST',
    'permission_callback' => '__return_true',
    'callback' => function ($request) {
      $p = $request->get_json_params();
      $email   = sanitize_email($p['email'] ?? '');
      $subject = sanitize_text_field($p['subject'] ?? 'No subject');
      $body    = wp_kses_post($p['body'] ?? '');

      if (!$email || !$body) {
        return new WP_REST_Response(['ok'=>false,'error'=>'email and body are required'], 400);
      }

      $ticket_id = wp_insert_post([
        'post_type'   => 'ticket',
        'post_status' => 'publish',
        'post_title'  => $subject . ' — ' . $email,
        'post_content'=> $body,
        'meta_input'  => compact('email')
      ]);

      return ['ok'=>true,'ticket_id'=>$ticket_id,'message'=>'Ticket created. Our team will email you shortly.'];
    }
  ]);
});

Register the tool in the Chatbot UI as:

  • Name: open_ticket
  • Description: “Create a support ticket. Requires email and issue body.”
  • Schema for email, subject, body.

If you use a SaaS helpdesk, call their REST API inside the callback instead of creating a CPT.


7) Add a Lead-gen tool (store leads + email opt-in)

/**
 * Tool: capture_lead
 * Endpoint: /wp-json/rapidtextai/v1/tool/capture_lead
 */
add_action('rest_api_init', function () {
  register_rest_route('rapidtextai/v1', '/tool/capture_lead', [
    'methods' => 'POST',
    'permission_callback' => '__return_true',
    'callback' => function($request) {
      $p = $request->get_json_params();
      $name  = sanitize_text_field($p['name'] ?? '');
      $email = sanitize_email($p['email'] ?? '');
      $note  = sanitize_textarea_field($p['note'] ?? '');

      if (!$email) return new WP_REST_Response(['ok'=>false,'error'=>'email required'], 400);

      // Store lead as a post or in a CRM
      $lead_id = wp_insert_post([
        'post_type'   => 'lead',
        'post_status' => 'publish',
        'post_title'  => "$name <$email>",
        'post_content'=> $note,
        'meta_input'  => compact('email')
      ]);

      // Optional: Add to Sendy/Mailchimp/HubSpot here via their APIs.

      return ['ok'=>true,'lead_id'=>$lead_id,'message'=>'Thanks! We’ve saved your details.'];
    }
  ]);
});

Register tool capture_lead with fields name, email, note.


8) Example: Make the bot smart about your products (search first, then answer)

A common pattern is a search tool that returns a few results the model can read and synthesize into an answer.

/**
 * Tool: search_products
 * Query WooCommerce and return top matches
 */
add_action('rest_api_init', function () {
  register_rest_route('rapidtextai/v1', '/tool/search_products', [
    'methods'=>'POST',
    'permission_callback'=>'__return_true',
    'callback'=>function($request){
      $q = sanitize_text_field(($request->get_json_params())['query'] ?? '');
      if (!$q) return new WP_REST_Response(['ok'=>false,'error'=>'query required'], 400);

      $args = [
        'post_type' => 'product',
        'posts_per_page' => 5,
        's' => $q
      ];
      $res = [];
      $loop = new WP_Query($args);
      while ($loop->have_posts()) {
        $loop->the_post();
        $price = function_exists('wc_get_product') ? wc_get_product(get_the_ID())->get_price() : '';
        $res[] = [
          'id'=> get_the_ID(),
          'title'=> get_the_title(),
          'url'=> get_permalink(),
          'price'=> $price
        ];
      }
      wp_reset_postdata();
      return ['ok'=>true,'results'=>$res];
    }
  ]);
});

Register tool search_products with an object that includes query and returns results[] (id, title, url, price). In your system prompt, tell the model:

“For product questions, always call search_products first, then answer using the results. If the user wants to buy, share the product URLs.”


9) Guardrails & UX polishing

  • Ask first, then act: “I can book that for you on Friday 2:00 PM—shall I proceed?” This avoids accidental tool calls.
  • PII minimization: Only collect what you actually need (e.g., email for tickets).
  • Rate limiting / nonce: If your site has heavy traffic, wrap endpoints with nonces or simple rate-limits.
  • Hand-off to human: If confidence is low or user is frustrated, give a “contact human” button (link to WhatsApp, email, or live chat).
  • Model routing: Use a cheaper model for small talk; switch to a stronger model for tool calls or knowledge answers (supported by RapidTextAI’s multi-model setup). (app.rapidtextai.com)

10) Hypothetical (but realistic) blueprints you can ship today

A) “Book a demo” concierge

  • Tools used: capture_lead, book_appointment
  • Flow: “Book a demo next week” → bot collects name/email → checks available slots (your own calendar API or a Google Calendar service account) → confirms booking → email notification.

B) Tier-1 Support triage

  • Tools used: open_ticket, search_posts (KB), optional handoff_to_human
  • Flow: User describes an issue → bot retrieves top 3 KB articles → summarizes answers → if unresolved, opens a ticket with transcript + context.

C) Product finder (e-commerce)

  • Tools used: search_products → (optional) add_to_cart
  • Flow: “I need a black hoodie under $30” → search → present top matches with links → if user says “buy #2,” call add_to_cart.

D) Lead magnet + Newsletter

  • Tools used: capture_lead, optional webhook to Sendy/Mailchimp
  • Flow: Offer a free checklist or coupon → capture email → send via your ESP → store lead in CPT/CRM.

11) Optional: Retrieval from your WP content (RAG)

If your Chatbots module exposes retrieval from posts/pages, enable it in the bot settings. Otherwise, you can add a lightweight tool:

/**
 * Tool: search_posts
 * Returns short excerpts from posts/pages to ground answers.
 */
add_action('rest_api_init', function(){
  register_rest_route('rapidtextai/v1','/tool/search_posts',[
    'methods'=>'POST',
    'permission_callback'=>'__return_true',
    'callback'=>function($req){
      $q = sanitize_text_field(($req->get_json_params())['query'] ?? '');
      $args = ['post_type'=>['post','page'],'posts_per_page'=>5,'s'=>$q];
      $loop = new WP_Query($args);
      $items=[];
      while($loop->have_posts()){ $loop->the_post();
        $items[]=[
          'id'=>get_the_ID(),
          'title'=>get_the_title(),
          'url'=>get_permalink(),
          'excerpt'=>wp_strip_all_tags(get_the_excerpt())
        ];
      }
      wp_reset_postdata();
      return ['ok'=>true,'results'=>$items];
    }
  ]);
});

Prompt nudge:

“When a question is about our documentation, call search_posts first and cite the URLs you used.”


12) Production checklist

  • Security: sanitize all inputs, prefer nonces for logged-in flows.
  • Observability: log tool calls (time, user, payload, result) to a custom table or Log channel.
  • Content quality: add a tone style (“concise, friendly”) and brand facts in the system prompt.
  • Fallbacks: if a tool fails, apologize and provide a manual link (“You can also book here: /bookings/”).
  • A/B test prompts: keep versions; small changes improve success rates significantly.

13) Frequently asked questions

Q. Can I run multiple chatbots? Yes—create multiple and embed per page (e.g., Pricing bot, Docs bot). (WordPress.org)

Q. Can I switch models per request? Yes—RapidTextAI supports multi-model workflows; route cheap/expensive models by intent/tool. (app.rapidtextai.com)

Q. Do I need another plugin for the widget? No—the Chatbots extension in your RapidTextAI plugin provides the widget/block/shortcode. (WordPress.org)


14) Copy-paste System Prompt you can reuse

You are {site_name} Assistant. Goals: Solve user requests quickly, accurately, and politely. Rules:

  1. If user asks for booking, call book_appointment (collect name, email, date, time; confirm before calling).
  2. For support issues, ask 1–2 clarifying questions, then call open_ticket with the summary; return the ticket ID.
  3. For product questions, call search_products, then answer using results; include links.
  4. If the user asks about site content, call search_posts and cite URLs.
  5. If unsure, ask a clarifying question. Keep answers under 120 words unless asked for detail.

15) Troubleshooting

  • The tool didn’t trigger:

    • Ensure the tool is enabled for the chatbot and the schema matches what your endpoint expects.
    • Check REST route URL and that permalinks are working (Settings → Permalinks → Save).
  • CORS or 401 errors:

    • If you front the site with Cloudflare/WAF, allow POST /wp-json/rapidtextai/*.
    • If you locked REST to logged-in users, keep a nonce check and generate it in the chatbot embed.
  • Model “refuses” to call a tool:

    • Add explicit instructions in the system prompt (“Always use the tool for…”).
    • Provide examples in the Tool Description to bias the model.

16) Where to go next

  • Add voice (STT/TTS) for a voice concierge.
  • Sync tickets to your helpdesk and mirror status back to users.
  • Add a “My orders” tool (authenticate user, fetch recent Woo orders).
  • Record analytics: top intents, success rate, time-to-action.

References & further reading

  • RapidTextAI WordPress plugin page (features include Chatbots). (WordPress.org)
  • RapidTextAI WordPress integration overview (multi-model & workflow ideas). (app.rapidtextai.com)

If you want, I can adapt these tools to WooCommerce Bookings, Amelia, Freshdesk/HelpScout, or Calendly/Google Calendar with exact API calls—just tell me which stack you’re using and I’ll drop in the precise handlers.

0 comments:

Post a Comment