Contact Centres

Check data balance and buy bundles through AI chat

Workflow purpose

This guide demonstrates how to use Proto's AI agent to answer the most common question a mobile operator gets – how much data have I got left? – and to sell the next bundle in the same conversation.

The workflow identifies the line, checks the airtime, data and minutes balance through your billing system, and shows a bundle menu built from your catalogue. Before anything is charged, it states the bundle, the price and how it'll be paid, and waits for a clear yes. It handles insufficient balance, mobile money payments and bundles bought for someone else's number.

Nothing is charged to a line the AI agent hasn't verified. On WhatsApp the number the person writes from is a good start, but it isn't always the line they mean – so the workflow asks, and uses a one-time PIN for any other number.

Who can benefit from this guide:

  • Mobile network operators selling prepaid data and voice bundles
  • Mobile virtual network operators without a large call centre
  • Mobile money providers that sell airtime and bundles from the wallet
  • Customer care teams handling high volumes of balance enquiries
  • Digital sales teams moving bundle sales into chat

Check balance and buy bundles

This workflow checks a verified line's balance and sells a bundle with an explicit confirmation before the charge. See how to build a balance and bundles workflow.

Just starting with the platform?
For initial setup of your AI agent – including workspace setup, agent training, and channel deployment – please start here. This workflow guide assumes your AI agent is set up and ready for more advanced configurations.

1. Create a trigger

Start the flow when a subscriber asks about their balance or wants to buy data.

  • Navigate to the Workflows tab in the AI agent settings.
  • Click New workflow and select Message received as the Workflow type.
  • Name the trigger (e.g. “Balance and Bundles”) and add a short description (e.g. “Triggers if a subscriber asks how much airtime, data or minutes they have left, when their bundle expires, or wants to buy a data, voice or combo bundle for themselves or someone else.”).
  • Add training phrases (e.g. “How much data do I have”, “Check my balance”, “Buy a bundle”, “My data is finished”, “I want 5 GB”, “Send a bundle to my mum’s number”).

Keep failed purchases out of this trigger – “I paid but didn’t get my bundle” belongs to fix a failed top-up or bundle purchase, which looks up the transaction instead of selling a new one.

2. Confirm which line they mean

Use the WhatsApp number as a starting point, never as an assumption.

Add a Branch action that checks whether {_channel_profile.phone_number} has a value.

If it does (WhatsApp), add a Send message action with quick replies:

“Is this about the line you’re writing from, {_channel_profile.phone_number}?”

Quick replies: Yes, this number | A different number

Under a Message received sub-trigger for Yes, this number, add a Set variable action: msisdn = {_channel_profile.phone_number} and verified = Yes. A person writing from WhatsApp on that SIM already holds the line, so no PIN is needed.

Under A different number, and on every channel where the phone number isn’t known (Webchat, Messenger, Telegram), continue to Step 3. People often write from a work phone or a family member’s WhatsApp, and a balance belongs only to the person who holds the line.

3. Verify any other number with a one-time PIN

Prove the person holds the line before showing its balance or charging it.

Add an Ask survey action. Action title: Line to check

Field Variable Type Invalid reply
The mobile number you want to check msisdn Phone Please enter the full number, including the country code

Add a Send API action:

  • HTTP method: POST
  • URL endpoint: your own OTP service’s send endpoint
  • Headers: the authorisation key your system requires
  • Body: msisdn and the purpose balance-and-bundles
  • Resulting variable: otp_request

On Success, add a Send message: “We’ve sent a 6-digit PIN to {msisdn}. It expires in 5 minutes.” Then add an Ask survey with one Number field, otp_code, and the invalid reply “Please enter the 6 digits from the message”.

Add a second Send API action with POST to your OTP verify endpoint, passing msisdn and otp_code. Store the result in otp_result and parse it with Set variable: otp_result = _.json_parse(otp_result).

Condition Next
otp_result["valid"] == true Set verified = Yes and continue to Step 4
Else, first or second attempt Send message: “That PIN didn’t match. Please try again.” Then a Jump back to the PIN survey
Else, third attempt Send message: “I can’t verify this number right now. You can still buy a bundle for it as a gift from your own line.” Then Jump to Step 8

Count attempts with a Set variable action. Under Error and Timed out on either call, tell the person the check isn’t available and offer a Live agent handoff. The PIN is created and sent by your OTP service – the AI agent only passes on what the person types.

4. Look up the balance

Show everything that matters on one screen: what’s left and when it runs out.

Add a Send API action:

  • HTTP method: GET
  • URL endpoint: your billing system’s balance endpoint, with {msisdn} as a parameter
  • Headers: the authorisation key your system requires
  • Resulting variable: balance

On Success, parse it with Set variable: balance = _.json_parse(balance). Then add a Send message action with quick replies:

“Here’s your balance for {msisdn}: Airtime: {balance[“airtime”]} Data: {balance[“data_remaining”]} (expires {balance[“data_expiry”]}) Minutes: {balance[“minutes_remaining”]} SMS: {balance[“sms_remaining”]}“

Quick replies: Buy a bundle | That’s all, thanks

Add a Branch before the message for an expired or empty data bundle, and lead with it: “Your data bundle ran out on {balance[“data_expiry”]}, so you’re browsing at standard rates.“ That line is often the real reason for the chat. Under Error and Timed out, say the balance service isn’t responding and offer to try again in a few minutes – never show a cached or partial balance.

5. Show the bundle menu

Let the person pick a bundle without typing codes or prices.

Add a Send message with quick replies: Daily | Weekly | Monthly | Voice and combo

Under each sub-trigger, add a Show carousel action for that category. Each card has an image (Upload image, Image link or Chat script), a title, a subtitle and up to 3 buttons. The cards themselves are set up in the builder, up to 10 per carousel, so match them to your catalogue. Their title and subtitle can include variables, so you can fill the live price from your catalogue API with a Send API before the carousel:

Card Title Subtitle Buttons
1 1 GB – 7 days {catalogue["wk_1gb"]["price"]} Buy this (Send Message) · Terms (Open Link)
2 5 GB – 30 days {catalogue["mo_5gb"]["price"]} · social media free Buy this · Terms
3 20 GB – 30 days {catalogue["mo_20gb"]["price"]} · best value per GB Buy this · Terms

Each Send Message button gets its own sub-trigger. Under each, add a Set variable action with that bundle’s bundle_id, bundle_name and bundle_price, then Jump to Step 6.

If your catalogue changes often or differs by subscriber, use quick replies instead – they can hold variables from the catalogue response (e.g. {offers[0]["label"]}), and empty ones are dropped, so the menu only shows the offers the line can buy.

6. Choose how to pay and confirm

State exactly what will be charged, and charge nothing without a clear yes.

Add a Send message with quick replies: Pay from airtime | Pay with mobile money

Under Pay from airtime, add a Branch:

Condition Next
_.as_float(balance["airtime"]) >= _.as_float(bundle_price) Continue to the confirmation
Else Send message: “Your airtime is {balance[“airtime”]}, and this bundle costs {bundle_price}. You can pay with mobile money or pick a smaller bundle.“ Quick replies: Pay with mobile money · Choose another bundle (Jump to Step 5)

Add a Set variable action for payment_method, then a Send message with quick replies:

“Buy {bundle_name} for {msisdn} at {bundle_price}, paid from your {payment_method}? It starts straight away.”

Quick replies: Yes, buy it | No, go back

Only Yes, buy it continues. No, go back returns to the menu. Free-text replies such as “ok” or “sure” should Jump back to the confirmation rather than count as a yes.

7. Buy the bundle

Charge once, and tell the person exactly what happened.

Add a Set variable action to create order_ref – a unique reference for this purchase, e.g. {msisdn} plus _.now(). Then add a Send API action:

  • HTTP method: POST
  • URL endpoint: your billing system’s bundle purchase endpoint
  • Body: msisdn, bundle_id, payment_method and order_ref
  • Resulting variable: purchase

Your billing system should treat order_ref as an idempotency key, so a repeated request can never charge twice. Parse the result and add a Branch:

Result Reply
success “Done – {bundle_name} is active on {msisdn} until {purchase[“expiry”]}. Your airtime balance is now {purchase[“airtime_after”]}.“
insufficient_balance “Your balance changed before the payment went through, so nothing was charged. Would you like to pay with mobile money instead?”
awaiting_approval (mobile money) “Please approve the payment of {bundle_price} on your phone. Your bundle starts as soon as it’s approved.”
not_eligible “This bundle isn’t available on your plan. Here are the ones you can buy.” Then Jump to Step 5
Any other failure “The purchase didn’t go through and nothing was charged. Reference: {order_ref}.”

Under Timed out, never retry automatically – the charge may have gone through. Send: “I didn’t get a reply from our billing system, so please don’t buy again yet. Check your balance in 5 minutes. If you were charged without getting the bundle, I can fix that for you.” Add a quick reply that Jumps to fix a failed top-up or bundle purchase – order_ref is already set, so the lookup can start from it.

8. Buy a bundle for another number

Allow gifts, with an extra check that the number is right.

People often buy data for a child or a parent. Offer Buy for someone else as a quick reply in Step 4. The recipient doesn’t need a PIN, because nothing about their line is shown – but the payer must be verified in Step 2 or 3, because it’s their airtime or wallet that pays.

Add an Ask survey with two Phone fields, recipient_number and recipient_number_confirm (invalid reply: “Please enter the full number, including the country code”). Add a Branch: if the two don’t match, send “Those numbers don’t match – please enter them again” and Jump back to the survey.

Then use a stronger confirmation than Step 6:

“You’re buying {bundle_name} for {recipient_number} – not your own line. It’ll be charged to {msisdn} and can’t be moved once it’s sent. Buy it?”

Quick replies: Yes, send it | No, cancel

Run the purchase as in Step 7, with recipient_number as the target and msisdn as the payer.

9. Hand over when the AI agent can’t help

Give the person a live agent for anything outside the standard purchase.

For repeated purchase failures, a disputed charge or a request the bundle menu doesn’t cover, add a Send message: “I’ll pass you to our team – they can see your balance and what you tried to buy.” Then add a Live agent handoff action with Live agent availability check on. Under If there is no live agent online, add a short Ask survey for the person’s name and email, then a Create ticket with the number, the bundle and order_ref, tagged bundle-purchase, and give the person {_new_ticket.short_id}.

10. Test the flow

Validate every path before going live using the AI agent tester side panel.

  • Check the balance from a test WhatsApp profile with Yes, this number, then with A different number and a wrong PIN three times – confirm no balance is shown.
  • Buy a bundle with too little airtime and confirm the AI agent offers mobile money before the confirmation, not after a failed charge.
  • Make the purchase API time out and confirm nothing retries and the person is told not to buy again.
  • Buy for another number with mismatched entries, then matching ones, and check the gift confirmation names the recipient.
  • Build and test in an undeployed version – Duplicate the live version first – then click Deploy when every path passes.

Finalise the AI agent deployment by configuring your preferred channels and languages.