Building a QR Code Loyalty Card with Aiflo

Let's imagine you own a coffee shop and want to reward your loyal customers. How about a digital loyalty card that uses QR codes? Each time a customer buys a coffee, you scan their unique QR code, and the system automatically tracks their purchases and rewards them with a free coffee after every fifth purchase.

Sounds cool, right? Let's build this using Aiflo!

1. The Goal: A Unique QR Code

We want to generate a unique QR code for each customer. This QR code should contain:

2. Building the Aiflo Program

We'll use several Aiflo nodes to achieve this:

3. Connecting the Nodes

Now, let's connect these nodes to create the workflow:

  1. Generate a unique ID using the uuid node.
  2. Sign the ID using the signature node to ensure authenticity.
  3. Get the current date and time using the datetime.now node.
  4. Combine the ID, signature, and creation time into a JSON object using the object node.
  5. Convert the JSON object to a text string using the text node.
  6. Generate the QR code image from the text string using the qr node.
  7. Send the QR code image as a response to the user.

4. The Complete Aiflo Code

Here's what the final Aiflo program looks like:

[
  { "type":"datetime.now", "then":[{"target":"ticket", "name":"created"}] },
  { "type":"uuid", "then": [{"target":"sign_ticket"}, {"target":"ticket", "name":"id"}] },
  { "name":"sign_ticket", "type":"signature", "then":[{"target":"ticket", "name":"signature"}]},
  { "name":"ticket", "type":"object", "then":[{"target":"ticket_json"}]},
  { "name":"ticket_json", "type":"text", "then":[{"target":"qr_maker"}] },
  { "name":"qr_maker","type":"qr", "then":[{"target":"response"}] },
  { "name":"response", "type":"response" },
  { "name":"Content-Type", "type":"response", "value":"image/png" } 
]

5. Running the Program

You can run this Aiflo program using the Aiflo CLI or integrate it into a web application. Each time it runs, it will generate a new unique QR code that can be printed on a card for a customer.

This example demonstrates how Aiflo can be used to create practical, real-world applications with just a few lines of easy-to-understand JSON code.