Tutorial: Build a Swahili-Fluent WhatsApp AI Bot
In this guide, we will use Python, Flask, and the Fikra API to build an autonomous WhatsApp customer service agent that understands deep East African contexts.
Prerequisites
- A Lacesse Developer Account (Get your API Key here).
- A Meta Developer Account with WhatsApp Business API enabled.
- Python 3.8+ installed.
Step 1: Set up the Webhook Server
WhatsApp requires a webhook to send incoming messages to your server. We will use Flask to catch these messages and pass them to the Fikra reasoning engine.
from flask import Flask, request, jsonify
from lacesse import FikraClient
import requests
import os
app = Flask(__name__)
# Initialize Lacesse Client
fikra = FikraClient(api_key=os.environ.get("LACESSE_API_KEY"))
@app.route('/webhook', methods=['POST'])
def whatsapp_webhook():
data = request.json
# Extract the user's message
if 'messages' in data['entry'][0]['changes'][0]['value']:
user_message = data['entry'][0]['changes'][0]['value']['messages'][0]['text']['body']
sender_phone = data['entry'][0]['changes'][0]['value']['messages'][0]['from']
# Pass to Fikra API for reasoning
response = fikra.chat.completions.create(
model="fikra-7b-instruct",
messages=[
{"role": "system", "content": "You are a customer service agent for a Nairobi electronics store. You speak English and Swahili."},
{"role": "user", "content": user_message}
]
)
ai_reply = response.choices[0].message.content
# Send reply back to WhatsApp (Implement send_whatsapp_message function)
send_whatsapp_message(sender_phone, ai_reply)
return jsonify({"status": "success"}), 200
if __name__ == '__main__':
app.run(port=5000)
Step 2: Why Fikra API over OpenAI?
When building for African consumers, latency and localization are everything. By utilizing the Fikra API at just $0.002 per 1K tokens, your bot will natively understand colloquial prompts like "Niaje, naweza lipa na Till?" without requiring massive translation middleware.
Step 3: Taking it further with Fikra Claw
A simple chatbot is great, but an Agent is better. By integrating this bot with the Fikra Claw framework, you can give your WhatsApp bot the ability to directly trigger the Daraja API to check M-Pesa payments autonomously.