Foreva AI
Foreva AI Developer Portal

Complete Example

Comprehensive example showing all SDK features and methods.

from foreva_ai import ForevaAgent, MenuBuilder, MenuCustomization, OrderMode, EscalationEvents

# Your API key from dashboard
API_KEY = "foreva_your_key_here"
PHONE_NUMBER = "+14155551234"

def comprehensive_restaurant_setup():
    # Step 1: Create agent
    agent = ForevaAgent(API_KEY, PHONE_NUMBER)
    
    # Step 2: Configure restaurant information
    agent.set_store(
        name="Tony's Pizza",
        address="123 Main Street, San Francisco, CA 94110",
        timezone="America/Los_Angeles",
        website="https://tonyspizza.com",
        category="Italian Restaurant"
    )
    
    # Step 3: Set business hours
    hours = [
        {"weekday": 0, "open": "11:00", "close": "22:00"},  # Monday
        {"weekday": 1, "open": "11:00", "close": "22:00"},  # Tuesday
        {"weekday": 2, "open": "11:00", "close": "22:00"},  # Wednesday
        {"weekday": 3, "open": "11:00", "close": "22:00"},  # Thursday
        {"weekday": 4, "open": "11:00", "close": "23:00"},  # Friday
        {"weekday": 5, "open": "12:00", "close": "23:00"},  # Saturday
        {"weekday": 6, "open": "12:00", "close": "21:00"}   # Sunday
    ]
    agent.set_hours(hours)
    
    # Step 4: Set business context
    agent.set_context(
        "Family-owned Italian restaurant specializing in wood-fired "
        "pizza and pasta. We offer dine-in, takeout, and delivery."
    )
    
    # Step 5: Build comprehensive menu
    menu = (MenuBuilder()
        .add_category(1, "Appetizers")
        .add_category(2, "Pizza")
        .add_category(3, "Pasta")
        .add_category(4, "Beverages")
        
        # Simple items
        .add_item(
            id=101,
            name="Garlic Bread",
            price=8.99,
            category=1,
            desc="Fresh baked bread with garlic and herbs"
        )
        .add_item(
            id=401,
            name="Coke",
            price=2.99,
            category=4,
            desc="12oz can"
        )
        
        # Pizza with customizations
        .add_item_with_customization(
            id=201,
            name="Margherita Pizza",
            price=18.99,
            category=2,
            desc="Fresh mozzarella, basil, tomato sauce",
            customizations=[
                MenuCustomization("Size")
                    .add_option("Small (12\")", 0)
                    .add_option("Large (16\")", 4.00)
                    .set_required(True)
                    .build(),
                MenuCustomization("Extra Toppings")
                    .add_option("Pepperoni", 2.50)
                    .add_option("Italian Sausage", 2.50)
                    .add_option("Mushrooms", 2.00)
                    .set_multiple(True)
                    .build()
            ]
        )
        .add_item_with_customization(
            id=301,
            name="Spaghetti Carbonara",
            price=16.99,
            category=3,
            desc="Traditional Roman pasta with eggs, cheese, pancetta",
            customizations=[
                MenuCustomization("Pasta Type")
                    .add_option("Spaghetti", 0)
                    .add_option("Penne", 0)
                    .add_option("Fettuccine", 1.00)
                    .set_required(True)
                    .build(),
                MenuCustomization("Add Protein")
                    .add_option("Grilled Chicken", 4.00)
                    .add_option("Italian Sausage", 3.50)
                    .set_multiple(False)
                    .build()
            ]
        )
        .build())
    
    agent.set_menu(menu)
    
    # Step 6: Configure AI behavior and communication
    agent.set_greeting(
        "Hi! Thanks for calling Tony's Pizza. "
        "How can I help you with your order today?"
    )
    
    # Set escalation events
    agent.set_escalation_events([EscalationEvents.DELIVERY])
    
    # Set call forwarding
    agent.set_forwarding_number("+14155559876")
    
    # Configure notifications
    agent.set_notifications(
        sms="+14155559876",
        email="manager@tonyspizza.com"
    )
    
    # Set webhook for orders
    agent.set_webhook_url("https://tonyspizza.com/api/orders")
    
    # Configure order mode
    agent.set_order_mode(OrderMode.DEFAULT)
    
    # Activate agent
    result = agent.activate()
    print("🎉 SUCCESS! Your AI agent is now live!")
    print(f"📞 Forward your restaurant phone to: {result['routing_number']}")
    print(f"🤖 Agent ID: {result['agent_id']}")
    return result['routing_number']

# Live updates example
def show_live_updates():
    agent = ForevaAgent.load(API_KEY, PHONE_NUMBER)
    
    # Update greeting for dinner rush
    agent.set_greeting(
        "Hi! Thanks for calling Tony's Pizza. "
        "We're experiencing high call volume but I'm here to help!"
    )
    
    # Force immediate sync
    sync_result = agent.sync()
    print(f"✅ Sync initiated: {sync_result['message']}")

# Management examples
def manage_existing_agents():
    # Load existing agent
    agent = ForevaAgent.load(API_KEY, PHONE_NUMBER)
    
    # List all your agents
    agents = ForevaAgent.list_agents(API_KEY)
    for agent_info in agents:
        print(f"📞 {agent_info.get('phone_number')}: {agent_info.get('store_name')}")

    # Change linked phone number (keep same agent_id)
    agent.change_phone_number("+14155557777")
    print(f"📇 Agent Info: {agent.get_info()}")

if __name__ == "__main__":
    comprehensive_restaurant_setup()

Back to Documentation

← Back to SDK Overview