Objective: Sell a Product and Generate an Invoice
This tutorial demonstrates how to build a flow that lets a user select a product, make a payment, and receive a PDF invoice.
Nodes we will use: `Keyword Trigger`, `Table Get Row`, `Branch`, `Ecocash Payment`, `Generate Document`, `Send Message`.
Step 1: Set Up Your Products Table
First, create a `Data Table` named `Products` with the following columns:
- `product_name` (Text)
- `price` (Number)
- `description` (Text)
Add a few sample products to this table manually from the Data Sidebar.
Step 2: Build the Sales Flow
- Start with a Keyword: Use a `Keyword Trigger` node with the keyword "buy".
- Ask for Product: Connect a `Question` node asking "What product would you like to buy?" and save the answer to `product_query`.
- Find the Product: Add a `Table Get Row` node.
- Select the `Products` table.
- Set the condition: `product_name` contains `{{product_query}}`.
- Save the result to a variable named `found_product`.
- Branch if Found: Add a `Branch` node to check if a product was found. The condition is `{{found_product}}` is not empty.
- "False" Path (Not Found): Connect the `false` handle to a `Message` node that says "Sorry, we couldn't find that product." and then to an `End Flow` node.
- "True" Path (Found): From the `true` handle, connect a `Message` node that says: "Great! I found the {{found_product.product_name}} for ${{found_product.price}}. Please confirm the payment."
- Take Payment: Connect an `Ecocash Payment` node. Set the amount to `{{found_product.price}}`.
- Handle Payment Failure: Connect the `failure` handle of the payment node to a `Message` node saying "Payment failed. Please try again."
- Handle Payment Success: From the `success` handle, connect a `Generate Document` node.
- Set Template to "Invoice".
- Set Data Source to a JSON object. You can construct this in a `Set Variable` node first, or write it directly: `{"customer_name": "{{contact_name}}", "product": "{{found_product.product_name}}", "amount": "{{found_product.price}}"}}`
- Set Output URL Variable to `invoice_url`.
- Send the Invoice: Connect a `PDF` node. Set the PDF URL to `{{invoice_url}}` and add a caption like "Thank you for your purchase! Here is your invoice."
- End Flow: Connect the `PDF` node to an `End Flow` node.